keyulpatel6464
Published © GPL3+

covid-19 hand wash using arduino

An automatic soap dispenser is a device that dispenses a controlled amount of soap solution.

IntermediateProtip527
covid-19 hand wash using arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

diagram_sibdi9lGVH.png

Code

Untitled file

C/C++
const int servo = 3;
const int trigPin = 10;
const int echoPin = 11;

// defines variables
long duration;
int distance;

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  myservo.attach(servo);  // attaches the servo on pin 9 to the servo object  
  myservo.write(0);   // Sets Servo to initially 0 degrees 
  Serial.begin(9600); // Starts the serial communication
}

void loop() {
    //
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    Serial.println(distance);
    //Servo
    if(distance<10){ //Check distance is less than 10cm 
       myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 
       delay(100);
       myservo.write(90);
       delay(100);
      myservo.write(135);
       delay(100);
       myservo.write(180); //Ajust how far you want the servo to go.
       delay(1000);
       myservo.write(0); // Reset the servo to 0 Degrees
       delay(3000);   //Delay the next time someone can get soap
    }                 
}

Untitled file

C/C++
const int servo = 3;
const int trigPin = 10;
const int echoPin = 11;

// defines variables
long duration;
int distance;

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  myservo.attach(servo);  // attaches the servo on pin 9 to the servo object  
  myservo.write(0);   // Sets Servo to initially 0 degrees 
  Serial.begin(9600); // Starts the serial communication
}

void loop() {
    //
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    Serial.println(distance);
    //Servo
    if(distance<10){ //Check distance is less than 10cm 
       myservo.write(0); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 
       delay(100);
       myservo.write(90);
       delay(100);
      myservo.write(135);
       delay(100);
       myservo.write(180); //Ajust how far you want the servo to go.
       delay(1000);
       myservo.write(0); // Reset the servo to 0 Degrees
       delay(3000);   //Delay the next time someone can get soap
    }                 
}

Credits

keyulpatel6464
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.