Regular hand washing and use of sanitizer is the only way to remove the corona viruses from our hand. The health experts recommends the 20 seconds hand wash. 20 seconds ?. It is not possible to check the clock while washing the hand. The common stopwatch or timer is not suitable here. So here I am going to build a custom touchless 20 second timer.
Here I use a distance sensor to detect presence of hand. Then the microcontroller(here Arduino Uno) start the servo motor from 180 to 0. This rotation will take 20 seconds to complete. Here servo motor arm act as a pointer.
Buy electronic components with free shipping on utsource.net
Step - 1
First I am going create the sketch
Open Arduino IDE.
Here we use the servo motor. so we need to use the "servo.h" library for better communication. Now I define twopins, trigPin on 4 and echoPin on 5. And Then declare two variables. One is "duration" and other is "distance". If you don't know the purpose of this variable read my previous article "Interface ultrasonic sensor with Arduino". Then declare another variable "Myservo" for communicate between Arduino board and servo motor. Next declare another variable "pos" as loop variable.
#define echoPin 4
#define trigPin 5
int long duration;
Step - 2
Now we need to code setup part.
First set the pinMode of trigPin as "OUTPUT" and echoPin as "INPUT". And set the attach pin of servo motor. Here we are using pin number 3 of Arduino board.
Setup part is completed.
Step - 3
Next we need to code the loop part.
First set the trigPin as "LOW" for 2 microseconds. Then set the same pin to "HIGH" for 10 microseconds. Next set it back to "LOW". Then read the echoPin and store the time to "duration" by using "pulseIn()" function. Then calculate the distance with this duration.
Next we need to use a "if" and "else" to control servo with condition. In the if condition we need to use a for() loop. Three arguments are used in "for()" loop. First is the initial value of loop variable here loop variable is "pos". This value is 180. The second argument is maximum value of loop variable. This value is 0. ( why the initial value is 0 ? and maximum is 180? See the calibration part ). The third argument is "pos--" or "pos-1". Then write the value in "pos" to servo motor. Now add a delay function. The value is 111.11 milliseconds. Why it is 111.11 ?. Because, we need to rotate the servo motor 180 degree in 20 seconds or 20000 milliseconds. So 20000/180=111.11. Next code the else part. In "else" part, set the servo position in 180 degree. Then wait 200 milliseconds and repeat this step. For this purpose add another delay function.
The coding part is complete. the complete code is given in the code section. Upload the code to Arduino board.
Step - 4
Next is some craft work. We need to create a scale or a dial for understand the servo position or time.
You can either print above image or create your own. I strongly recommend the second option. You can get the Photoshop files from the end of this article. This shape paste on a cardboard piece. Then cut the outlines. Now paste it to the servo motor. Use the small arm as pointer or needle.(see the calibration part).
Step - 5
Arduino Digital Pin 3 - Servo signal pin
Arduino Digital Pin 4 - HC-SR 04 trig pin
Arduino Digital Pin 5 - HC-SR 04 echo pin
Arduino 5V pin - HC-SR 04 Vcc
Arduino 5V pin - Servo motor Vcc
Arduino GND - Servo motor GND
Arduino GND - HC-SR 04 GND
Here some same pins are used to different devices. You can use "T" connection for this purpose.
Step - 6
For calibrate the servo motor, turn on the Arduino after complete the the hardware connections. Then don't place your hand or any object in front of the distance sensor. Now the position of Servo motor is 180 degree. Then put the small arm on the shaft which points to least position (left hand side )of the scale.
Now mound the distance sensor near the servo. And connect adapter. The device is completed.
Please don't copy paste my code. Understand each lines and it's purpose. Then make your own.
You can join our telegram group here or search INNOVATION.
STAY HOME, STAY SAFE, STAY CREATIVE. Let break the chain.
Follow me on,
Instagram : five_volt_player
Facebook : Akshay Joseph
Github : akshayjoseph666
Share your experience and suggestions on the comment box.