Make Your Water Tap💧 SMART!! | Arduino | Ultrasonic Sensor | Solenoid Valve

by __sreesanth__sre in Circuits > Arduino

344 Views, 4 Favorites, 0 Comments

Make Your Water Tap💧 SMART!! | Arduino | Ultrasonic Sensor | Solenoid Valve

WhatsApp Image 2024-06-20 at 6.04.46 PM.png

Traditional water taps have many unnoticeable problems like water wastage, Hygiene issues etc. This can be eastly avoided by replacing with an automatic water tap but the cost is too high. The cost effective solution is to convert an existing water tap to a smart tap.

So Here... I'm sharing how I automated a water tap using a simple circuit in PCB using Arduino and a Solenoid valve and a little bit of basic coding. There are many alternate sensors can be used to implement this project but best is ultrasonic sensor. Infrared sensor can also be used and hence we can avoid using Arduino board but Infrared sensor causes issues with sunlight.

This project can be done using basic knowledge in circuit designing, Soldering and coding and hence it is the best beginner project.

Supplies

  • Arduino UNO (or any arduino) (buy)
  • 12v Solenoid valve (Norally Closed) (buy)
  • Ultrasonic Sensor (buy)
  • 5v Relay
  • 2n222
  • 10k Resistor
  • Dot PCB
  • Header pins
  • 12v Adapter
  • Heat shrink sleeve

Making the Circuit

Schematic_Automating_water_tap_2024-06-20.png
WhatsApp Image 2024-06-20 at 5.55.29 PM (2).jpeg
WhatsApp Image 2024-06-20 at 5.55.29 PM.jpeg
WhatsApp Image 2024-06-20 at 5.55.29 PM (1).jpeg
WhatsApp Image 2024-06-20 at 5.55.08 PM.jpeg

So our aim is to actuate on the solenoid valve when we place hands in front of ultrasonic sensor. If you want to know more about ultrasonic sensor and its working, refer this article. Basically ultrasonic sensor is measuring distance infront of it. We've programmed the Arduino board to measure distance and when the distance is less than required value, then pin connected to solenoid valve is turn high. Solenoid valve is actually switching using a NPN transistor 2N222 and a relay since the valve is working in 12v and Arduino outputs 5v. (actually the relay is not necessary in this circuit since the solenoid valve works on 12 v itself. But I've included that in the case of upgrading/reusing this project. Also Using arduino promini or any similar board is enough for this project which is more handy for pcb and compact).


Transistor switching is required for Arduino with actuators like motors and solenoid valves because these devices require a significant amount of current to operate, which is beyond the capabilities of the Arduino’s output pins. Transistors provide a safe and reliable way to switch the current on and off, protecting both the Arduino and the devices. 

I have created a circuit design using easyeda and soldered everything in a dot PCB . I was planning to power up everything using the power jack of arduino uno using 12v power supply which can also be used for the solenoid valve. Since the VIN pin is directly connected to the power jack, I was able to take 12v for the valve from that pin itself. Hence no separate power jack or connections was required.

Programming the Arduino Board

Screenshot (8).png

After finishing the circuit making, connected the Arduino to pc using a USB cable, later compiled and uploaded the code below! The code is just measuring the distance with ultrasonic sensor and turning the relaypin high if the distance less than 21 cm(in my case).


const int trigPin = A0;    // TRIG pin
const int echoPin = A1;    // ECHO pin
const int relayPin= 8;
float duration, dist;
void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  digitalWrite(relayPin, LOW);
}


void loop()
{
  //ultrasonic sensor distance measuring
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  dist = 0.017 * duration;


  if(dist<=21){
    digitalWrite(relayPin, HIGH);
    delay(100);
  }
  else{
      digitalWrite(relayPin, LOW);
  }

}