DEV Community

張旭豐
張旭豐

Posted on • Edited on

5 HC-SR04 Ultrasonic Sensor Projects That Detect the World Around You

5 HC-SR04 Ultrasonic Sensor Projects That Detect the World Around You

Build proximity-triggered projects: smart trash can, parking sensor, desk lamp, water level monitor, and pedestrian detection system

HC-SR04 Ultrasonic Sensor Hero

The HC-SR04 ultrasonic distance sensor is one of the most versatile components in any maker's toolkit. It uses sonar to measure distances by emitting ultrasonic waves and calculating the time it takes for the echo to return. In this guide, we'll build five complete proximity-triggered projects that take this $3 sensor from basic distance reading to intelligent environmental awareness.

Topics covered: Arduino programming, sensor integration, threshold logic, event-driven automation, physical build tips.

Affiliate disclosure: As an Amazon Associate, I earn from qualifying purchases.

Affiliate links: HC-SR04 on Amazon | Arduino Nano on Amazon | Jumper wires on Amazon


What You'll Need

  • HC-SR04 ultrasonic sensor (×5 for complete builds, or ×1 for sequential testing)
  • Arduino Nano or Uno (×1)
  • USB cable for programming
  • Breadboard and jumper wires
  • Active buzzer or LED strip (per project)
  • Servo motor (for trash can lid and gate projects)
  • Relay module (for lamp and water pump projects)
  • Water pump (for water level project)

How the HC-SR04 Works

Before diving into the projects, let's understand the sensor's operation:

Arduino          HC-SR04
  Pin 9  ──────  Trig
  Pin 10  ──────  Echo
  5V      ──────  VCC
  GND     ──────  GND
Enter fullscreen mode Exit fullscreen mode

Measurement cycle:

  1. Send a 10µs HIGH pulse on Trig
  2. Sensor emits 8 cycles of 40kHz ultrasonic burst
  3. Sensor raises Echo HIGH immediately
  4. Sensor lowers Echo LOW when echo is detected (or after 38ms timeout)
  5. Arduino measures Echo HIGH duration (38ms max = ~6.4m range)
  6. Distance = (time × speed_of_sound) / 2
float getDistance_cm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  long duration = pulseIn(ECHO_PIN, HIGH, 30000);
  return duration * 0.034 / 2; // cm
}
Enter fullscreen mode Exit fullscreen mode

Project 1: Smart Trash Can

Goal: Automatically open the trash can lid when someone approaches within 50cm.

Smart Trash Can

Hardware

  • HC-SR04 sensor (mounted on lid underside)
  • SG90 servo motor (attached to lid hinge)
  • Arduino Nano
  • External 5V power supply (for servo)

Wiring

HC-SR04:   Trig→Pin 9,  Echo→Pin 10,  VCC→5V,  GND→GND
Servo:     Signal→Pin 6,  VCC→5V external,  GND→GND
Enter fullscreen mode Exit fullscreen mode

Code

// WF1 Run #034 - Project 1: Smart Trash Can
// HC-SR04 + SG90 Servo

#include <Servo.h>

#define TRIG_PIN  9
#define ECHO_PIN  10
#define SERVO_PIN 6

#define OPEN_DISTANCE_CM   50.0
#define LID_OPEN_ANGLE     90.0
#define LID_CLOSED_ANGLE   0.0

Servo lidServo;
bool isOpen = false;

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  lidServo.attach(SERVO_PIN);
  lidServo.write(LID_CLOSED_ANGLE);
  Serial.println(&tag=hfchang-20"Smart Trash Can ready.");
}

void loop() {
  float distance = getDistance_cm();

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  if (distance > 0 && distance < OPEN_DISTANCE_CM) {
    if (!isOpen) {
      openLid();
      isOpen = true;
    }
  } else {
    if (isOpen) {
      closeLid();
      isOpen = false;
    }
  }

  delay(200);
}

void openLid() {
  Serial.println("Opening lid...");
  for (int angle = LID_CLOSED_ANGLE; angle <= LID_OPEN_ANGLE; angle += 5) {
    lidServo.write(angle);
    delay(15);
  }
}

void closeLid() {
  Serial.println("Closing lid...");
  for (int angle = LID_OPEN_ANGLE; angle >= LID_CLOSED_ANGLE; angle -= 5) {
    lidServo.write(angle);
    delay(15);
  }
}

float getDistance_cm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  long duration = pulseIn(ECHO_PIN, HIGH, 30000);
  if (duration == 0) return 200.0; // no echo
  return duration * 0.034 / 2;
}
Enter fullscreen mode Exit fullscreen mode

Build Notes

  • Mount the HC-SR04 flat against the underside of the trash can lid, facing downward
  • The sensor has a 15° beam angle—position centrally for even coverage
  • Use a servo with at least 1.5kg torque to lift most plastic lid sizes
  • Add a small sponge gasket around the rim to dampen the closing sound

Need a custom enclosure design? I offer rapid prototyping and sensor integration on Fiverr.


Project 2: Car Parking Sensor

Goal: Alert the driver with increasing beeps as the car approaches an obstacle.

Car Parking Sensor

Hardware

  • HC-SR04 sensor (×3 for rear coverage)
  • Active buzzer module
  • Arduino Nano
  • 9V battery clip for portable power
  • LED indicator

Wiring

HC-SR04 #1 (center):  Trig→Pin 9,  Echo→Pin 10
HC-SR04 #2 (left):    Trig→Pin 11, Echo→Pin 12
HC-SR04 #3 (right):   Trig→Pin 13, Echo→Pin 14
Buzzer:               Signal→Pin 3,  VCC→5V,  GND→GND
LED:                   Anode→Pin 4 (via 220Ω resistor), Cathode→GND
Enter fullscreen mode Exit fullscreen mode

Code

// WF1 Run #034 - Project 2: Car Parking Sensor
// 3× HC-SR04 + Active Buzzer + LED

#define TRIG_CENTER  9
#define ECHO_CENTER  10
#define TRIG_LEFT    11
#define ECHO_LEFT    12
#define TRIG_RIGHT   13
#define ECHO_RIGHT   14
#define BUZZER_PIN   3
#define LED_PIN      4

void setup() {
  Serial.begin(115200);

  pinMode(TRIG_CENTER, OUTPUT);
  pinMode(ECHO_CENTER, INPUT);
  pinMode(TRIG_LEFT, OUTPUT);
  pinMode(ECHO_LEFT, INPUT);
  pinMode(TRIG_RIGHT, OUTPUT);
  pinMode(ECHO_RIGHT, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  Serial.println("Parking sensor ready. Begin reversing.");
}

void loop() {
  float dCenter = getDistance_cm(TRIG_CENTER, ECHO_CENTER);
  float dLeft   = getDistance_cm(TRIG_LEFT, ECHO_LEFT);
  float dRight  = getDistance_cm(TRIG_RIGHT, ECHO_RIGHT);

  float closest = min(min(dCenter, dLeft), dRight);

  Serial.print("Center: "); Serial.print(dCenter);
  Serial.print(" | Left: "); Serial.print(dLeft);
  Serial.print(" | Right: "); Serial.print(dRight);
  Serial.print(" | Closest: "); Serial.println(closest);

  int beepInterval = mapDistanceToBeep(closest);

  if (beepInterval > 0) {
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);
    delay(100);
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
    delay(beepInterval);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }

  delay(50);
}

int mapDistanceToBeep(float distance) {
  if (distance <= 0 || distance > 200) return 0;
  if (distance < 20)  return 100;  // Very close: fast beeps
  if (distance < 50)  return 250;  // Close: medium beeps
  if (distance < 100) return 500;  // Medium: slow beeps
  if (distance < 150) return 1000; // Far: very slow beeps
  return 0;                         // Safe: no beep
}

float getDistance_cm(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH, 30000);
  if (duration == 0) return 300.0;
  return duration * 0.034 / 2;
}
Enter fullscreen mode Exit fullscreen mode

Calibration

Distance Range Beep Interval Visual Feedback
> 150 cm None LED off
100–150 cm 1 second Slow blink
50–100 cm 500 ms Medium blink
20–50 cm 250 ms Fast blink
< 20 cm 100 ms Solid on

Build Notes

  • Mount sensors behind the rear bumper, facing outward
  • Position center sensor at bumper height (40–60cm from ground)
  • Drill holes with rubber grommets for weatherproofing
  • The 3-sensor array gives coverage of ~120° arc behind the car

Need help with the wiring harness or enclosure? I can source components and build custom sensor arrays on Fiverr.


Project 3: Proximity Desk Lamp

Goal: Turn on the desk lamp when hands approach within 30cm, off when they leave.

Proximity Desk Lamp

Hardware

  • HC-SR04 sensor
  • Arduino Nano
  • 5V relay module (or MOSFET module)
  • Desk lamp with incandescent or LED bulb (up to 100W)
  • 110/220V AC to 5V DC power converter

Wiring

HC-SR04:   Trig→Pin 9,  Echo→Pin 10,  VCC→5V,  GND→GND
Relay:     Signal→Pin 8,  VCC→5V,  GND→GND
           COM → lamp live wire,  NO → AC neutral
Enter fullscreen mode Exit fullscreen mode

⚠️ Safety Warning

This project involves mains voltage. If you're not comfortable working with AC wiring, skip to Project 4 or 5. Always unplug before wiring. Use a properly rated enclosure.

Code

// WF1 Run #034 - Project 3: Proximity Desk Lamp
// HC-SR04 + Relay Module

#define TRIG_PIN   9
#define ECHO_PIN   10
#define RELAY_PIN  8

#define PRESENCE_THRESHOLD_CM  30.0
#define AWAY_THRESHOLD_CM       50.0  // hysteresis: need to move farther away to turn off

bool lampOn = false;
bool someonePresent = false;

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);

  digitalWrite(RELAY_PIN, LOW); // relay OFF = lamp OFF (verify your relay logic)
  Serial.println("Proximity desk lamp ready.");
}

void loop() {
  float distance = getDistance_cm();

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Hysteresis prevents flickering at the threshold boundary
  if (distance < PRESENCE_THRESHOLD_CM && !someonePresent) {
    someonePresent = true;
    setLamp(true);
  } else if (distance > AWAY_THRESHOLD_CM && someonePresent) {
    someonePresent = false;
    setLamp(false);
  }

  delay(150);
}

void setLamp(bool on) {
  if (on) {
    digitalWrite(RELAY_PIN, HIGH);
    lampOn = true;
    Serial.println("Lamp ON");
  } else {
    digitalWrite(RELAY_PIN, LOW);
    lampOn = false;
    Serial.println("Lamp OFF");
  }
}

float getDistance_cm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  long duration = pulseIn(ECHO_PIN, HIGH, 30000);
  if (duration == 0) return 400.0;
  return duration * 0.034 / 2;
}
Enter fullscreen mode Exit fullscreen mode

Build Notes

  • Point the HC-SR04 toward the area where hands typically approach (above desk surface)
  • Use a small PIR-motion-style enclosure box to hide the electronics
  • The hysteresis gap (30cm on / 50cm off) prevents rapid on-off cycling
  • The sensor works through non-metallic enclosures—mount inside a 3D-printed case

Want a custom 3D-printed enclosure for this project? I design and print custom sensor housings on Fiverr.


Project 4: Water Level Monitor

Goal: Display water level percentage in a tank and auto-start pump when below 20%.

Water Level Monitor

Hardware

  • HC-SR04 sensor (mounted at tank lid, facing water surface)
  • 16×2 LCD I2C display
  • Arduino Nano
  • 5V relay module
  • Water pump (5V submersible)
  • Waterproof container for electronics

Wiring

HC-SR04:   Trig→Pin 9,  Echo→Pin 10,  VCC→5V,  GND→GND
LCD I2C:   SDA→A4,  SCL→A5,  VCC→5V,  GND→GND
Relay:     Signal→Pin 8,  VCC→5V,  GND→GND
Pump:      NO relay contact → pump → 5V supply
Enter fullscreen mode Exit fullscreen mode

Code

// WF1 Run #034 - Project 4: Water Level Monitor
// HC-SR04 + LCD I2C + Water Pump Relay

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define TRIG_PIN   9
#define ECHO_PIN   10
#define RELAY_PIN  8

#define TANK_HEIGHT_CM    40.0
#define PUMP_ON_THRESHOLD 20.0   // percent
#define PUMP_OFF_THRESHOLD 90.0  // percent (hysteresis)
#define EMPTY_DISTANCE_CM 38.0   // sensor to water when tank is empty
#define FULL_DISTANCE_CM  2.0    // sensor to water when tank is full

LiquidCrystal_I2C lcd(0x27, 16, 2);
bool pumpRunning = false;

void setup() {
  Serial.begin(115200);

  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(RELAY_PIN, OUTPUT);

  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Water Level Monitor");
  delay(2000);
  lcd.clear();

  Serial.println("Water level monitor ready.");
}

void loop() {
  float distance = getDistance_cm();
  float fillPercent = calculateFillPercent(distance);

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.print(" cm | Fill: ");
  Serial.print(fillPercent);
  Serial.println(" %");

  lcd.setCursor(0, 0);
  lcd.print("Level: ");
  lcd.print(fillPercent, 0);
  lcd.print("%    ");

  // Pump control with hysteresis
  if (fillPercent < PUMP_ON_THRESHOLD && !pumpRunning) {
    startPump();
  } else if (fillPercent > PUMP_OFF_THRESHOLD && pumpRunning) {
    stopPump();
  }

  lcd.setCursor(0, 1);
  if (pumpRunning) {
    lcd.print("Pump: FILLING   ");
  } else {
    lcd.print("Pump: IDLE      ");
  }

  delay(500);
}

void startPump() {
  digitalWrite(RELAY_PIN, HIGH);
  pumpRunning = true;
  Serial.println("Pump started.");
}

void stopPump() {
  digitalWrite(RELAY_PIN, LOW);
  pumpRunning = false;
  Serial.println("Pump stopped.");
}

float calculateFillPercent(float distance) {
  // Distance to water surface -> percentage
  // Close distance = full tank, far distance = empty tank
  float percent = map(distance, EMPTY_DISTANCE_CM, FULL_DISTANCE_CM, 0, 100);
  return constrain(percent, 0, 100);
}

float getDistance_cm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  long duration = pulseIn(ECHO_PIN, HIGH, 30000);
  if (duration == 0) return EMPTY_DISTANCE_CM;
  return duration * 0.034 / 2;
}
Enter fullscreen mode Exit fullscreen mode

Calibration

  1. Fill the tank completely and measure the sensor-to-water distance → set FULL_DISTANCE_CM
  2. Empty the tank and measure → set EMPTY_DISTANCE_CM
  3. Adjust TANK_HEIGHT_CM for display reference only

Build Notes

  • The HC-SR04 works through plastic and glass—mount it above the waterline
  • For outdoor tanks, use a waterproof enclosure (plastic project box + silicone seal)
  • The sensor has ~2cm minimum range—account for this in shallow tanks
  • Submersible pumps may draw more current than the relay can handle; use a pump relay or motor shield

Need help setting up the LCD display or calibrating the sensor? I provide step-by-step build support on Fiverr.


Project 5: Pedestrian Detection Gate

Goal: Automatically open a garden gate when a person approaches from either side.

Pedestrian Detection Gate

Hardware

  • HC-SR04 sensor (×2, facing opposite directions for 180° coverage)
  • SG90 servo motor (for gate latch release)
  • Arduino Nano
  • LED indicators (green = open, red = locked)
  • 5V buzzer (short beep on open)

Wiring

HC-SR04 #1 (front):  Trig→Pin 9,  Echo→Pin 10
HC-SR04 #2 (back):    Trig→Pin 11, Echo→Pin 12
Servo:                Signal→Pin 6,  VCC→5V,  GND→GND
LED Green:            Anode→Pin 3 (220Ω resistor), Cathode→GND
LED Red:              Anode→Pin 4 (220Ω resistor), Cathode→GND
Buzzer:               Signal→Pin 5,  VCC→5V,  GND→GND
Enter fullscreen mode Exit fullscreen mode

Code

// WF1 Run #034 - Project 5: Pedestrian Detection Gate
// 2× HC-SR04 + Servo + LEDs + Buzzer

#include <Servo.h>

#define TRIG_FRONT   9
#define ECHO_FRONT   10
#define TRIG_BACK    11
#define ECHO_BACK    12
#define SERVO_PIN    6
#define LED_GREEN    3
#define LED_RED      4
#define BUZZER_PIN   5

#define DETECT_DISTANCE_CM  80.0
#define GATE_OPEN_ANGLE     90.0
#define GATE_CLOSED_ANGLE   0.0

Servo gateServo;
bool gateOpen = false;
bool someonePresent = false;

void setup() {
  Serial.begin(115200);

  pinMode(TRIG_FRONT, OUTPUT);
  pinMode(ECHO_FRONT, INPUT);
  pinMode(TRIG_BACK, OUTPUT);
  pinMode(ECHO_BACK, INPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  gateServo.attach(SERVO_PIN);
  gateServo.write(GATE_CLOSED_ANGLE);
  updateIndicators(false);

  Serial.println("Pedestrian gate ready.");
}

void loop() {
  float dFront = getDistance_cm(TRIG_FRONT, ECHO_FRONT);
  float dBack  = getDistance_cm(TRIG_BACK, ECHO_BACK);

  bool detectedFront = (dFront > 0 && dFront < DETECT_DISTANCE_CM);
  bool detectedBack  = (dBack > 0 && dBack < DETECT_DISTANCE_CM);
  bool detected = detectedFront || detectedBack;

  Serial.print("Front: "); Serial.print(dFront);
  Serial.print(" cm | Back: "); Serial.print(dBack);
  Serial.print(" cm | Detected: "); Serial.println(detected);

  if (detected && !someonePresent) {
    someonePresent = true;
    openGate();
  } else if (!detected && someonePresent) {
    someonePresent = false;
    closeGate();
  }

  delay(200);
}

void openGate() {
  if (gateOpen) return;
  gateOpen = true;

  Serial.println("Person detected. Opening gate.");
  updateIndicators(true);
  tone(BUZZER_PIN, 1000, 200); // short beep

  // Smooth servo motion
  for (int angle = GATE_CLOSED_ANGLE; angle <= GATE_OPEN_ANGLE; angle += 3) {
    gateServo.write(angle);
    delay(20);
  }
}

void closeGate() {
  if (!gateOpen) return;
  gateOpen = false;

  Serial.println("Area clear. Closing gate.");
  tone(BUZZER_PIN, 800, 150); // softer close beep

  for (int angle = GATE_OPEN_ANGLE; angle >= GATE_CLOSED_ANGLE; angle -= 3) {
    gateServo.write(angle);
    delay(20);
  }

  updateIndicators(false);
}

void updateIndicators(bool open) {
  digitalWrite(LED_GREEN, open ? HIGH : LOW);
  digitalWrite(LED_RED, open ? LOW : HIGH);
}

float getDistance_cm(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH, 30000);
  if (duration == 0) return 500.0;
  return duration * 0.034 / 2;
}
Enter fullscreen mode Exit fullscreen mode

Build Notes

  • Mount sensors at gate post height (~1m from ground) on each side
  • Sensors should face outward at 90° angles from the gate plane
  • The two-sensor array provides ~180° detection arc—sufficient for walkway approach
  • For narrower beams, use the SR-04's narrow-beam variant or shield with a paper tube
  • A physical stop on the gate hinge prevents over-rotation

Looking to expand this to a smart home integration? I can add Wi-Fi or Bluetooth control on Fiverr.


Universal HC-SR04 Helper Library

All five projects use a common getDistance_cm() function. Here's a clean, reusable version:

// HC-SR04 Ultrasonic Sensor Helper
// Place in a separate .h file or at top of your sketch

#ifndef ULTRASONIC_H
#define ULTRASONIC_H

#include <Arduino.h>

class Ultrasonic {
public:
  Ultrasonic(int trigPin, int echoPin) 
    : _trigPin(trigPin), _echoPin(echoPin) {}

  void begin() {
    pinMode(_trigPin, OUTPUT);
    pinMode(_echoPin, INPUT);
  }

  float getDistance_cm() {
    digitalWrite(_trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(_trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(_trigPin, LOW);

    long duration = pulseIn(_echoPin, HIGH, 30000);
    if (duration == 0) return 400.0;
    return duration * 0.034 / 2;
  }

  float getDistance_in() {
    return getDistance_cm() / 2.54;
  }

private:
  int _trigPin;
  int _echoPin;
};

#endif
Enter fullscreen mode Exit fullscreen mode

Usage:

Ultrasonic sensor(9, 10);

void setup() {
  sensor.begin();
}

void loop() {
  Serial.print("Distance: ");
  Serial.print(sensor.getDistance_cm());
  Serial.println(" cm");
  delay(500);
}
Enter fullscreen mode Exit fullscreen mode

Troubleshooting Common HC-SR04 Issues

Symptom Likely Cause Fix
Always reads ~388 cm No echo received Check wiring (Trig/Echo swapped)
Jumpy readings Electrical noise Add 100µF capacitor across VCC/GND
Works on breadboard, fails in enclosure Reflected signals Add cotton wool stuffing inside case
Works near objects, misses far ones Soft surfaces absorb sound Use harder target surfaces for testing
Readings halts mid-loop pulseIn timeout Check duration == 0 fallback

Shopping List & Affiliate Links

Component Amazon (affiliate) AliExpress
HC-SR04 (1pc) $3.99 $1.50
Arduino Nano $9.99 $4.00
SG90 Servo $4.99 $2.00
5V Relay Module $5.99 $1.50
Active Buzzer $3.99 $0.50
LCD I2C 16×2 $7.99 $3.00
Jumper Wires $5.99 $2.00
Breadboard $6.99 $2.00

As an Amazon associate, I earn from qualifying purchases.


Next Steps

  1. Start with Project 1 (smart trash can) — it's the simplest entry point
  2. Add IoT capability to any project using an ESP8266 or ESP32 instead of Arduino Nano
  3. Combine sensors: add a light sensor (LDR) to the desk lamp for smart dimming
  4. Log data: connect an SD card module to the water level monitor for historical tracking

Need Custom Build Help?

I offer one-on-one project consultation, custom sensor integration, and 3D-printed enclosure design on Fiverr. From concept to working prototype, I can help you bring your proximity sensor idea to life.


All code in this article is open source under the MIT license. Code is provided as-is for educational purposes. Always observe electrical safety precautions when working with mains voltage.


Next Step: From Scene to Sensor, Without Writing Code

If this guide gave you ideas for your own setup — but you're not sure which sensors and outputs work best for your specific space — I can help you map that out.

I offer a personalized interactive device design guide at Fiverr:

👉 https://www.fiverr.com/phd_hfchang/generate-an-arduino-interactive-prototypef

What you get:

  • A custom guide based on your actual scene (not generic recommendations)
  • Sensor selection matched to user behavior and physical constraints
  • Interaction logic without needing to write code from scratch
  • Testing methodology with pass/fail criteria for each output

Tags: Arduino HC-SR04 Ultrasonic Sensor Proximity Sensor Arduino Projects IoT Electronics Maker Tutorial

Top comments (0)