Automated Disinfectant Spray Dispenser COVID19

Canal de YouTube

Many of you have been asking me about a simple home project for dispensing gel and spraying disinfectant. Here is a small tutorial with diagram for wiring and some simple code to get you started.

The great thing about this project is that it is simple enough and the benefits are invaluable. There are so many cases of one family member bringing home the “germs” and unwillingly infecting other family members. Look out for your family, implement this project today!

Here is the code:


#include <Servo.h>
Servo myservo;
int calibrationTime = 30;
long unsigned int lowIn;

long unsigned int pause = 500;
boolean takeLowTime;
int pirPin = 6;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;

void setup() {
 Serial.begin(9600);
 pinMode(pirPin, INPUT);
 pinMode(ledPin, OUTPUT);
 digitalWrite(pirPin, LOW);
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
 delay(1000);
 myservo.write(0);
}

void loop() {

 if (digitalRead(pirPin) == HIGH) {
   Serial.print("Motion at: ");
   Serial.print(millis() / 1000);
   Serial.println(" secs");
   digitalWrite(ledPin,HIGH);
   digitalWrite(pirPin, LOW);
   spray();
   digitalWrite(ledPin,LOW);
 }
}

void spray() {
 for (int i = 0; i <= 1; i++) {
   myservo.write(180);              
   Serial.println(180);
   digitalWrite(ledPin,HIGH);
   delay(1000);                       // waits 15ms for the servo to reach the position
   myservo.write(0);
   Serial.println(0);
   digitalWrite(ledPin,LOW);
   delay(1000);                       // waits 15ms for the servo to reach the position
   myservo.write(180);             
   Serial.println(180);
   myservo.write(0);
   Serial.println(0);
   digitalWrite(ledPin,HIGH);
   delay(2000);
 }
}

Leave a Reply