Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266 NodeMCU Automated Water Tank Filling System

View and Edit Project In Cirkit DesignerImage of ESP8266 NodeMCU Automated Water Tank Filling System

Automatic Tank Filling System Documentation

Summary

The Automatic Tank Filling System is designed to control a water pump using an ESP8266 NodeMCU microcontroller. The system incorporates two water level sensors to monitor the water level within a tank. The pump is managed based on the feedback from these sensors: it is turned off when both sensors detect water, and it is turned on when neither sensor detects water. A relay module is used to control the high-power circuit of the water pump, which is powered by a 9V battery.

Component List

ESP8266 NodeMCU

Water Level Sensor (x2)

1 Channel 5V Relay Module

9V Battery

Water Pump

Wiring Details

ESP8266 NodeMCU

Water Level Sensors

1 Channel 5V Relay Module

9V Battery

Water Pump

Documented Code

/*
 * Automatic Tank Filling System
 * This code controls a water pump using an ESP8266 NodeMCU. The system uses two
 * water level sensors to detect the water level in a tank. When both sensors
 * detect water, the pump is turned off. When neither sensor detects water, the
 * pump is turned on.
 */

#include <Arduino.h>

const int lowSensorPin = 4;  // Low water level sensor connected to D2 (GPIO4)
const int highSensorPin = 5; // High water level sensor connected to D1 (GPIO5)
const int relayPin = 0;      // Relay module connected to D3 (GPIO0)

void setup() {
  pinMode(lowSensorPin, INPUT);  // Set low sensor pin as input
  pinMode(highSensorPin, INPUT); // Set high sensor pin as input
  pinMode(relayPin, OUTPUT);     // Set relay pin as output
  digitalWrite(relayPin, LOW);   // Initialize relay to off
}

void loop() {
  bool lowSensorState = digitalRead(lowSensorPin);  // Read low sensor state
  bool highSensorState = digitalRead(highSensorPin); // Read high sensor state

  if (lowSensorState == HIGH && highSensorState == HIGH) {
    digitalWrite(relayPin, LOW);  // Turn off pump if both sensors detect water
  } else if (lowSensorState == LOW && highSensorState == LOW) {
    digitalWrite(relayPin, HIGH); // Turn on pump if neither sensor detects water
  }

  delay(1000); // Wait for 1 second before next reading
}

This code is designed to be uploaded to the ESP8266 NodeMCU. It initializes the pins connected to the water level sensors and the relay module. In the main loop, it reads the state of both water level sensors and controls the relay accordingly, which in turn controls the water pump.