Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Based Smart Water Monitoring System with OLED Display and Wi-Fi Connectivity

Image of ESP32-Based Smart Water Monitoring System with OLED Display and Wi-Fi Connectivity

Circuit Documentation

Summary

This circuit is designed to monitor water flow and temperature, display the data on an OLED screen, and control a WS2812 RGB LED strip based on the water flow rate. The system is powered by a 2000mAh battery and includes a TP4056 battery charging protection module and an MT3608 step-up converter. The ESP32 microcontroller is the central unit that interfaces with all sensors and peripherals, and it also connects to the internet via Wi-Fi to send data to a Blynk server.

Component List

  1. ESP32

    • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  2. Water Flow Sensor

    • Description: A sensor to measure the flow rate of water.
    • Pins: Signal, Vcc, GND
  3. 0.96" OLED

    • Description: A small OLED display for showing data.
    • Pins: GND, VDD, SCK, SDA
  4. Temperature Sensor

    • Description: A sensor to measure the temperature of water.
    • Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
  5. Pushbutton

    • Description: A simple pushbutton for user input.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  6. WS2812 RGB LED Strip

    • Description: An addressable RGB LED strip.
    • Pins: DIN, 5V, GND, DO
  7. 2000mAh Battery

    • Description: A rechargeable battery to power the circuit.
    • Pins: VCC, GND
  8. TP4056 Battery Charging Protection Module (Type C)

    • Description: A module for charging and protecting the battery.
    • Pins: OUT +, B+, B-, OUT -, +, -
  9. MT3608

    • Description: A step-up converter to boost the battery voltage.
    • Pins: VIN+, VIN-, VOUT+, VOUT-

Wiring Details

ESP32

  • GND connected to:

    • TP4056 Battery Charging Protection Module (Type C) OUT -
    • Water Flow Sensor GND
    • MT3608 VIN-
    • Pushbutton Pin 2
    • Temperature Sensor Temp GND Black
    • 0.96" OLED GND
  • VIN connected to:

    • MT3608 VIN+
    • TP4056 Battery Charging Protection Module (Type C) OUT +
    • Water Flow Sensor Vcc
    • Temperature Sensor Temp VDD Red
  • 3V3 connected to:

    • 0.96" OLED VDD
  • D15 connected to:

    • Temperature Sensor Temp DQ Data Yellow
  • D2 connected to:

    • Water Flow Sensor Signal
  • D4 connected to:

    • Pushbutton Pin 3
  • D5 connected to:

    • WS2812 RGB LED Strip DIN
  • D21 connected to:

    • 0.96" OLED SDA
  • D22 connected to:

    • 0.96" OLED SCK

Water Flow Sensor

  • GND connected to:

    • ESP32 GND
    • TP4056 Battery Charging Protection Module (Type C) OUT -
  • Vcc connected to:

    • ESP32 VIN
    • MT3608 VIN+
  • Signal connected to:

    • ESP32 D2

0.96" OLED

  • GND connected to:

    • ESP32 GND
    • MT3608 VIN-
  • VDD connected to:

    • ESP32 3V3
  • SCK connected to:

    • ESP32 D22
  • SDA connected to:

    • ESP32 D21

Temperature Sensor

  • Temp GND Black connected to:

    • ESP32 GND
    • MT3608 VIN-
  • Temp VDD Red connected to:

    • ESP32 VIN
    • MT3608 VIN+
  • Temp DQ Data Yellow connected to:

    • ESP32 D15

Pushbutton

  • Pin 2 connected to:

    • ESP32 GND
    • MT3608 VIN-
  • Pin 3 connected to:

    • ESP32 D4

WS2812 RGB LED Strip

  • DIN connected to:

    • ESP32 D5
  • 5V connected to:

    • MT3608 VOUT+
  • GND connected to:

    • MT3608 VOUT-

2000mAh Battery

  • VCC connected to:

    • TP4056 Battery Charging Protection Module (Type C) B+
  • GND connected to:

    • TP4056 Battery Charging Protection Module (Type C) B-

TP4056 Battery Charging Protection Module (Type C)

  • OUT - connected to:

    • ESP32 GND
    • Water Flow Sensor GND
  • OUT + connected to:

    • ESP32 VIN
    • MT3608 VIN+
    • Water Flow Sensor Vcc
    • Temperature Sensor Temp VDD Red
  • B+ connected to:

    • 2000mAh Battery VCC
  • B- connected to:

    • 2000mAh Battery GND

MT3608

  • VIN+ connected to:

    • TP4056 Battery Charging Protection Module (Type C) OUT +
    • ESP32 VIN
    • Water Flow Sensor Vcc
    • Temperature Sensor Temp VDD Red
  • VIN- connected to:

    • ESP32 GND
    • Pushbutton Pin 2
    • Temperature Sensor Temp GND Black
    • 0.96" OLED GND
  • VOUT+ connected to:

    • WS2812 RGB LED Strip 5V
  • VOUT- connected to:

    • WS2812 RGB LED Strip GND

Code Documentation

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

// OLED configuration
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Water flow sensor configuration
#define WATER_SENSOR_PIN 2
volatile int pulseCount = 0;
float flowRate = 0.0;
float waterConsumed = 0.0; // Liters

// Temperature sensor configuration
#define TEMP_SENSOR_PIN 15
OneWire oneWire(TEMP_SENSOR_PIN);
DallasTemperature tempSensor(&oneWire);

// Button configuration
#define BUTTON_PIN 4
volatile bool displayMode = 0; // 0 for Water Consumption, 1 for Temperature
volatile bool buttonPressed = false;

// NeoPixel configuration
#define NEOPIXEL_PIN 5
#define NUMPIXELS 16
Adafruit_NeoPixel strip(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);

// Wi-Fi and Blynk credentials
char auth[] = "YourBlynkAuthToken"; // Replace with your Blynk authentication token
char ssid[] = "YourWiFiSSID";       // Replace with your WiFi SSID
char pass[] = "YourWiFiPassword";   // Replace with your WiFi password

// Constants
const float calibrationFactor = 4.5; // Sensor-specific value
unsigned long lastTime = 0;
const unsigned long interval = 1000; // Update every second
unsigned long lastActivityTime = 0;  // OLED sleep timer
bool oledActive = true;

// Animations
int animationStep = 0;

// Function prototypes
void IRAM_ATTR pulseCounter();
void IRAM_ATTR handleButtonPress();
void updateNeoPixel(float flowRate);
void drawWaterAnimation();
void wakeOLED();

void setup() {
  Serial.begin(115200);

  // OLED initialization
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("Failed to initialize OLED");
    for (;;);
  }
  display.clearDisplay();
  display.display();

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 10);
  display.println("Initializing AquaTrack...");
  display.display();
  delay(2000);

  // Water flow sensor setup
  pinMode(WATER_SENSOR_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(WATER_SENSOR_PIN), pulseCounter, FALLING);

  // Temperature sensor setup
  tempSensor.begin();

  // Button setup
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handle