SensorsParking Sensor with Sound and Lights
An ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.
Home and IoTBring your hand close and the lid lifts by itself. An ultrasonic sensor notices the hand, and a servo opens the lid and closes it three seconds after the hand has gone.
Written by the RoboHub team. A question? Write to us.
Choose a variation and the parts list updates.
Connect the HC-SR04's VCC to 5V, GND to ground, TRIG to pin 6 and ECHO to pin 7. Mount the sensor on the front of the bin, facing up or forward.
The servo has three wires: brown to ground, red to 5V, orange to pin 3. The sensor and the servo both need 5V, so feed them from one breadboard rail.
Fix the servo at the back of the bin next to the lid's hinge, and link its arm to the lid with a piece of wire or a wooden stick. Choose a light lid: an SG90 can't lift a heavy one.
CLOSED and OPEN are the lid angles. If the lid doesn't open fully or goes too far, change these numbers.
#include <Servo.h>
const int TRIG = 6, ECHO = 7, SERVO = 3;
const int CLOSED = 0, OPEN = 100; // lid angles: adjust them for your bin
const int NEAR_CM = 20; // a hand closer than this opens the lid
Servo lid;
unsigned long lastSeen = 0;
long distanceCm() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH, 30000);
return us / 58; // 0 = nothing in range
}
void setup() {
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
lid.attach(SERVO);
lid.write(CLOSED);
}
void loop() {
long cm = distanceCm();
if (cm > 0 && cm < NEAR_CM) {
lid.write(OPEN);
lastSeen = millis();
} else if (millis() - lastSeen > 3000) {
lid.write(CLOSED); // 3 seconds after the hand has gone
}
delay(100);
}
SensorsAn ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.
Home and IoTType the secret code and press #: with the right code the green light comes on and a servo slides the bolt open, with the wrong one the buzzer beeps three times.
Home and IoTA PIR sensor notices a warm body moving. As soon as someone walks into the room, a siren sounds and a red light flashes.