Hey guys, this is kayode and together over the next couple of weeks we will be unboxing some really cool projects ranging from home automation systems to home security systems. At the end of each project am very sure that putting together your own project will not be a problem. Let’s get started.
In our day to day activities, it is common to have shortage of water or overflow of water in our storage tanks. This is because it takes time for individual who is manually operating the water pump to turn off the pumping machine and this may cause water spillage and at times the individual might not know that the water level has dropped so low until the tank is completely emptied. So why not build a system that monitors and controls this essential part of our life?
We are going to design a contactless water level indicator and controller using ultrasonic sensor. We will need the following;
- LCD 16X2
- Arduino uno
- Jumper wires
- A computer
- Your attention (Hope you will give it to me?)
Ultrasonic Sensor Module
The HC-SR04 ultrasonic module is a module that can provide non-contact measurement within the range of 2cm to 400cm with ranging accuracy that can reach 3mm. It works on the principle of echolocation.
Working principle of the project
The ultrasonic sensor as a trigger and an echo pin. The arduino provides a high signal of 10microseconds to this pin. After the HC-SR04 is triggered, it sends out eight 40Khz sound waves to the surface of the water. On getting to the surface of the water, the wave is echoed back to the sensor and the arduino reads the echo pin to determine time spent between triggering and receiving of the echo. Since we know that the speed of sound is around 340m/s then we can calculate the distance using;
Distance = (time/2)*speed of sound
To determine the level of the water in the tank we must know the total length of the tank. It is this value that will enable us calibrate our tank to our taste.
The circuit is self-explanatory. The trigger and echo pins of the ultrasonic sensor are connected to pins 9 and 8 of the arduino respectively. The LCD is connected to the arduino in 4-bit mode with the control pins RS, RW and EN connected to pins 2, GND and 3 respectively. The data pins D4-D7 are connected to pins 4 ,5 ,6 and 7 respectively. The negative terminal of the motor is connected at pin 11 of arduino through ULN2003 for turning on or turning off the water pump.
NOTE: For the purpose of testing this project, we made use of a dc motor as shown in the circuit diagram. A relay must be connected to the output of the ULN2003 when controlling a pumping machine.
The Ultrasonic sensor module is placed at the top of bucket (water tank) for demonstration. This sensor module will read the distance between itself and the water surface and it will show the level of water and the status of the motor on the LCD screen. If the distance is greater than or equal to 40 cm then Arduino turns ON the water pump. The LCD will show “LEVEL: LOW” and “MOTOR: ON”. When the distance reaches distance about 10cm arduino turns OFF the relay and LCD will show “LEVEL: FULL” and “MOTOR: OFF”. The LCD will also display medium and high levels when it get to these points.
We will do a little breakdown of the code and i will leave you with the code at the end.
First, we are going include the lcd library and also declare the pins we will be connecting things to.
Next, we set the pins the state of the pins we have earlier declared and display our initial message on the lcd.
We move into our void loop section where the main job is done. The first seven lines handle the sending of signals out from the arduino and receiving it back.
The next line deals with calculating the distance between the sensor and the water surface.
The final part of the code deals with the monitoring of the water level and then taking appropriate decision with respect to our motor.
That’s it guys copy and paste the code into the arduino IDE and voila you are good to go. Let me know if you have any question.