This project is a submission for the Carenuity Level 3 Challenge: API Usage & App Development. It demonstrates practical API integration, IoT development, and power management in an Arduino-based application that monitors important emails and displays them on a real-time OLED screen.
The Carenuity Level 3 challenge focuses on:
- Creating custom applications using the Arduino IDE
- Integrating third-party APIs into IoT projects
- Leveraging AI assistance (ChatGPT) for code optimization
- Uploading and sharing projects on the Solution Builder platform
- Building practical IoT solutions that solve real-world problems
This Email Monitor application transforms an ESP32-S2 Mini microcontroller into an intelligent email notification device. It connects to the internet, fetches important email metadata via a Google Apps Script API, and displays the information on an OLED screen—all while optimizing power consumption through deep sleep cycles.
✅ WiFi Connectivity - Connects to home/office network for internet access
✅ Google Apps Script Integration - Fetches email data via custom API endpoint
✅ OLED Display - Shows email count and latest subject on 128x64 display
✅ Power Management - Uses deep sleep (~5-minute intervals) for extended battery operation
✅ Real-time Updates - Automatically polls for new important emails
✅ Trim & Parse - Cleans and formats incoming data for reliable display
| Component | Details |
|---|---|
| Microcontroller | ESP32-S2 Mini |
| Display | Adafruit SSD1306 OLED (128x64, I2C) |
| Communication | WiFi (built-in) & I2C (display connection) |
| Pins Used | SDA: GPIO 33, SCL: GPIO 35 |
| Power | USB or Battery (deep sleep optimized) |
┌─────────────────────┐
│ ESP32-S2 Mini │
│ (Microcontroller) │
└──────────┬──────────┘
│
┌─────┴─────┐
│ │
▼ ▼
[WiFi] [I2C Bus]
│ │
│ ▼
│ ┌────────────────┐
│ │ SSD1306 OLED │
│ │ Display 128x64 │
│ └────────────────┘
│
▼
[Google Apps Script API]
│
▼
[Gmail / Email Service]
-
Initialization Phase
- ESP32 boots and initializes I2C communication
- OLED display activates and displays connection status
- Device attempts WiFi connection
-
Connected State
- Displays "WiFi Online!" confirmation
-
Main Loop - Data Fetching
- Makes HTTP GET request to Google Apps Script
- Receives payload:
count|subject - Parses data and updates display
-
Display Update
- Shows: "IMPORTANT EMAILS:" header
- Shows: Email count
- Shows: "LATEST SUBJECT:" header
- Shows: Most recent email subject
-
Power Management
- Logs "Going to sleep for 5 minutes..."
- Enables deep sleep timer (5 × 60 × 1,000,000 microseconds)
- Enters ESP deep sleep mode
- Wakes automatically, repeats from Main Loop
const char* ssid = "Barbara"; // WiFi SSID
const char* password = "Cleopatra123"; // WiFi Password
const char* scriptUrl = "..."; // Google Apps Script endpoint#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Custom I2C pins for ESP32-S2 Mini
Wire.begin(33, 35); // SDA=33, SCL=35// Fetches data from Google Apps Script
http.begin(scriptUrl);
int httpCode = http.GET();
String payload = http.getString();
// Parses format: "count|subject"
int splitIndex = payload.indexOf('|');
String count = payload.substring(0, splitIndex);
String subject = payload.substring(splitIndex + 1);// Converts 5 minutes to microseconds
uint64_t sleepTime = 5 * 60 * 1000000;
esp_sleep_enable_timer_wakeup(sleepTime);
esp_deep_sleep_start(); // The "Magic" Level 3 commandshowStatus(String msg)- Shows large status messages (WiFi connection, errors)updateDisplay(String count, String subject)- Displays formatted email information
- Arduino IDE installed
- ESP32 board support added to Arduino IDE
- Required libraries:
WiFi.h(built-in with ESP32)HTTPClient.h(built-in with ESP32)Wire.h(built-in with ESP32)Adafruit_GFX.hAdafruit_SSD1306.h
-
Install Dependencies
- In Arduino IDE: Sketch → Include Library → Manage Libraries
- Search and install: "Adafruit GFX" and "Adafruit SSD1306"
-
Configure WiFi Credentials
const char* ssid = "Your_Network_SSID"; const char* password = "Your_Network_Password";
-
Set Google Apps Script URL
- Create a Google Apps Script that monitors Gmail
- Deploy as web app with appropriate permissions
- Update
scriptUrlwith your endpoint
-
Board Selection
- Tools → Board → ESP32S2 (or your specific variant)
- Tools → Port → Select your ESP32 port
-
Upload
- Sketch → Upload
- Open Serial Monitor (115200 baud) to verify connection
The backend uses Google Apps Script to:
- Access Gmail API
- Filter for important emails/labels
- Return data in format:
count|subject - Handle authentication and caching
Example response structure:
5|Re: Urgent Project Update - Q1 2025
This project uses ESP32 Deep Sleep for power efficiency:
- Active Time: ~3-5 seconds (WiFi + HTTP + Display)
- Sleep Time: 5 minutes (uses minimal power)
- Deep Sleep Current: ~10-100 µA (compared to ~80 mA active)
Result: Approximately 96-98% power reduction compared to continuous operation!
...
Going to sleep for 5 minutes...
State 1 - Connecting:
Connecting WiFi...
State 2 - Connected:
WiFi Online!
State 3 - Email Data:
IMPORTANT EMAILS:
> 5
LATEST SUBJECT:
Team Meeting Notes - March
| Issue | Solution |
|---|---|
| Display not showing | Verify I2C address (0x3C), check SDA/SCL pin connections |
| WiFi won't connect | Check SSID/password, verify network compatibility (2.4GHz) |
| HTTP Error messages | Verify Google Apps Script URL is correct and deployed |
| No data displayed | Check Google Apps Script returns correct format (count|subject) |
| Frequent reboots | May indicate power issues or memory problems |
✓ Real-world API integration and HTTP communication
✓ IoT device programming with microcontrollers
✓ I2C display communication protocols
✓ Power management and deep sleep optimization
✓ WiFi connectivity and network debugging
✓ Problem-solving through API debugging
✓ Time management in multi-component projects
✓ Technical documentation and communication
✓ Community engagement through project sharing
- Add multiple email labels/filters
- Display email sender information
- Button control for manual refresh or configuration
- Battery level indicator
- Multiple OLED screens for more data
- Mobile app integration
- Cloud logging of email trends
- Carenuity Challenge: https://carenuity.com/home-challenge/level-3/
- ESP32-S2 Mini Documentation: https://www.espressif.com/
- Adafruit SSD1306 Library: https://github.com/adafruit/Adafruit_SSD1306
- Google Apps Script Guide: https://developers.google.com/apps-script
- Arduino IDE: https://www.arduino.cc/en/software
Carenuity_project/
├── code.cpp # Main Arduino sketch
├── README.md # This file
└── binary/ # Compiled binary (for Solution Builder)
Challenge Level: 3 - API Usage & App Development
Platform: Solution Builder (https://solutions.carenuity.com)
Reward: DS18B20 Sensor / Oximeter Sensor
Difficulty: Basic
Tutor: Paul
Status: ✅ Completed and Ready for Submission
For questions or to share this project, contact: team@carenuity.com