Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Submersible water pump - 5V
Relay Module (Generic)
Solderless Breadboard Half Size
Software & Tools
Arduino IDE
Project description
Code
Automatic Faucet (Touchless) using Arduino
arduino
1// 66. AUTOMATIC FAUCET(TOUCHLESS) USING ARDUINO 2// ARDUINO PROJECTS BY R 3// AUTHOR: RUCKSIKAA RAAJKUMAR 4#define trig 5 5#define echo 4 6const int Relay = 6; 7long duration; 8int distance; 9void setup() { 10 pinMode(trig, OUTPUT); // Set the trigger pin as OUTPUT 11 pinMode(echo, INPUT); // Set the echo pin as INPUT 12 pinMode(Relay, OUTPUT); // Configure the pin of the relay module as OUTPUT 13 Serial.begin(9600); // Set baud rate as 9600 14} 15void loop() { 16 digitalWrite(trig, LOW); 17 delayMicroseconds(5); 18 digitalWrite(trig, HIGH); 19 delayMicroseconds(10); 20 digitalWrite(trig, LOW); 21 duration = pulseIn(echo, HIGH); // Calculate time taken (in microseconds) for the pulse emitted by the trigger pin to reach the echo pin. 22 distance = (duration/2) * (331.3/10000); // Calculate the distance from the sensor to the obstacle in cm, using the speed of sound in air(m/s) and the time taken (stored in duration variable) 23 Serial.println(distance); 24 if(distance>1 && distance<10){ 25 digitalWrite(Relay, HIGH); //Turns on the submersible water pump or solenoid water valve 26 }else{ 27 digitalWrite(Relay, LOW); //Turns off the submersible water pump or solenoid water valve 28 } 29 delay(2000); // Set a delay period of 2 seconds to prevent the clicking of the relay module 30} 31
Downloadable files
Schematic
Schematic

Schematic
Schematic

Comments
Only logged in users can leave comments