Guys, If we replace all the manual taps with a smart one that opens and closes on its own automatically how do you feel. Here we are not only save water but also have a healthier lifestyle since we don’t have to operate the tap with our dirty hands. So in this project we will build a Automatic Water Dispenser using Arduino and a Solenoid valve that can automatically give you water when a glass is placed near it. Sounds cool right! So let’s build one...
Components Required
1. | Arduino UNO | * 1 |
2. | Solenoid Valve | * 1 |
3. | Ultrasonic Sensor(HC-SR04) | * 1 |
4. | IRF540 MOSFET | * 1 |
5. | Resistor(10K ohm) | * 1 |
6. | Resistor(1K ohm) | * 1 |
7. | Bread Board | * 1 |
8. | Jumper Wires | * 1 |
Circuit Diagram
Program
#define trigger 9
#define echo 8
#define LED 13
#define MOSFET 12
float time=0,distance=0;
void setup()
{
Serial.begin(9600);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(LED,OUTPUT);
pinMode(MOSFET,OUTPUT);
delay(2000);
}
void loop()
{
measure_distance();
if(distance<10)
{
digitalWrite(LED,HIGH);digitalWrite(MOSFET,HIGH);
}
else
{
digitalWrite(LED,LOW);digitalWrite(MOSFET,LOW);
}
delay(500);
}
void measure_distance()
{
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
}