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

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

View and Edit Project In Cirkit DesignerImage 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

Water Flow Sensor

0.96" OLED

Temperature Sensor

Pushbutton

WS2812 RGB LED Strip

2000mAh Battery

TP4056 Battery Charging Protection Module (Type C)

MT3608

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