Athanasios Dimopoulos
Published © GPL3+

Automatic Soap Dispenser with 20 second hand washing LED

An ultrasonic sensor activated Automatic Soap Dispenser. Uses a LED to prompt 20 sec hand washing. Design compatible with common soap pumps.

IntermediateFull instructions provided12,114
Automatic Soap Dispenser with 20 second hand washing LED

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
4xAA battery holder
4xAA battery holder
×1
AA Batteries
AA Batteries
×4
Jumper wires (generic)
Jumper wires (generic)
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
Machine Screw, M4
Machine Screw, M4
M4x0.5 12mm
×1
Machine Screw, M3
Machine Screw, M3
M3x0.5 6mm
×1
Slide Switch, SPDT-CO
Slide Switch, SPDT-CO
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Liquid handwash soap bottle with soap pump
any commercial liquid soap bottle with common pump applicable
×1
0.2mm Diameter Clear Nylon Fish Fishing Line Spool
×1
Cable Tie, Belt Ty™ In Line
Cable Tie, Belt Ty™ In Line
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Drill / Driver, Cordless
Drill / Driver, Cordless

Story

Read more

Custom parts and enclosures

Automatic Soap Dispenser structural files

Download and 3D print preferably using PLA material the 2 structural stl CAD 3D models from the Thingiverse link attached.

Schematics

ASD device wiring diagram

Use this wiring diagram to connect the Arduino nano with the U/S sensor, the servo motor and all the other electric components of the device

Code

Automatic_soap_dispenser_hands.ino

Arduino
The source code to be loaded on the Arduino nano for the Automatic Soap Dispenser project. It controls the Ultra Sonic sensor, the servo motor and the LED to perform all required functions.
/* 
program by dimotha 29/3/2020
controls the SG90 servo motor based on the U/S sensor trigger input
The SG90 is assumed to be mounted on the ASD_base and the U/S sensor
on the ASD_lever. The whole assembly shall be mounted on the soap pump. 
see project instructions here:
https://dimotha.wordpress.com/automatic-soap-dispenser/
This is the hand washing version of the device
upon trigger:
- 10 doses by the soap pump
- 20 second LED blinikng to promt hand washing duration
*/

#include <Servo.h>  // SG90 servomotor driving program

#define echoPin 7   // U/S sensor Echo Pin
#define trigPin 8   // U/S sensor Trigger Pin
#define LEDPin 13   // Onboard LED


Servo servo;
int angle = 145;          // servo test
int maximumRange = 200;   // Maximum range needed U/S sensor
int minimumRange = 0;     // Minimum range needed U/S sensor
long duration, distance;  // Duration used to calculate distance -  U/S sensor

void setup() {

 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator

  servo.attach(9);
  servo.write(angle);
  Serial.begin(9600);
  delay(2000);
}


void loop() {
  digitalWrite(LEDPin, LOW);  // LED starts OFF
  
  angle=150;                  // servo up angle
  Serial.println(angle);
  servo.write(angle);         // servo/lever up
  delay(2000);  

/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 
 //Calculate the distance (in cm) based on the speed of sound in air
 distance = duration/58.2;
 
 if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer 
 to indicate "out of range" */
 Serial.println("-1");
 }
 else {
 /* Send the distance to the computer using Serial protocol
 to indicate successful reading. */
 Serial.println(distance);

/* when hand is at distance less than 7 cm from the U/S sensor
 * the servomotor will drive 10 pump soap doses. After this sequence 
 * the LED will blink for 20 seconds on a 0.5 sec ON / 0.5 sec OFF pattern. 
 */
if (distance<7) {         // condition trigger for soap dispensing

for(int i=1; i<11; i++){  // initiate soap dispensing
  angle=16;               // servo down angle
  Serial.println(angle);
  servo.write(angle);     // servo/lever down
  delay(1000);

  angle=150;              
  Serial.println(angle); 
  servo.write(angle);     // servo/lever back to up position
  delay(700);
       
}                         //end of soap dispensing

   
  for(int i=1; i<21; i++){      // Start blinking pattern
   digitalWrite(LEDPin, HIGH);  // LED ON
   delay(500);
   digitalWrite(LEDPin, LOW);   // LED OFF
   delay(500);
}
}  
}

}

Credits

Athanasios Dimopoulos

Athanasios Dimopoulos

0 projects • 4 followers
Design Engineer, Maker, DIY, Open - Source Hardware enthusiast, 3D Printing & Mechatronics

Comments