Arduino Water Level Indicator With LEDs

by | Mar 21, 2023 | Arduino, Basic Coding, Coding

Home » Coding » Arduino Water Level Indicator With LEDs

Introduction of the Project

Are you looking for a fun and engaging electronics project that can also be useful in your everyday life? Look no further than building your own Arduino water level indicator with LEDs! With just a few basic components and some programming skills, you can create a working water level sensor that lights up LEDs in response to changes in water level.

This project is not only a great way to improve your technical skills, but it’s also an opportunity to learn about water level sensing and monitoring and how to apply these concepts in real-world situations. So roll up your sleeves and get ready to dive into the world of DIY electronics with this exciting and practical project!

 

Supplies

In order to make an Arduino Water Level Indicator with LEDs, we will use LEDs of different colors to indicate the level of water in the tank. Apart from this, the components used are as follows:

Components

We have done our project on the TinkerCad website. If you are planning to do physical projects, you can buy the components online from amazon or any electronics store near you.

Circuit Diagram

Steps To Build An Arduino Water Level Indicator With LEDs

Step 1: Arrange all the components on the Digital Board or your workspace Table.

Ultrasonic Distance Sensor:

Step 2: Connect the Power terminal of the Ultrasonic Distance Sensor to the 5V pin of the Arduino at its Analog Side.

Step 3: Connect the Trigger Terminal of the Ultrasonic Distance Sensor to the 10-number pin of the Arduino.

Step 4: Connect the Echo Terminal of the Ultrasonic Distance Sensor to the 11-number pin of the Arduino.

Step 5: Connect the Ground Terminal of the Ultrasonic Distance Sensor to the GND pin of the Arduino.

LEDs:

Step 6: Connect the Cathode terminal of the LED to the GND pin of the Arduino through a resistor.

Step 7: Connect the Anode terminal of the LED to the 4, 5, & 6 number pins of the Arduino.

Source Code

int distance = 0;
int red = 4;
int blue = 5;
int green = 6;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);


digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);


return pulseIn(echoPin, HIGH);
}
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void loop()
{
distance = 0.01723 * readUltrasonicDistance(10, 11);
if(distance >= 200)
{
digitalWrite(red, HIGH);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
delay(2000);
}
if(distance > 100 && distance < 200)
{
digitalWrite(red, LOW);
digitalWrite(blue, HIGH);
digitalWrite(green, LOW);
delay(2000);
}
if(distance <= 100)
{
digitalWrite(red, LOW);
digitalWrite(blue, LOW);
digitalWrite(green, HIGH);
delay(2000);
}
}

Explanation of the Code

1. Initially, we initialized an integer variable ‘distance’ to 0 and three other variables ‘red’, ‘blue’, and ‘green’ to the Arduino pin number to which the LED is connected.

2. Then, we used a function to read ultrasonic distance using two parameters, which are inputs for the sensor. In the setup function, we have configured pin numbers 4, 5, & 6 for output purposes.

3. In the loop function, we are calculating the distance of the water from the top of the tank in centimeters and storing that value in a variable.

4. After this, we use an if statement, in which

  • If the distance is greater than 200cm (which means the tank is almost empty), the red LED will glow.
  • If the distance is less than 100 cm (which means the tank is almost full), the green LED will glow.
  • If it is in between the two, the blue LED will glow.

In this way, the level of the water will be indicated using different colored LEDs.

Output

Arduino Water Level Indicator With LEDs

On starting the simulation, the LEDs will glow as per the level of the water.

 

More Arduino Projects>>>

You May Also Like To Create…

0 Comments

Submit a Comment

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