How to make an automatic water tap machine using Arduino

automatic water tap

In this article, I am going to describe how you can make an automatic water tap machine or an automatic hand washing machine using Arduino UNO.

You need to make

  1. Arduino UNO
  2. Single-channel relay module
  3. HC-sr04 Ultrasonic sensor
  4. Mini DC pump
  5. Pipe
  6. PVC pipe 20mm( dia)
  7. Jumper wire
  8. 2x 9v battery or power bank or any AC to DC 9v power supply
  9. Tub
  10. Plywood
  11. LED (Blue)
  12. 220-ohm resistor

Connection

  • Ultrasonic module HC-sr04 Trig pin connect to Arduino Digital pin – 2
  • Ultrasonic module HC-sr04 Echo pin connect to Arduino Digital pin -3
  • Relay module signal in pin connect to Arduino Digital pin – 8
  • LED connect to pump (+) & (-) via 220 ohm resistor

Here I used two 9 v batteries, one for Arduino & another for pump & relay.

Connection diagram of automatic water tap

Arduino Code

//Ultasonic Sensor

//Pins connected to the ultrasonic sensor
#define trigPin  2
#define echoPin 3
//LED pins
#define led 9
#define pump 8


int range = 5;//range in inches

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  //initialize the sensor pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //initialize LED pins
  pinMode(led, OUTPUT);
  pinMode(pump, OUTPUT);
  //set LEDs
  digitalWrite(led, HIGH);
  digitalWrite(pump, LOW);
  
}
void loop()
{
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin, LOW);

  // Take reading on echo pin
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  if(inches < 5) {
    Serial.println("hand puted");
    digitalWrite(led, LOW);
    digitalWrite(pump, HIGH); 
     
    delay(100);
  } else {
    Serial.println("no hand");
     digitalWrite(led, HIGH);
     digitalWrite(pump, LOW); 
     delay(100);
  }  
  
  delay(200);
}

long microsecondsToInches(long microseconds)
{

  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}





You can download the code from here

making video

Leave a Reply

Your email address will not be published. Required fields are marked *