A robust, battery-powered IoT sensor logging system for ESP32 microcontrollers with cloud integration via Adafruit IO. Designed for reliable long-term operation with deep sleep power management, watchdog protection, and flexible multi-output debugging.
- Low Power Operation: Deep sleep between readings with I2C power-down for extended battery life
- Robust Error Handling: Hardware watchdog timer, automatic retries, and graceful failure recovery
- Multi-Output Debugging: Serial, Remote (Adafruit IO), and Syslog logging - enable any combination
- Cloud Integration: Automatic data publishing to Adafruit IO for remote monitoring
- Modular Design: Reusable library (
ESP32_IoT_Utils) for easy project development - Battery Monitoring: Built-in battery voltage reading and reporting
- Easy Configuration: Single-file configuration for sensors, intervals, and debug options
- Board: Adafruit QtPy ESP32-S3 with BFF Backpack
- Sensor: HDC302x Temperature/Humidity Sensor (via STEMMA QT)
- Power: Battery monitoring on A2 (via voltage divider)
- Connectivity: WiFi to Adafruit IO
- Temperature (Β°F)
- Humidity (%)
- Battery Voltage (V)
- Device status and diagnostics
-
Arduino IDE (1.8.x or 2.x) with ESP32 board support
-
Required Libraries (install via Arduino Library Manager):
- Adafruit IO Arduino
- Adafruit HDC302x (for temp/humidity sensor)
- ESP32 Arduino Core
-
Adafruit IO Account (free tier works great)
- Sign up at io.adafruit.com
- Create a group called "esp32-weather" (or customize in code)
- Note your username and key
-
Clone this repository:
git clone https://github.com/YOUR-USERNAME/ESP32-Sensor-Logger.git
-
Install the ESP32_IoT_Utils library:
- Copy
library/ESP32_IoT_Utils/folder to your Arduino libraries directory:- Windows:
Documents\Arduino\libraries\ - Mac:
~/Documents/Arduino/libraries/ - Linux:
~/Arduino/libraries/
- Windows:
- Restart Arduino IDE
- Copy
-
Create secrets file: Create a file at
~/.secrets.h(or customize path in code) with:#define WIFI_SSID "your-wifi-name" #define WIFI_PASSWORD "your-wifi-password" #define ADAFRUIT_AIO_USERNAME "your-aio-username" #define ADAFRUIT_AIO_KEY "your-aio-key"
-
Upload the sketch:
- Open
SensorMonitor/SensorMonitor.ino - Select your board: Tools β Board β ESP32-S3 Dev Module (or your specific board)
- Upload!
- Open
- Open Serial Monitor (115200 baud)
- Watch the startup sequence and first reading
- Check Adafruit IO to see your data arriving
- Device will enter deep sleep after publishing
All configuration is at the top of SensorMonitor.ino:
// Debug output options (enable any combination)
#define ENABLE_SERIAL_DEBUG true // USB Serial
#define ENABLE_REMOTE_DEBUG true // Adafruit IO logging
#define ENABLE_SYSLOG_DEBUG false // Network syslog
// Timing
#define SLEEP_DURATION_SECONDS 300 // 5 minutes between readings
// Hardware
#define BATTERY_PIN A2
#define BATTERY_VOLTAGE_DIVIDER 2.0
// Adafruit IO
#define AIO_GROUP "esp32-weather"Create feeds in your Adafruit IO group:
esp32-weather.temperature- Temperature readingsesp32-weather.humidity- Humidity readingsesp32-weather.battery- Battery voltageesp32-weather.debug-log- Debug messages (optional)
Add these feeds to a dashboard with appropriate visualizations (line charts, gauges, etc.).
With the default 5-minute reading interval:
- 1000mAh battery: 5-6 days
- 2000mAh battery: 10-12 days
- 6000mAh (4ΓAA): 30-40 days
See docs/power_saving_guide.md for optimization tips.
ESP32-Sensor-Logger/
βββ README.md # This file
βββ .gitignore # Git ignore rules
βββ SensorMonitor/ # Main Arduino sketch
β βββ SensorMonitor.ino
βββ library/ # Reusable library
β βββ ESP32_IoT_Utils/
β βββ ESP32_IoT_Utils.h
β βββ ESP32_IoT_Utils.cpp
β βββ README.md # Library documentation
βββ docs/ # Additional documentation
β βββ power_saving_guide.md # Power optimization tips
β βββ REMOTE_DEBUG_FIX.md # Remote logging setup
β βββ SYSLOG_CRASH_FIX.md # Syslog debugging notes
βββ hardware/ # Hardware configurations
β βββ README.md # Supported hardware guide
βββ examples/ # Future: other sensor configs
The included library provides reusable classes for common ESP32 IoT tasks:
- DebugLogger: Multi-output debug logging (Serial, Remote, Syslog)
- PowerManager: Battery monitoring and deep sleep management
- WiFiManager: Simplified Adafruit IO connection with timeouts
- DataPublisher: Easy data publishing to feeds
- WatchdogManager: Hardware watchdog timer management
- ErrorHandler: Automatic retry logic and error recovery
See library/ESP32_IoT_Utils/README.md for complete API documentation.
Single sensor configuration (HDC302x on QtPy ESP32-S3)
- Configuration System: Identify board and sensor setup by CPU ID or config file
- Sensor Abstraction: Common interface for different sensor types
- Dynamic Feed Creation: Automatic feed setup based on available sensors
- Multiple Board Support:
- ESP32-S3 (current)
- ESP32-C3 (planned)
- ESP32-WROOM (planned)
- Sensor Library: Support for various sensors:
- Temperature/Humidity (HDC302x, DHT22, SHT31)
- Air Quality (BME680, SGP30)
- Light (TSL2591, VEML7700)
- Soil Moisture (Capacitive sensors)
- Motion (PIR)
Option 1: CPU ID-based configuration
uint64_t chipID = ESP.getEfuseMac();
switch (chipID) {
case 0x123456789ABC: // Kitchen sensor
sensorType = HDC302x;
location = "kitchen";
break;
case 0x987654321DEF: // Garden sensor
sensorType = SOIL_MOISTURE;
location = "garden";
break;
}Option 2: Configuration file
// config.h per device
#define DEVICE_NAME "kitchen-sensor"
#define SENSOR_TYPE HDC302X
#define HAS_BATTERY true
#define SLEEP_DURATION 300Contributions and ideas welcome! See Contributing below.
"Library not found" error
- Ensure
ESP32_IoT_Utilsis in your Arduino libraries folder - Restart Arduino IDE
Sensor not detected
- Check I2C connections (especially for STEMMA QT)
- Verify sensor I2C address (0x44 for HDC302x)
- Try different I2C bus (Wire vs Wire1)
WiFi connection fails
- Check secrets file path and credentials
- Increase
WIFI_TIMEOUT_MSvalue - Check WiFi signal strength
Device keeps resetting
- Watchdog timeout - add more
watchdog.reset()calls - Increase
WATCHDOG_TIMEOUT_SECONDS - Check power supply stability
Remote debug logs not appearing
- Ensure
ENABLE_REMOTE_DEBUGis true - Verify debug-log feed exists in Adafruit IO
- Check that
io.run()is being called - See
docs/REMOTE_DEBUG_FIX.md
High power consumption
- Verify I2C power-down is working:
powerMgr.powerDownI2C(&Wire1) - Disable remote/syslog debugging in production
- Increase sleep duration
- See
docs/power_saving_guide.md
- Library API Documentation - Complete library reference
- Power Saving Guide - Battery optimization tips
- Remote Debug Setup - Setting up remote logging
- Syslog Configuration - Network logging setup
- Hardware Guide - Supported hardware configurations
Contributions are welcome! Here are some ways you can help:
- Add sensor support: Create examples for new sensors
- Test on different boards: Verify compatibility with other ESP32 variants
- Improve documentation: Clarify instructions or add tutorials
- Report issues: Found a bug? Open an issue!
- Optimize power: Share your battery optimization discoveries
- Copy
SensorMonitor/SensorMonitor.inotoexamples/YourSensorName/ - Modify sensor initialization and reading functions
- Update
#define AIO_GROUPto match your setup - Test thoroughly and document hardware requirements
- Submit a pull request!
MIT License - Feel free to use and modify for your projects!
Built with:
Hardware from:
Questions? Suggestions? Open an issue or start a discussion!
Happy Logging! ππ‘οΈπΎ