Skip to content

linotex/PowerMonitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Power Monitor - IoT Power Monitoring Device

Autonomous IoT device based on ESP32-C3 that monitors power presence and sends Telegram notifications when power status changes.

🎯 Purpose

Designed for monitoring electrical grid during rolling blackouts in Ukraine. The device runs on a Li-Ion battery (400-500mAh) and automatically notifies when power appears or disappears.

⚡ Features

  • 🔋 Autonomous operation
  • 📱 Telegram notifications: instant messages about power status changes
  • 📊 Battery monitoring: displays charge in % and volts
  • 🌐 Web interface: configuration through browser
  • 📺 OLED display: status display on button press
  • ⚙️ Config mode: short press toggles screen for accessing settings
  • Configurable interval: from 1 to 30 minutes between checks
  • 🔄 Factory Reset: reset to factory settings via button on boot

🛠️ Components

Component Description Notes
ESP32-C3 SuperMini Microcontroller WiFi, deep sleep support
TP4056 Li-ion charging module Overcharge protection
MT3608 Booster Boost voltage to 5V
Battery 400mAh - 500mAh Li-Ion 18650 or pouch cell
OLED 128x32 SSD1306 Display (I2C) Blue or white
10kΩ resistors 4 pieces For voltage divider
Diodes (SS34 recommended) 2 pieces (optional) Reverse current protection
Tactile button NO (normally open) For wake-up and config
USB charger 5V For power and charging 1-2A
Switch For battery disconnect

Detailed Connections:

TP4056 ↔ Battery:

TP4056 BAT+ → Battery (+)
TP4056 BAT- → Battery (-)

TP4056 ↔ USB charger:

TP4056 IN+ → USB +5V
TP4056 IN- → USB GND

TP4056 ↔ ESP32-C3 (power):

TP4056 OUT+ → [SWITCH] → MT3608 IN+
MT3608 OUT+ → [DIODE] → ESP32 5V (optional protection, SS34 recommended)
TP4056 OUT- → MT3608 IN- → ESP32 GND

Note: Diode protects ESP32 from reverse current if multiple power
sources are connected. Schottky diode (SS34) recommended for lower
voltage drop, but any diode works.

Voltage Divider #1 (power detector):

TP4056 IN+ ──[10kΩ]──┬──[10kΩ]── TP4056 IN- (GND)
                     │
                   GPIO2

Voltage Divider #2 (battery monitor):

TP4056 BAT+ ──[10kΩ]──┬──[10kΩ]── TP4056 BAT- (GND)
                      │
                    GPIO3

Button:

GPIO4 ──[BUTTON]── GND
(uses internal pull-up)

OLED display:

OLED VCC → ESP32 3.3V
OLED GND → ESP32 GND
OLED SDA → ESP32 GPIO8
OLED SCL → ESP32 GPIO9

🔧 Assembly Tips

Component Quality:

  • Only a small percentage of ESP32-C3 boards work reliably
  • Test WiFi functionality before final assembly
  • Use quality resistors (1% tolerance recommended)

Power Protection:

  • Diode prevents reverse current damage (Schottky recommended)
  • Essential if using multiple power sources
  • Install between MT3608 OUT+ and ESP32 5V
  • Any diode works, but Schottky has lower voltage drop

Battery Notes:

  • Lookup table calibration provides ±3-5% accuracy
  • Works with any Li-Ion chemistry (18650, pouch cell, etc.)
  • Capacity doesn't affect percentage calculation
  • Only voltage curve matters

📲 Setup

1. Creating Telegram Bot

  1. Message @BotFather in Telegram
  2. Send /newbot
  3. Choose name and username
  4. Save Bot Token (format: 123456:ABC-DEF1234ghIkl...)

2. Getting Chat ID

Option 1 (simple):

  1. Send /start to your bot
  2. Open in browser: https://api.telegram.org/bot<TOKEN>/getUpdates
  3. Find "chat":{"id":123456789} - this is your Chat ID

Option 2 (via bot):

  1. Message @userinfobot
  2. It will show your Chat ID

3. First Connection

  1. Upload firmware to ESP32-C3
  2. Device will create WiFi network: PowerMon (password shown on OLED display)
  3. Connect to this network from your phone
  4. Web form will open automatically or go to 192.168.4.1
  5. Enter data:
    • WiFi SSID and password
    • Telegram Bot Token and Chat ID
    • Device name (e.g., "Lviv")
    • Check interval (recommended 5 minutes)
  6. Press SAVE
  7. Device will reboot and connect to WiFi
  8. On successful setup you'll receive a Telegram message

🎮 Usage

Factory Reset

Hold button while powering on the device - instructions will appear on screen.

After Factory Reset device will create WiFi network PowerMon (password shown on display) for new configuration.

📱 Telegram Messages

On device startup:

🔄 Device started!
📡 IP: 192.168.1.100
⏰ UP: 15 secs
⚡ Power: ON

On power status change:

⚡ POWER: ON (5.00V)
🔋 BTR: 87% (3.85V)
⏰ UP: 2 h 15 min(s) 30 secs
📡 IP: 192.168.1.100

🔧 Calibration

Battery Calibration

If voltage or percentage shows incorrectly:

  1. Measure real battery voltage with multimeter (e.g., 3.99V)
  2. Check ADC raw in Serial Monitor (e.g., 2760)
  3. Calculate coefficient: 3.99 / 2760 = 0.001446
  4. Update constant BATTERY_CALIBRATION in code

Power Detector Calibration

  1. WITHOUT charger measure IN+/IN- → check ADC raw (e.g., 2287)
  2. WITH charger measure IN+/IN- → check ADC raw (e.g., 3976)
  3. Threshold should be in middle: (2287 + 3976) / 2 ≈ 3100
  4. Update constant POWER_THRESHOLD in code

Power Voltage Calibration

  1. Connect USB charger (5V)
  2. Check Serial Monitor:
   Power ADC raw: 3976 -> 9.94V  ← INCORRECT!
  1. Measure REAL voltage with multimeter on TP4056 IN+ (should be ≈5V)
  2. Calculate calibration:
   POWER_CALIBRATION = real_voltage / rawValue
   Example: 5.0V / 3976 = 0.001258

🐛 Troubleshooting

Device won't connect to WiFi:

  • Check SSID and password in settings
  • Make sure WiFi is 2.4GHz (ESP32 doesn't support 5GHz)
  • MT3608 boost converter creates electromagnetic interference. Try moving MT3608 or ESP32 further away

Telegram messages not arriving:

  • Check Bot Token and Chat ID
  • Use TEST TELEGRAM button in web interface
  • Make sure device is connected to internet

Incorrect voltage or percentage:

  • Perform calibration (see section above)

📚 Libraries

Install via Arduino IDE Library Manager:

  • Adafruit SSD1306 - for OLED display
  • Adafruit GFX Library - graphics library
  • UniversalTelegramBot by Brian Lough - for Telegram
  • ArduinoJson (v6) - for JSON processing
  • ESP32 board support - from Espressif

📄 License

MIT License - free to use, modify and distribute.

About

Power Monitoring

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors