Non-contact Switch for Public Water Dispenser – Using Arduino Uno Rev3

Maintaining hand hygiene and washing hands are the most important personal hygiene measures to prevent the new coronavirus. In daily life, we inevitably touch various public facilities, such as the switch of the company’s water dispenser. Since drinking water is everyone’s daily and you need to touch the switch of the dispenser many times a day. In order to avoid cross infection caused by bacterial virus transmission as much as possible, I made the simplest automatic sensor switch on my Arduino and shared it with you.

Hardware

Arduino Uno Rev3 X1

Grove Base Shield V2.0 for Arduino X1

Grove – IR Distance Interrupter v1.2 X1

Grove – Servo X1

Grove – Rotary Angle Sensor X1

USB Cable X1

Power Bank X1

Software

Arduino IDE

Coding


#include <Servo.h>
Servo myservo;  // create servo object to control a servo

int anglepin = A0;  // analog pin used to connect the potentiometer
int angle;    // variable to read the angleue from the analog pin

#define SENSOR  7  //connect IR Sensor to pin7

void setup() {
   Serial.begin(115200);
   myservo.attach(8);  // attaches the servo on pin 8 to the servo object
   pinMode(SENSOR,INPUT);
   myservo.write(15);
}

void loop() {
    short sensor=0;
    sensor=digitalRead(SENSOR);
   // Serial.print("sensor=");
    Serial.println((int)sensor);

  angle = analogRead(anglepin);            // reads the angleue of the potentiometer (angleue between 0 and 1023)
  angle = map(angle, 0, 1023, 0, 180);  

  
    if(0==sensor)
    {
        Serial.println("Sensor is triggered!!");
        delay(200);
        myservo.write(angle);
        
    }
    else{
            myservo.write(angle-30);
            }

}

Install the Device to a Suitable Location

Please follow and like us:
Wordpress Social Share Plugin powered by Ultimatelysocial