Introduction

  • In this article, I have explained how to measure water level and purity in a Tank with Arduino Mega 2560.
  • It can be used to give information about the purity of a tank and the water level.
Parts
  • Arduino Mega 2560
  • SRF-05 ultrasonic
  • LED-2
  • Hookup wires
SRF-05 Ultrasonic
  • The SRF005 ultrasonic range sensor detects objects in its path.
  • It can be used to calculate the range of the object.
  • It is sensitive enough to detect a 3cm diameter broom handle at a distance of over 3m.
    Figure 1: SRF-05 Ultrasonic
Connection:
Step 1: Connection from Sensor to Arduino board
  • Connect the GND of the sensor to the Gnd of the board.
  • Connect the VCC of the sensor to the 5V of the board.
  • Connect the trigger of the sensor to the digital pin 03 of the board.
  • Connect the echo of the sensor to the digital pin 04 of the board.
Step 2: Connection From LEDs to Arduino board
Led 1 connection:
  • positive pin = 13
  • negative pin = Gnd
Led 2 connection:
  • positive pin = 12
  • negative pin = Gnd
Programming
  1. #define ECHOPIN 03 // Pin to receive echo pulse
  2. #define TRIGPIN 04 // Pin to send trigger pulse
  3. void setup(){
  4. Serial.begin(9600);
  5. pinMode(ECHOPIN, INPUT);
  6. pinMode(TRIGPIN, OUTPUT);
  7. pinMode(13, OUTPUT);
  8. pinMode(12, OUTPUT);
  9. }
  10. void loop(){
  11. digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
  12. delayMicroseconds(2);
  13. digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
  14. delayMicroseconds(10);
  15. digitalWrite(TRIGPIN, LOW); // Send pin low again
  16. int distance = pulseIn(ECHOPIN, HIGH); // Read in times pulse
  17. distance= distance/58; // Calculate distance from time of pulse
  18. Serial.println(distance); // print distance
  19. delay(50); // Wait 50mS before next ranging
  20. digitalWrite(13, HIGH); // set the tank meter board LED on
  21. digitalWrite(12, HIGH); // set the Arduino onboard LED on
  22. delay(1000); // wait for a second
  23. digitalWrite(13, LOW); // set the tank meter board LED off
  24. digitalWrite(12, LOW); // set the Arduino onboard LED off
  25. delay(1000); // wait for a second
  26. }
Explanation:
  • It is used to check the range of the water in a tank
  • The pulse and distance are shown in the serial monitor
  • When the tank meter is on, led is ON
  • When the tank meter is off, led is OFF.
Output
Figure 2 : Output