Skip to main content

IOT Based Water Level Indicator Project Using Esp32 And Ultrasonic Sensor

 



Water Level Indicator Project Using ESP32

 

Water Level Indicator with Alarm on Tank Full. IoT Wi-Fi smart water level indicator for tanks with mobile app control.


📟 OLED Display (0.96" I2C SSD1306)

 

OLED Pin        ESP32 Pin

VCC                   3.3V

GND                   GND

SDA                  GPIO 21

SCL                    GPIO 22

 


 

🔔 BUZZER

 

Buzzer Pin       ESP32 Pin

 

+          GPIO 26

-           GND

 

 

 

 

Each LED connects to an ESP32 GPIO pin via a current-limiting resistor.

 


 

📋 Parts Required:

 

3 × LEDs (Red, Yellow, Green)

 

3 × 220Ω resistors

 

Jumper wires

 

 


🧠 ESP32 to LED Connections:

 

LED     Color   Connect ESP32 Pin    Series Resistor            Connect To

 

LOW    Red     GPIO 15          220Ω   GND

MID     Yellow GPIO 4            220Ω   GND

HIGH   Green  GPIO 2            220Ω   GND

 

 


 

🔧 How to Connect Physically:

 

For each LED:

 

1. Long leg (anode +) → Connect to a GPIO pin via a 220Ω resistor

 

 

2. Short leg (cathode -) → Connect directly to GND

 

 

 

➡️ Full Code

 

// Full ESP32 Water Level Indicator Code

// Features: OLED Display, 3 LEDs, Buzzer, Web Server for Mobile View (ESP32-compatible tone handling)

 

#include <WiFi.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include <WebServer.h>

 

#define SCREEN_WIDTH 128

#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

 

// Probe sensor input pins

#define LOW_PIN 33

#define MID_PIN 32

#define HIGH_PIN 25

 

// LED output pins

#define LED_LOW 15

#define LED_MID 4

#define LED_HIGH 2

 

// Buzzer pin

#define BUZZER_PIN 26

#define BUZZER_CHANNEL 0

 

// WiFi credentials

const char* ssid = "YOUR_WIFI_SSID";

const char* password = "YOUR_WIFI_PASSWORD";

 

 

WebServer server(80);

String waterLevelStatus = "Unknown";

 

void setup() {

  Serial.begin(115200);

 

  // Pin modes

  pinMode(LOW_PIN, INPUT_PULLUP);

  pinMode(MID_PIN, INPUT_PULLUP);

  pinMode(HIGH_PIN, INPUT_PULLUP);

 

  pinMode(LED_LOW, OUTPUT);

  pinMode(LED_MID, OUTPUT);

  pinMode(LED_HIGH, OUTPUT);

 

  // Buzzer PWM setup

  //ledcSetup(BUZZER_CHANNEL, 1000, 8);

  //ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL);

  // Buzzer setup using tone()

  pinMode(BUZZER_PIN, OUTPUT);

 

  // OLED setup

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

    Serial.println("SSD1306 allocation failed");

    while (true);

  }

  display.clearDisplay();

  display.setTextColor(WHITE);

 

  // Connect to Wi-Fi

  WiFi.begin(ssid, password);

  display.setCursor(0, 0);

  display.setTextSize(1);

  display.println("Connecting to WiFi...");

  display.display();

 

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }

 

  Serial.println("WiFi connected");

  display.clearDisplay();

  display.setCursor(0, 0);

  display.println("WiFi Connected!");

  display.println(WiFi.localIP().toString().c_str());

  display.display();

  delay(2000);

 

  // Web server endpoint

  server.on("/", []() {

    String html = "<html><head><meta http-equiv='refresh' content='3'></head><body><h2>Water Level: " + waterLevelStatus + "</h2></body></html>";

    server.send(200, "text/html", html);

  });

  server.begin();

}

 

void loop() {

  server.handleClient();

 

  bool low = digitalRead(LOW_PIN) == LOW;

  bool mid = digitalRead(MID_PIN) == LOW;

  bool high = digitalRead(HIGH_PIN) == LOW;

 

  // Determine level status

  display.clearDisplay();

  display.setCursor(0, 0);

  display.setTextSize(1);

  display.println("Water Level:");

 

  if (high) {

    waterLevelStatus = "FULL";

    display.setTextSize(2);

    display.setCursor(0, 20);

    display.println("FULL");

    digitalWrite(LED_HIGH, HIGH);

    digitalWrite(LED_MID, LOW);

    digitalWrite(LED_LOW, LOW);

    //ledcWriteTone(BUZZER_CHANNEL, 1500);

    //delay(200);

    //ledcWriteTone(BUZZER_CHANNEL, 0);

    tone(BUZZER_PIN, 1500);

delay(200);

noTone(BUZZER_PIN);

  } else if (mid) {

    waterLevelStatus = "MEDIUM";

    display.setTextSize(2);

    display.setCursor(0, 20);

    display.println("MEDIUM");

    digitalWrite(LED_HIGH, LOW);

    digitalWrite(LED_MID, HIGH);

    digitalWrite(LED_LOW, LOW);

    //ledcWriteTone(BUZZER_CHANNEL, 0);

    noTone(BUZZER_PIN);

  } else if (low) {

    waterLevelStatus = "LOW";

    display.setTextSize(2);

    display.setCursor(0, 20);

    display.println("LOW");

    digitalWrite(LED_HIGH, LOW);

    digitalWrite(LED_MID, LOW);

    digitalWrite(LED_LOW, HIGH);

    //ledcWriteTone(BUZZER_CHANNEL, 1000);

    //delay(500);

    //ledcWriteTone(BUZZER_CHANNEL, 0);

    tone(BUZZER_PIN, 1000);

delay(500);

noTone(BUZZER_PIN);

  } else {

    waterLevelStatus = "EMPTY";

    display.setTextSize(2);

    display.setCursor(0, 20);

    display.println("EMPTY");

    digitalWrite(LED_HIGH, LOW);

    digitalWrite(LED_MID, LOW);

    digitalWrite(LED_LOW, LOW);

    //ledcWriteTone(BUZZER_CHANNEL, 800);

    //delay(800);

    //ledcWriteTone(BUZZER_CHANNEL, 0);

    tone(BUZZER_PIN, 800);

delay(800);

noTone(BUZZER_PIN);

  }

 

  display.display();

  delay(1000);

}


Comments

Popular posts from this blog

Clap On Off Switch Circuit Using Arduino

  Arduino Clap LED program #define MicAO 8 int ledPin = 13; int clap = 0; long detection_range_start = 0; long detection_range = 0; boolean status_lights = false; void setup() {   pinMode(MicAO, INPUT);   pinMode(ledPin,OUTPUT);   } void loop() { int status_MicAO = digitalRead(MicAO); if (status_MicAO == 0) { if (clap == 0) { detection_range_start = detection_range = millis(); clap++; } else if (clap > 0 && millis()-detection_range >= 50) { detection_range = millis(); clap++; } } if (millis()-detection_range_start >= 400) { if (clap == 2) { if (!status_lights) { status_lights = true; digitalWrite(ledPin, HIGH); } else if (status_lights) { status_lights = false; digitalWrite(ledPin, LOW); } } clap = 0; } }

How To Make Radar With Arduino UNO Using Ultrasonic Sensor

  Creating a radar system with an Arduino UNO and an ultrasonic sensor involves a few straight forward steps. First, you'll need to connect the ultrasonic sensor's trigger pin to one of the Arduino’s digital output pins and the echo pin to a digital input pin. Then, write a simple Arduino sketch to send a pulse from the trigger pin and measure the duration of the pulse received on the echo pin. This duration, proportional to the distance of an object from the sensor, can be calculated using the speed of sound. By continuously taking readings and mapping them to distances, you can plot these measurements to visualize objects in your environment, effectively creating a basic radar system. To display the results, you could use a serial monitor or even integrate an LCD display for real-time feedback. Here is the code below ,- //radar.ino #include <Servo.h>  const int trigPin = 9; const int echoPin = 8; long duration; int distance; Servo myServo;  void setup() {   p...

Obstacle Avoiding Robot Car Using Arduino - How To Make a Smart Car

How To Make Smart Robot Car With Arduino Obstacle avoiding robot car using Arduino, how to make a smart car with ultrasonic sensor, servo motor, and L298N motor driver module. Arduino UNO :- https://amzn.to/3MF9jky SG90 Servo Motor And HC-SR04 Ultrasonic Sensor :- https://amzn.to/3EX03pu LM298N motor driver module :- https://amzn.to/3y2tx3Y BO Motor with Wheel Pair :- https://amzn.to/38zFMu6 arduino smart car kit :- https://amzn.to/3kmtZlk Project Code :-  #include <Servo.h>          //Servo motor library. This is standard library #include <NewPing.h>        //Ultrasonic sensor function library. You must install this library //our L298N control pins const int LeftMotorForward = 7; const int LeftMotorBackward = 6; const int RightMotorForward = 4; const int RightMotorBackward = 5; //sensor pins #define trig_pin A1 //analog input 1 #define echo_pin A2 //analog input 2 #define maximum_distance 200 boolean goesForward = ...