Auto Sanitizer
Note
🌟 Welcome to the SunFounder Facebook Community! Whether you’re into Raspberry Pi, Arduino, or ESP32, you’ll find inspiration, help ideas here.
✅ Be the first to get free learning resources.
✅ Stay updated on new products & exclusive giveaways.
✅ Share your creations and get real feedback.
Kit purchase
Looking for parts? Check out our all-in-one kits below — packed with components, beginner-friendly guides, and tons of fun.
Name |
Includes ESP32 board |
PURCHASE LINK |
|---|---|---|
ESP32 Ultimate Starter Kit |
ESP32 WROOM 32E + |
|
Universal Maker Sensor Kit |
Course Introduction
This program uses an ESP32 board with an infrared obstacle avoidance sensor and a water pump.
The sensor is used to detect the presence of an object.
When an object is detected, the water pump is activated to dispense liquid (liquid hand soap).
Note
If this is your first time working with an ESP32 project, we recommend downloading and reviewing the basic materials first.
Required Components
In this project, we need the following components:
SN |
COMPONENT INTRODUCTION |
QUANTITY |
PURCHASE LINK |
|---|---|---|---|
1 |
ESP-WROOM-32 ESP32 ESP-32S Development Board |
1 |
|
2 |
USB Type-C cable |
1 |
|
3 |
Breadboard |
1 |
|
4 |
Wires |
Several |
|
5 |
Power Supply |
1 |
|
6 |
IR Obstacle Avoidance Sensor Module |
1 |
|
7 |
L9110 Motor Driver Module |
1 |
|
8 |
Centrifugal Pump |
1 |
Wiring
Common Connections:
L9110 Motor Driver Module
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.
A-1A: Connect to GPIO25 on the ESP32.
A-1B: Connect to GPIO26 on the ESP32.
IR Obstacle Avoidance Sensor Module
OUT: Connect to GPIO23 on the ESP32.
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.
Centrifugal Pump
Connect to L9110 Motor Driver Module MOTOR A.
Connect to L9110 Motor Driver Module MOTOR A.
Writing the Code
Note
You can copy this code into Arduino IDE.
Don’t forget to select the board(ESP32 Dev module) and the correct port before clicking the Upload button.
// ESP32 version: IR obstacle sensor + DC pump
// ---- Pins (ESP32 safe GPIOs) ----
const int SENSOR_PIN = 23; // IR sensor DO (active-LOW typical)
const int PUMP_INA = 25; // Pump driver input A
const int PUMP_INB = 26; // Pump driver input B (kept LOW for one direction)
// ---- Timings ----
const unsigned long PUMP_ON_MS = 700; // pump ON duration
const unsigned long REST_MS = 1000; // cooldown between shots
void setup() {
pinMode(SENSOR_PIN, INPUT); // if your module needs pull-up, use INPUT_PULLUP
pinMode(PUMP_INA, OUTPUT);
pinMode(PUMP_INB, OUTPUT);
// Ensure pump is off
digitalWrite(PUMP_INA, LOW);
digitalWrite(PUMP_INB, LOW);
Serial.begin(115200);
}
void loop() {
int sensorValue = digitalRead(SENSOR_PIN); // LOW = obstacle (typical)
Serial.println(sensorValue);
if (sensorValue == LOW) { // detected
digitalWrite(PUMP_INB, LOW); // one direction only
digitalWrite(PUMP_INA, HIGH); // pump ON
delay(PUMP_ON_MS);
digitalWrite(PUMP_INA, LOW); // pump OFF
delay(REST_MS); // avoid rapid retrigger
}
}