Automatic Water Pump Controller

Making a automatic water pump controller using arduino board.In this project I will be using a adruino UNO you can also use any other arduino board for this.

Materials Required

LET'S Begin With The Code

To upload the code we will need a software called arduino IDE.To download it click here.
Copy paste the code given below and upload it to arduino UNO board.Keep in mind that you have selected correct board and port before uploading the code. 

int trigpin=7;
int echopin=6;
int state=0;
void setup()  {
  Serial.begin(9600);
  }

void loop(){
  long duration, distance;
  pinMode(trigpin, OUTPUT);
  digitalWrite(trigpin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin, LOW);
  pinMode(echopin, INPUT);
  duration = pulseIn(echopin, HIGH);
  distance = duration/24/2;
  Serial.println(distance);
  if (distance<=3){
     digitalWrite(2, LOW);
  }
  else if(distance>10){ 
      
    digitalWrite(2, HIGH)
  }
}


(NOTE:-Replace '10' in else if condition(else if(distance>10){)  according to the height of you tank.)

Connections

Arduino Projects

1)Ultrasonic Sensor

Connect ultrasonic sensor's vcc and gnd pin to 5v and gnd of aduindo board respectively.Now connect echo pin to digital pin 6 and trig pin to digital pin 7 on board.

2)Relay Module

Connect power(center) pin of module to positive terminal of battery and gnd(right) of module to bread board which in turn will be connected to negative terminal of battery and gnd of arduino board.

(Note:- We are using a bread board because we have to connect gnd pin of relay module to negative terminal of battery and also with gnd of arduino board.Remember we have to always connect negative terminal of external power supply(like battery) to gnd.)

Now replace the switch of the water pump with relay by connecting the two wires of switch to normally closed(left) and common(center) outlet of the relay module.

Working

Place the ultrasonic sensor on top of the tank. Ultrasonic sensor calculates the distance and according to the code if distance is less than or equal to 3cm it switch offs the pump and if the distance is grater than 10(which is recommended to be changed according to your need) the relay turn on the pump.

(Note:- Ultrasonic sensor is placed at the top hence if the distance increases it means level of water is decreasing and vice-versa.)
Previous
Next Post »

4 comments

Click here for comments
gromit4x4
admin
March 16, 2019 at 2:27 AM ×

Above sketch seems to be missing: int trigpin = 7;

Reply
avatar
April 3, 2019 at 6:52 AM ×

Thank you for the correction. I have updated the sketch.

Reply
avatar
Unknown
admin
June 11, 2020 at 4:48 PM ×

Code is not working

Reply
avatar
April 8, 2021 at 12:08 PM ×

Hello Dear ... I Read your blog, it have very nice explanation about petrol water pump prices in Kenya. I have already work on this solar project, so i have more details of water Pump and Controller

Reply
avatar