Free delivery on orders above Rs 900 | Single Delivery charges for Multiple Items


Your Cart is Empty

Back To Shop


Your Cart is Empty

Back To Shop

Step-By-Step Guide: How To Build Your Own IoT Water Level Indicator with Nodemcu ?

Building your own IoT water level indicator with NodeMCU is a fun and educational project that combines hardware and software development. Below is a step-by-step guide to help you create your water level indicator:

Step 1: Gather the Required Components:

Before you begin, make sure you have all the necessary components:

  1. NodeMCU development board (ESP8266)
  2. Ultrasonic distance sensor (HC-SR04)
  3. Breadboard and jumper wires
  4. USB cable for NodeMCU
  5. Power source (e.g., USB power bank or USB wall adapter)
Step 2: Understand the Working Principle:

The water level indicator works on the principle of ultrasonic distance measurement. The HC-SR04 sensor emits ultrasonic waves, which bounce back when they encounter an obstacle (water surface in this case). The sensor then calculates the distance based on the time taken for the waves to return.

Step 3: Circuit Connection:
  1. Connect the VCC and GND pins of the HC-SR04 sensor to the 3.3V and GND pins of the NodeMCU board, respectively.
  2. Connect the TRIG and ECHO pins of the HC-SR04 sensor to any GPIO pins of the NodeMCU (e.g., D1 and D2).
  3. Double-check all connections to ensure they are correct.
Step 4: Set Up Arduino IDE:
  1. Download and install the Arduino IDE from the official website.
  2. Open the Arduino IDE, go to “File” > “Preferences,” and in the “Additional Boards Manager URLs” field, paste the following link:
  3. Go to “Tools” > “Board” > “Boards Manager.” Search for “esp8266” and install the “esp8266” board package.
Step 5: Install Necessary Libraries:
  1. In the Arduino IDE, go to “Sketch” > “Include Library” > “Manage Libraries.”
  2. Search for and install the “NewPing” library, which is essential for working with the HC-SR04 sensor.
Step 6: Write the Code:

Now, it’s time to write the code for the water level indicator. The code should read the distance measured by the HC-SR04 sensor and communicate it to a cloud service for remote monitoring.

Here’s a simple example code to get you started:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <NewPing.h>

const char* ssid = “YOUR_WIFI_SSID”;
const char* password = “YOUR_WIFI_PASSWORD”;
const char* mqttBroker = “MQTT_BROKER_IP”;
const char* mqttTopic = “water_level”;

#define TRIGGER_PIN D1
#define ECHO_PIN D2
#define MAX_DISTANCE 200

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
Serial.println(“Connecting to WiFi…”);

Serial.println(“Connected to WiFi”);
client.setServer(mqttBroker, 1883);

void reconnect() {
while (!client.connected()) {
Serial.println(“Connecting to MQTT…”);
if (client.connect(“WaterLevelClient”)) {
Serial.println(“Connected to MQTT”);
} else {
Serial.print(“Failed with state “);

void loop() {
if (!client.connected()) {

int distance = sonar.ping_cm();
Serial.print(“Distance: “);
Serial.println(” cm”);

char msg[10];
sprintf(msg, “%d”, distance);
client.publish(mqttTopic, msg);

delay(5000); // Update every 5 seconds

Step 7: Configure the Code:

Replace the placeholders in the code with your Wi-Fi network credentials (SSID and password) and the MQTT broker’s IP address.

Step 8: Upload the Code:

Connect your NodeMCU to your computer via the USB cable, select the correct board and port in the Arduino IDE, and then click “Upload” to upload the code to the NodeMCU.

Step 9: Monitor Water Level:

Once the code is uploaded, open the Serial Monitor in the Arduino IDE to view the distance readings. The water level indicator will also publish the distance values to the specified MQTT topic, allowing you to view the data remotely using an MQTT client or an IoT platform.

That’s it! You have now built your own IoT water level indicator with NodeMCU. You can expand the project by adding additional sensors, implementing notifications, or integrating it with cloud services for data logging and visualization.



Your Cart is Empty

Back To Shop

It will take just few seconds to claim 7% Discount, After Submitting check Email for Coupon code.