Automatic Sanitizer dispenser
// Written by Anas.AP
// Using Arduino IDE 1.8.12
// Using HC-SR04 Module
// Tested on 16 May 2020
//If you have do

Automatic sanitizer dispenser using Arduino

submited by
Style Pass
2020-09-08 07:34:39

Automatic Sanitizer dispenser // Written by Anas.AP // Using Arduino IDE 1.8.12 // Using HC-SR04 Module // Tested on 16 May 2020 //If you have doubts please mail me at tommysoftwares@gmail.com // —————————————————————- //

int relayPin=5;//attach relays in to D5 of Arduino(DC Pump is connected to Arduino) // defines variables long duration; // variable for the duration of sound wave travel int distance; // variable for the distance measurement

long inch; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT pinMode(relayPin, OUTPUT); Serial.begin(9600);// Serial Communication is starting with 9600 of baudrate speed 9600 Serial.println(“Ultrasonic Sensor HC-SR04 Test”); // print some text in Serial Monitor Serial.println(“with Arduino UNO”);

// Clears the trigPin condition digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds 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; // Speed of sound wave divided by 2 (go and back) inch=distance/2.54;//converting cm to inch // Displays the distance on the Serial Monitor if(distance<8)//Set the distance in centemeters(When an obstacle is detected the liquid will dispense) { digitalWrite(relayPin, LOW);//LOW for the relay to be on delay(370);//For how many milliseconds your Pump works for pumping the liquid(Dispensing quantity) digitalWrite(relayPin, HIGH);//HIGH for the relay to be off delay(3700);//Delay after each dispensing } else { digitalWrite(relayPin, HIGH); }

Leave a Comment