Create Your Own Automatic Soap Dispenser: A DIY Guide
Transform your bathroom into a smart space with a homemade automatic soap dispenser. This hands-free device not only adds a touch of elegance but also promotes hygiene. Here's a step-by-step guide to help you create your own automatic soap dispenser at home.
Materials Needed
- Empty soap dispenser bottle
- Arduino Uno board
- Ultrasonic sensor (HC-SR04)
- Jumper wires
- 9V battery and connector
- Pump (12V DC, 240L/h)
- Power supply for pump (12V, 1A)
- Hot glue gun and glue sticks
- Soldering iron and solder
Understanding the Components
Before we dive into the assembly process, let's understand the components:
- Arduino Uno: The brain of our dispenser, it processes signals from the sensor and controls the pump.
- Ultrasonic Sensor (HC-SR04): Detects the presence of hands under the dispenser.
- Pump: Dispenses the soap when activated by Arduino.
Assembling the Automatic Soap Dispenser
Step 1: Prepare the Pump
Attach the pump to the bottom of the soap dispenser bottle using hot glue. Ensure the pump's outlet aligns with the bottle's dispenser hole.

Step 2: Wire the Components
Connect the components as follows:
| Component | Arduino Pin | Power Supply/Pump |
|---|---|---|
| Ultrasonic Sensor (VCC) | 5V | 5V |
| Ultrasonic Sensor (GND) | GND | GND |
| Ultrasonic Sensor (TRIG) | 12 | |
| Ultrasonic Sensor (ECHO) | 13 | |
| Pump (Positive) | 12V | |
| Pump (Negative) | 9 | GND |
Step 3: Program the Arduino
Upload the following code to your Arduino board:
const int trigPin = 12;
const int echoPin = 13;
const int pumpPin = 9;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pumpPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
if (distance < 4) {
digitalWrite(pumpPin, HIGH);
delay(500);
digitalWrite(pumpPin, LOW);
}
}
Step 4: Test Your Automatic Soap Dispenser
Power up your dispenser using the 9V battery. Place your hand under the dispenser, and watch as it dispenses soap automatically. Adjust the distance threshold in the Arduino code if needed.

Congratulations! You've just created your own automatic soap dispenser. This DIY project not only saves you money but also adds a personal touch to your home. Happy tinkering!























