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.
ESP32
Water Flow Sensor
0.96" OLED
Temperature Sensor
Pushbutton
WS2812 RGB LED Strip
2000mAh Battery
TP4056 Battery Charging Protection Module (Type C)
MT3608
GND connected to:
VIN connected to:
3V3 connected to:
D15 connected to:
D2 connected to:
D4 connected to:
D5 connected to:
D21 connected to:
D22 connected to:
GND connected to:
Vcc connected to:
Signal connected to:
GND connected to:
VDD connected to:
SCK connected to:
SDA connected to:
Temp GND Black connected to:
Temp VDD Red connected to:
Temp DQ Data Yellow connected to:
Pin 2 connected to:
Pin 3 connected to:
DIN connected to:
5V connected to:
GND connected to:
VCC connected to:
GND connected to:
OUT - connected to:
OUT + connected to:
B+ connected to:
B- connected to:
VIN+ connected to:
VIN- connected to:
VOUT+ connected to:
VOUT- connected to:
#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