This page shows how I built: the Auto Bin, the Toilet Flusher (same mechanism), and the Smart Light. All builds are Arduino-based and designed to be simple, cheap and easy to reproduce.
Parts: Servo, HC-SR04, Arduino, small spoon (or thin strip), DFPlayer Mini + microSD + small speaker (or just a passive speaker), power supply (5V), wires.
When the ultrasonic detects a hand/object within a set distance (e.g. < 20 cm), the Arduino rotates the servo which swings the spoon to press the bin lid (or push a latch). Optionally play a short sound using the DFPlayer Mini.
HC-SR04:
Vcc -> 5V
GND -> GND
Trig -> Arduino pin 7
Echo -> Arduino pin 6
Servo:
Vcc -> 5V (prefer separate 5V regulator or use 5V power bank)
GND -> GND (common ground!)
Signal -> Arduino pin 5
DFPlayer Mini (optional voice):
Vcc -> 5V
GND -> GND
TX -> Arduino RX via SoftwareSerial pin 10
RX -> Arduino TX via SoftwareSerial pin 11
Speaker -> DFPlayer speaker pins
Power note: Servos draw spikes when moving — don't power them directly from Arduino if using heavy loads. Use a dedicated 5V supply (power bank, 5V regulator) and connect grounds together.
This sketch uses the DFRobotDFPlayerMini library (install via Library Manager) and SoftwareSerial. If you don't use DFPlayer, ignore the DFPlayer parts.
// AutoBin: ultrasonic -> servo, optional DFPlayer voice
#include <Servo.h>
#include <SoftwareSerial.h>
#include "DFRobotDFPlayerMini.h"
Servo binServo;
const int trigPin = 7;
const int echoPin = 6;
const int servoPin = 5;
const int triggerDistance = 20; // cm
unsigned long lastTrigger = 0;
const unsigned long triggerCooldown = 2500; // ms
// DFPlayer (optional)
SoftwareSerial dfSerial(10, 11); // RX, TX (to DFPlayer)
DFRobotDFPlayerMini dfplayer;
bool useDFPlayer = true;
void setup() {
Serial.begin(9600);
binServo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
binServo.write(10); // rest angle
// init DFPlayer
if (useDFPlayer) {
dfSerial.begin(9600);
if (!dfplayer.begin(dfSerial)) {
Serial.println("DFPlayer not found");
useDFPlayer = false;
} else {
dfplayer.volume(20); // 0..30
}
}
}
long readDistanceCm() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000);
long dist = duration * 0.034 / 2;
return dist;
}
void openBin() {
// play sound if available
if (useDFPlayer) dfplayer.play(1); // file 0001.mp3 on microSD
binServo.write(75); // adjust to your mech
delay(700);
binServo.write(12); // back to rest
}
void loop() {
long d = readDistanceCm();
if (d > 0 && d < triggerDistance) {
if (millis() - lastTrigger > triggerCooldown) {
lastTrigger = millis();
openBin();
}
}
delay(120);
}
Put an mp3 named 0001.mp3 on the root of the microSD for DFPlayer to play track 1. If you prefer voice TTS, skip DFPlayer and use a phone + HC-05 to send a signal to Arduino to play an action.
I reused the exact same servo+spoon approach for the toilet flusher. Mount the spoon or small lever to push the flush lever, calibrate angles, and protect the servo from splashes (use a small enclosure or waterproof the area).
Parts: 1-channel 5V relay module, Arduino, HC-05 Bluetooth (optional), lamp or LED strip, appropriate AC caution if switching mains.
Relay module:
Vcc -> 5V
GND -> GND
IN -> Arduino pin 4 (digital output)
HC-05 (optional, for Bluetooth control):
Vcc -> 5V (or 3.3V depending on module)
GND -> GND
TX -> Arduino RX via SoftwareSerial pin 8
RX -> Arduino TX via SoftwareSerial pin 9
Lamp:
Lamp's live wire -> relay COM
Lamp's neutral -> mains neutral (be careful)
Relay NO -> mains live (only connect mains if you know what you're doing)
SAFETY: If you are switching mains AC, you must know basic electrical safety. Use insulated connectors, fuse protection, and, if unsure, use a qualified electrician. For testing, use a low-voltage lamp or LED strip.
This listens for simple text commands over Bluetooth: ON or OFF. You can use a phone terminal app to send those commands.
#include <SoftwareSerial.h>
SoftwareSerial btSerial(8, 9); // RX, TX (to HC-05)
const int relayPin = 4;
void setup() {
Serial.begin(9600);
btSerial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // relay off (change if your module is active LOW)
}
void loop() {
if (btSerial.available()) {
String cmd = btSerial.readStringUntil('\\n');
cmd.trim();
Serial.println("BT cmd: " + cmd);
if (cmd.equalsIgnoreCase("ON")) {
digitalWrite(relayPin, HIGH);
Serial.println("Light ON");
} else if (cmd.equalsIgnoreCase("OFF")) {
digitalWrite(relayPin, LOW);
Serial.println("Light OFF");
}
}
// optional: echo Serial -> BT
if (Serial.available()) {
btSerial.write(Serial.read());
}
}
If you want voice commands, use phone voice assistant + a Bluetooth terminal app that converts speech to text then send commands to HC-05. Another option: connect a small microphone + speech-to-text module (more advanced).
triggerDistance.This is a practical, low-cost setup — perfect for demos and hacky home automation. If you want, I can:
Tell me which of those you want next and I’ll add it straight into this page.