Post

# Measure Water Level And Purity In A Tank With Arduino Mega 2560

• 12.9k
• 0
• 2

## 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.
4. void setup(){
5.   Serial.begin(9600);
6.   pinMode(ECHOPIN, INPUT);
7.   pinMode(TRIGPIN, OUTPUT);
8.   pinMode(13, OUTPUT);
9.   pinMode(12, OUTPUT);
10. }
11.
12. void loop(){
13.   digitalWrite(TRIGPIN, LOW);                   // Set the trigger pin to low for 2uS
14.   delayMicroseconds(2);
15.   digitalWrite(TRIGPIN, HIGH);                  // Send a 10uS high to trigger ranging
16.   delayMicroseconds(10);
17.   digitalWrite(TRIGPIN, LOW);                   // Send pin low again
18.   int distance = pulseIn(ECHOPIN, HIGH);        // Read in times pulse
19.   distance= distance/58;                        // Calculate distance from time of pulse
20.   Serial.println(distance);                     // print distance
21.   delay(50);                                    // Wait 50mS before next ranging
22.   digitalWrite(13, HIGH);    // set the tank meter board LED on
23.   digitalWrite(12, HIGH);   // set the Arduino onboard LED on
24.   delay(1000);              // wait for a second
25.   digitalWrite(13, LOW);     // set the tank meter board LED off
26.   digitalWrite(12, LOW);    // set the Arduino onboard LED off
27.   delay(1000);              // wait for a second
28.
29. }
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

Recommended Free Ebook
Similar Articles