covid-19 hand wash using arduino
An automatic soap dispenser is a device that dispenses a controlled amount of soap solution.
Components and supplies
1
SG90 Micro-servo motor
1
Jumper wires (generic)
1
Breadboard (generic)
1
Ultrasonic Sensor - HC-SR04 (Generic)
2
Arduino UNO
Apps and platforms
1
Arduino IDE
Project description
Code
Untitled file
c_cpp
1const int servo = 3; 2const int trigPin = 10; 3const int echoPin = 11; 4 5// defines variables 6long duration; 7int distance; 8 9#include <Servo.h> 10 11Servo myservo; // create servo object to control a servo 12// twelve servo objects can be created on most boards 13 14int pos = 0; // variable to store the servo position 15 16void setup() { 17 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 18 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 19 myservo.attach(servo); // attaches the servo on pin 9 to the servo object 20 myservo.write(0); // Sets Servo to initially 0 degrees 21 Serial.begin(9600); // Starts the serial communication 22} 23 24void loop() { 25 // 26 digitalWrite(trigPin, LOW); 27 delayMicroseconds(2); 28 // Sets the trigPin on HIGH state for 10 micro seconds 29 digitalWrite(trigPin, HIGH); 30 delayMicroseconds(10); 31 digitalWrite(trigPin, LOW); 32 // Reads the echoPin, returns the sound wave travel time in microseconds 33 duration = pulseIn(echoPin, HIGH); 34 // Calculating the distance 35 distance= duration*0.034/2; 36 // Prints the distance on the Serial Monitor 37 Serial.print("Distance: "); 38 Serial.println(distance); 39 //Servo 40 if(distance<10){ //Check distance is less than 10cm 41 myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 42 delay(100); 43 myservo.write(90); 44 delay(100); 45 myservo.write(135); 46 delay(100); 47 myservo.write(180); //Ajust how far you want the servo to go. 48 delay(1000); 49 myservo.write(0); // Reset the servo to 0 Degrees 50 delay(3000); //Delay the next time someone can get soap 51 } 52} 53
untitled
c_cpp
1const int servo = 3; 2const int trigPin = 10; 3const int echoPin = 11; 4 5// defines variables 6long duration; 7int distance; 8 9#include <Servo.h> 10 11Servo myservo; // create servo object to control a servo 12// twelve servo objects can be created on most boards 13 14int pos = 0; // variable to store the servo position 15 16void setup() { 17 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 18 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 19 myservo.attach(servo); // attaches the servo on pin 9 to the servo object 20 myservo.write(0); // Sets Servo to initially 0 degrees 21 Serial.begin(9600); // Starts the serial communication 22} 23 24void loop() { 25 // 26 digitalWrite(trigPin, LOW); 27 delayMicroseconds(2); 28 // Sets the trigPin on HIGH state for 10 micro seconds 29 digitalWrite(trigPin, HIGH); 30 delayMicroseconds(10); 31 digitalWrite(trigPin, LOW); 32 // Reads the echoPin, returns the sound wave travel time in microseconds 33 duration = pulseIn(echoPin, HIGH); 34 // Calculating the distance 35 distance= duration*0.034/2; 36 // Prints the distance on the Serial Monitor 37 Serial.print("Distance: "); 38 Serial.println(distance); 39 //Servo 40 if(distance<10){ //Check distance is less than 10cm 41 myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 42 delay(100); 43 myservo.write(90); 44 delay(100); 45 myservo.write(135); 46 delay(100); 47 myservo.write(180); //Ajust how far you want the servo to go. 48 delay(1000); 49 myservo.write(0); // Reset the servo to 0 Degrees 50 delay(3000); //Delay the next time someone can get soap 51 } 52} 53 54 55 56
untitled
c_cpp
1const int servo = 3; 2const int trigPin = 10; 3const int echoPin = 11; 4 5// defines variables 6long duration; 7int distance; 8 9#include <Servo.h> 10 11Servo myservo; // create servo object to control a servo 12// twelve servo objects can be created on most boards 13 14int pos = 0; // variable to store the servo position 15 16void setup() { 17 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 18 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 19 myservo.attach(servo); // attaches the servo on pin 9 to the servo object 20 myservo.write(0); // Sets Servo to initially 0 degrees 21 Serial.begin(9600); // Starts the serial communication 22} 23 24void loop() { 25 // 26 digitalWrite(trigPin, LOW); 27 delayMicroseconds(2); 28 // Sets the trigPin on HIGH state for 10 micro seconds 29 digitalWrite(trigPin, HIGH); 30 delayMicroseconds(10); 31 digitalWrite(trigPin, LOW); 32 // Reads the echoPin, returns the sound wave travel time in microseconds 33 duration = pulseIn(echoPin, HIGH); 34 // Calculating the distance 35 distance= duration*0.034/2; 36 // Prints the distance on the Serial Monitor 37 Serial.print("Distance: "); 38 Serial.println(distance); 39 //Servo 40 if(distance<10){ //Check distance is less than 10cm 41 myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 42 delay(100); 43 myservo.write(90); 44 delay(100); 45 myservo.write(135); 46 delay(100); 47 myservo.write(180); //Ajust how far you want the servo to go. 48 delay(1000); 49 myservo.write(0); // Reset the servo to 0 Degrees 50 delay(3000); //Delay the next time someone can get soap 51 } 52} 53 54 55 56
Untitled file
c_cpp
1const int servo = 3; 2const int trigPin = 10; 3const int echoPin = 11; 4 5// defines variables 6long duration; 7int distance; 8 9#include <Servo.h> 10 11Servo myservo; // create servo object to control a servo 12// twelve servo objects can be created on most boards 13 14int pos = 0; // variable to store the servo position 15 16void setup() { 17 pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output 18 pinMode(echoPin, INPUT); // Sets the echoPin as an Input 19 myservo.attach(servo); // attaches the servo on pin 9 to the servo object 20 myservo.write(0); // Sets Servo to initially 0 degrees 21 Serial.begin(9600); // Starts the serial communication 22} 23 24void loop() { 25 // 26 digitalWrite(trigPin, LOW); 27 delayMicroseconds(2); 28 // Sets the trigPin on HIGH state for 10 micro seconds 29 digitalWrite(trigPin, HIGH); 30 delayMicroseconds(10); 31 digitalWrite(trigPin, LOW); 32 // Reads the echoPin, returns the sound wave travel time in microseconds 33 duration = pulseIn(echoPin, HIGH); 34 // Calculating the distance 35 distance= duration*0.034/2; 36 // Prints the distance on the Serial Monitor 37 Serial.print("Distance: "); 38 Serial.println(distance); 39 //Servo 40 if(distance<10){ //Check distance is less than 10cm 41 myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 42 delay(100); 43 myservo.write(90); 44 delay(100); 45 myservo.write(135); 46 delay(100); 47 myservo.write(180); //Ajust how far you want the servo to go. 48 delay(1000); 49 myservo.write(0); // Reset the servo to 0 Degrees 50 delay(3000); //Delay the next time someone can get soap 51 } 52} 53
untitled
c_cpp
1const int servo = 3; 2const int trigPin = 10; 3const int echoPin = 4 11; 5 6// defines variables 7long duration; 8int distance; 9 10#include 11 <Servo.h> 12 13Servo myservo; // create servo object to control a servo 14// 15 twelve servo objects can be created on most boards 16 17int pos = 0; // variable 18 to store the servo position 19 20void setup() { 21 pinMode(trigPin, OUTPUT); 22 // Sets the trigPin as an Output 23 pinMode(echoPin, INPUT); // Sets the echoPin 24 as an Input 25 myservo.attach(servo); // attaches the servo on pin 9 to the servo 26 object 27 myservo.write(0); // Sets Servo to initially 0 degrees 28 Serial.begin(9600); 29 // Starts the serial communication 30} 31 32void loop() { 33 // 34 digitalWrite(trigPin, 35 LOW); 36 delayMicroseconds(2); 37 // Sets the trigPin on HIGH state for 38 10 micro seconds 39 digitalWrite(trigPin, HIGH); 40 delayMicroseconds(10); 41 42 digitalWrite(trigPin, LOW); 43 // Reads the echoPin, returns the sound wave 44 travel time in microseconds 45 duration = pulseIn(echoPin, HIGH); 46 // 47 Calculating the distance 48 distance= duration*0.034/2; 49 // Prints the 50 distance on the Serial Monitor 51 Serial.print("Distance: "); 52 Serial.println(distance); 53 54 //Servo 55 if(distance<10){ //Check distance is less than 10cm 56 myservo.write(0); 57 // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 58 delay(100); 59 60 myservo.write(90); 61 delay(100); 62 myservo.write(135); 63 64 delay(100); 65 myservo.write(180); //Ajust how far you want the servo 66 to go. 67 delay(1000); 68 myservo.write(0); // Reset the servo to 69 0 Degrees 70 delay(3000); //Delay the next time someone can get soap 71 72 } 73} 74 75 76 77
Downloadable files
diagram_sibdi9lGVH.png
diagram_sibdi9lGVH.png

Comments
Only logged in users can leave comments