Last Updated on December 30, 2020 by technoreview85
It is an automatic hand sanitizer dispenser circuit & Arduino code for making an automatic sanitizer dispenser machine.

How it works
For making this circuit I used Arduino Nano & HC SR 04 Ultrasonic sensor.
when any object detected by the ultrasonic sensor within 15cm then the Arduino Nano digital pin 8 became high. this D8 pin is connected to an NPN transistor’s base via a resistor so when an object is detected near sensor the transistor flow negative voltage to relay & the 5v relay turn on the 12v dc pump & the liquid sanitizer flows from the spray nozzle. please check the circuit diagram given below.
You need to make
- Transistor 548b
- 5v relay
- 5 volt DC Regulator IC7805
- Capacitor 470mf/25v
- Resistor – 1 k, 220E
- Led
- Diode IN4007
- 5v mini buzzer ( Active buzzer)

- Arduino nano
- Hc sr 04 ultrasonic sensor
- Female header
- Terminal block 2 pin
- Female to male jumper 4 wire
- Vero board or Pref board

- DC12V Self-Priming Diaphragm Pump
- Low pressure spray nozzle (6mm)
Making circuit
Insert all components on pref board & connect asper circuit diagram

HC sr 04 trig pin connect to Arduino D2
HC sr 04 Echo pin connect to Arduino D3
connect buzzer + to Arduino D9 & D8 will be connected to the transistor base via 1K resistor.

Automatic sanitizer dispenser Arduino code
Now upload the code to Arduino Nano using Arduino IDE
//Ultasonic Sensor // sanitizer dispenser arduino code by http://technoreview85.com/ //Pins connected to the ultrasonic sensor #define trigPin 2 #define echoPin 3 #define pump 8 #define buzzer 9 int range = 7;//range in inches void setup() { // initialize serial communication: Serial.begin(9600); //initialize the sensor pins pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(pump, OUTPUT); pinMode(buzzer, OUTPUT); digitalWrite(pump, LOW); digitalWrite(buzzer, LOW); } void loop() { // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, inches, cm; // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(5); digitalWrite(trigPin, LOW); // Take reading on echo pin duration = pulseIn(echoPin, HIGH); // convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); if(inches < 7) { Serial.println("hand puted"); digitalWrite(pump, HIGH); digitalWrite(buzzer, HIGH); delay(1200); digitalWrite(pump, LOW); digitalWrite(buzzer,LOW); delay(3000); } else { Serial.println("no hand"); digitalWrite(pump, LOW); digitalWrite(buzzer,LOW); delay(50); } delay(200); } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
You can copy the code form above or Download INO file from hear

The video tutorial for this project