Smart Battery Monitor (ESP8266) with OLED, REST API & Blynk IoT

Smart Battery Monitor (ESP8266) with OLED, REST API & Blynk IoT

ESP8266 Blynk IoT OLED (SSD1306) DS3231 RTC EEPROM REST API

A menu-driven smart battery monitoring system built on ESP8266, featuring a 0.96" OLED, DS3231 RTC with NTP sync, and persistent settings in AT24C32 EEPROM. It measures voltage, current, power, and state of charge (SOC) using sensors like INA219, WCS1600, and ADS1115, exposes a RESTful API for custom integrations, and connects to the Blynk IoT platform (mobile + web dashboards) for remote monitoring and control.

View Source on GitHub
Smart Battery Monitor ESP8266 - Build Preview

Table of Contents

  1. Required Components
  2. Circuit & Wiring
  3. Installation & Libraries
  4. Menu-Based OLED Interface
  5. REST API Endpoints
  6. Blynk IoT Integration
  7. Key Code Snippets
  8. Demo Video & Screenshots
  9. Downloadables
  10. Future Enhancements
  11. Author

Required Components

  • ESP8266 (NodeMCU)
  • INA219 – voltage & current sensor
  • ADS1115 (ADS1X15) – external ADC
  • WCS1600 – current sensor – Watch how it works
  • DS3231 RTC + AT24C32 EEPROM
  • 0.96″ OLED (SSD1306, I²C)
  • Push buttons for navigation
  • 1X 470uf capacitor
  • Screw Terminals
  • Jumper wires, breadboard/PCB, power module

Circuit & Wiring

Wiring Diagram 1 Wiring Diagram 2 WCS1600 Current Sensor Wiring
  • I²C: SDA/SCL → OLED, DS3231, ADS1115
  • INA219 & WCS1600 routed to ADC inputs (as per your design)
  • Buttons to digital GPIOs (e.g., D5/D6/D7) for Up/Down/Select/Back
  • Stable power supply and proper grounding recommended

PDF

View the wiring PDF below or download it in the Downloadables section.

Copper Clad PCB Circuit

Copper Clad PCB Circuit 1 Copper Clad PCB Circuit 2

Installation & Libraries

  1. Clone the repo: git clone https://github.com/akshit-singhh/Smart-Battery-Monitor-ESP8266-V1.0
  2. Open BatteryMonitor.ino in Arduino IDE.
  3. Select board: NodeMCU 1.0 (ESP-12E Module).
  4. Install the following libraries (Library/Boards Manager):
  • ESP8266 Core for Arduino (Boards Manager)
  • ArduinoJson (BenoĆ®t Blanchon)
  • RTClib (Adafruit)
  • Adafruit INA219
  • Adafruit SSD1306 (auto-installs Adafruit GFX)
  • Adafruit ADS1X15 (ADS1115/ADS1015)
  • QRCode (e.g., ricmoo/QRCode)

Built-ins used: Wire (I²C), ESP/ESP8266WiFi/ESP8266WebServer/ESP8266HTTPClient, stdio, Arduino core.

The on-device UI is a full, navigable menu with timeouts and status screens:

  • Live Data: Voltage, Current, Power, SOC, WiFi RSSI, IP, Uptime
  • Configuration: Battery Settings (capacity, thresholds, type), Screen Timeout, Reset SOC
  • Calibration: Current & Voltage calibration, auto-zero/manual offsets, Save/Load to EEPROM
  • Statistics: Cycle count, Total Energy (Wh), Runtime history
  • System Info: Firmware version, Sensor status, Memory, Uptime
  • GitHub: QR code linking to the repository
  • AP Mode: Start/Stop AP, AP details + QR to setup page
OLED Menu Demo GIF OLED Menu Screen 2 OLED Menu Screen 3 OLED Menu Screen 4
Each screen represents a different menu view from the OLED interface.

REST API Endpoints

You can verify and interact with these API endpoints directly from your web browser or using tools like Postman. Below are some examples based on the local IP http://192.168.1.99. Note: The IP address of your device may vary depending on your network configuration. Please check your device’s current IP address before testing the endpoints.

  • Using a web browser: Simply enter the endpoint URL in the browser’s address bar (works best with GET requests). For example, open http://192.168.1.99/live_data to see the real-time JSON data.
  • Using Postman:
    1. Open Postman and create a new request.
    2. Set the request method (GET, POST, etc.) based on the API endpoint.
    3. Enter the full URL (e.g., http://192.168.1.99/settings).
    4. If needed, add headers or body data (e.g., for POST requests).
    5. Click Send to view the response.
Endpoint Description
/live_data Real-time JSON: voltage, current, power, SOC, WiFi mode, RSSI, IP
Example: http://192.168.1.99/live_data
/serial_log Rolling log buffer with uptime + RTC timestamps
Example: http://192.168.1.99/serial_log
/settings (GET) Read calibration + SOC
Example: http://192.168.1.99/settings
/settings (POST) Update and persist settings (EEPROM)
Use Postman or similar tool to send POST request with JSON body.
/wifi_config Provision WiFi via JSON or HTML
Example: http://192.168.1.99/wifi_config
/sta_ip Return STA IP or NOT_CONNECTED
/reboot Reboot device

Sample Response: /live_data

{
  "voltage": 12.34,
  "current": 1.23,
  "soc": 87.5,
  "power": 15.18,
  "status": "Charging|Discharging|Idle",
  "rssi": -60,
  "mode": "AP|STA|AP_STA|NONE",
  "ip": "192.168.4.1"
}

Blynk IoT Integration

  • Mobile + Web dashboards with live telemetry and controls.
  • Template + Datastreams mapping to device variables (SOC, V, A, W, alarms).
  • Automations/Notifications for thresholds (e.g., low SOC, overcurrent).
Blynk Dashboard Screenshot
Blynk IoT web dashboard with live battery telemetry.

Blynk Datastream Configuration

In the Blynk Web Dashboard or Mobile App, set up the following Datastreams to match your firmware variables. These use virtual pins V0 through V9.

# Label Virtual Pin Type Units Min Max Format
1VoltageV0DoubleV020#.##
2CurrentV1DoubleA-10020#.##
3PowerV2Double--100600#.##
4State of ChargeV3Double%0100#.##
5Battery StatusV4String----
6Energy InV5DoubleWh01000#.##
7Energy OutV6DoubleWh01000#.##
8UptimeV7String----
9Backup TimeV8String----
10Charging TimeV9String----

Note: Ensure each datastream is correctly mapped to its corresponding virtual pin in the Blynk Template. These pins should be updated in your firmware using Blynk.virtualWrite(Vx, value).

Important: Before deploying the Blynk dashboard, double-check that your Blynk.virtualWrite(Vx, value) calls in the firmware match the configured datastreams above. Also verify all sensor connections and GPIO mappings (e.g., for current sensors, buttons, and I²C devices) in your wiring and code. Incorrect pin assignments or loose connections may result in invalid or missing telemetry.

Key Code Snippets

Example: serving live telemetry from the ESP8266 web server.

// Example handler (simplified)
server.on("/live_data", HTTP_GET, []() {
  StaticJsonDocument<256> doc;
  doc["voltage"] = voltage;
  doc["current"] = current;
  doc["soc"]     = soc;
  doc["power"]   = power;
  doc["rssi"]    = WiFi.RSSI();
  serializeJson(doc, server.client());
});

Full source and additional endpoints are available on GitHub.

Demo Video & Screenshots

Watch the demo:

Downloadables


Future Enhancements

  • ESP32 upgrade (more resources, optional BLE)
  • Historical charts & analytics on web dashboard
  • MQTT (Home Assistant / Node-RED)
  • Data export (CSV) and long-term logging

Author

Project by Akshit Singh