How to make an automatic water tap machine using Arduino

automatic water tap

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

You need to make

  • Arduino UNO
  • Single-channel relay module
  • HC-sr04 Ultrasonic sensor
  • Mini DC pump
  • Pipe
  • PVC pipe 20mm( dia)
  • Jumper wire
  • 2x 9v battery or power bank or DC 9v power supply
  • Tub
  • Plywood
  • LED (Blue)
  • 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 copy the above code or you can download the code bellow

You can download the code from here

Video tutorial of Automatic water tap

25 Comments

  1. Hey there! I’ve been reading your website for a long time now and
    finally got the courage to go ahead and give
    you a shout out from Atascocita Texas! Just wanted to mention keep up the excellent job!

  2. Nice post. I was checking constantly this blog and I am inspired!
    Extremely helpful information specially the ultimate phase 🙂 I maintain such info a lot.
    I used to be seeking this certain information for a very
    long time. Thank you and good luck.

  3. Right here is the right blog for everyone who would like to
    find out about this topic. You understand a whole lot its almost tough to argue
    with you (not that I really will need to…HaHa).
    You definitely put a brand new spin on a topic which
    has been written about for a long time. Great stuff, just excellent!

  4. Thanks for a marvelous posting! I certainly enjoyed reading it,
    you could be a great author. I will make certain to bookmark your
    blog and definitely will come back someday. I want
    to encourage one to continue your great posts, have a nice weekend!

  5. Way cool! Some extremely valid points! I appreciate you writing this article and the rest of the site is really good.

  6. I was recommended this website by my cousin. I am not sure whether this
    post is written by him as no one else know such detailed
    about my problem. You’re amazing! Thanks!

  7. Hello! I could have sworn I’ve been to this site before but after looking at a few of the posts Irealized it’s new to me. Anyways, I’m definitely happy I came across it and I’ll bebook-marking it and checking back regularly!

  8. Nice post. I used to be checking continuously this weblog and I’m impressed!
    Very helpful information specially the ultimate section 🙂 I
    handle such information much. I was seeking this certain information for a very long time.
    Thank you and good luck.

Leave a Reply

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