Hey geeks, welcome back to Techatronic.
Do you know how a water level depth detection module works with NodeMCU? In this article, we are going to teach you how you can make a water level indicator using NodeMCU.
We have to dip the water level depth detection module into the water or fill the container with water in which the module is placed. This sensor is used to find the level of the water raised into the container.
This technology can be used to tell that the water tank is full or not. We have also discussed the working of a water level sensor with Arduino in our previous articles. You can also make the Blynk water level indicator which displays the real-time data in the Blynk app.
Table of Contents
How Does Water Level Indicator Work?
- The water level depth detection module can generate its output depending upon the level of water.
- While working with this module please place it vertically inside the container.
- You can see the readings on the IDEs serial monitor screen.
- Open the serial monitor which is given in the image below.
- When the output value of the water level sensor is above then 400 the red LED will glow,
- for the output value above then 540 the green and red LED will glow,
- and for the output value above then 580 all three LEDs will glow.
- But if you are using an RGB LED module one LED will glow at a time.
- The LEDs will go on and off according to the conditions specified in the code.
Simulation on the Serial monitor
Components Required
- NodeMCU esp8266 board
- Water level sensor
- Jumper wires
- Breadboard
- USB cable for uploading the code
- Three 220-ohm resistors
- LEDs of red, yellow, and green color or KY-016 RGB LED module
Water Level Indicator nodemcu circuit
It is very simple to make connections using a breadboard as you can see in the given diagram.still you have any doubt you can ask us in the comment section.
Connection table
Nodemcu esp8266 | LED R | LED Y | LED G | 220 Ohm Resistor |
D5 Pin | Anode Pin | |||
D6 Pin | Anode Pin | |||
D7 Pin | Anode Pin | |||
G,GND | Terminal 1 | |||
Cathode Pin | Cathode Pin | Cathode Pin | Terminal 2 |
Connections table
Nodemcu esp8266 | RGB Led Module |
D5 Pin | Terminal 1 B |
D6 Pin | Terminal 2 G |
D7 Pin | Terminal 3 R |
G ( GND ) | Terminal 4 |
- You have to make the circuit according to the given diagram.
- Connect the VCC pin of the water level sensor with the Vin pin of the NodeMCU.
- Attach the GND pin of the water level sensor with the GND pin of the NodeMCU.
- Join the signal pin of the water level sensor with the analog-0 pin of the NodeMCU.
If you are using the RGB LED module,
- connect the GND pin of the module with the GND pin of the NodeMCU.
- Join the R pin of the module with the digital-7 pin of the NodeMCU.
- Attach the G pin of the module with the digital-6 pin of the NodeMCU.
- Connect the B pin of the module with the digital-5 pin of the NodeMCU.
If you are using separate LEDs then
connect the negative leg of all the three LEDs with the GND pin of the NodeMCU through a 220-ohm resistance and the positive with digital-5, 6, 7 as shown above.
Water Level Indicator NodeMCU Circuit
NOTE: Please upload the code given below to the NodeMCU using Arduino IDE.
- Use this code if you are using separate LEDs
// TECHATRONIC.COM
int val = 0 ;
void setup()
{
Serial.begin(9600); // sensor buart rate
pinMode(14,HIGH); // Red led Pin Connected To D5 Pin
pinMode(13,HIGH); // Green Led Pin Connected To D7 Pin
pinMode(12,HIGH); // Yellow Led Connected To D6 Pin
}
void loop()
{
int s1=analogRead(A0); // Water Level Sensor output pin connected A0
Serial.println(s1); // See the Value In Serial Monitor
delay(100); // for timer
if(s1> 400 )
{
digitalWrite(14,HIGH); // Red led ON
}
else
{
digitalWrite(14,LOW); // Red led OFF
}
if(s1>540 )
{
digitalWrite(12,HIGH); // Green led ON
}
else
{
digitalWrite(12,LOW); // Green led OFF
}
if(s1>580 )
{
digitalWrite(13,HIGH); // Yellow led ON
}
else
{
digitalWrite(13,LOW); // Yellow led OFF
}
}
- Use this code if you are using a KY-016 RGB LED module
// TECHATRONIC.COM
int val = 0 ;
void setup()
{
Serial.begin(9600); // sensor buart rate
pinMode(14,HIGH); // Blue led Pin Connected To D5 Pin
pinMode(13,HIGH); // Red Led Pin Connected To D7 Pin
pinMode(12,HIGH); // Green Led Connected To D6 Pin
}
void loop()
{
int s1=analogRead(A0); // Water Level Sensor output pin connected A0
Serial.println(s1); // See the Value In Serial Monitor
delay(100); // for timer
if(s1>400 && s1<500 )
{
digitalWrite(14,HIGH); // Blue led ON
}
else
{
digitalWrite(14,LOW); // Blue led OFF
}
if(s1>500 && s1<550 )
{
digitalWrite(12,HIGH); // Green led ON
}
else
{
digitalWrite(12,LOW); // Green led OFF
}
if(s1>550 )
{
digitalWrite(13,HIGH); // Red led ON
}
else
{
digitalWrite(13,LOW); // Red led OFF
}
}
We hope that you like this project and now please try to make it on your own. If you are facing any difficulties while making this project feel free to ask in the comments sections below. Also, check tutorials on Arduino and Raspberry Pi written by us.
HAPPY LEARNING!