💡 Inspiration We’ve all played "Nap Roulette." You lay down for a quick 20-minute power nap to recharge during a hackathon or study session, but you wake up two hours later not knowing what year it is.

That heavy, groggy feeling is called Sleep Inertia, and it happens because traditional alarms are biologically blind. They wake you up based on a clock, often jolting you right out of Deep Sleep (N3)—the exact moment your brain is least ready to wake up.

We wanted to bio-hack the perfect power nap: a solution that wakes you up at an optimal time by analyzing your sleep cycle.

💤 What it does Happy Nappy is a smart neck pillow that guarantees you wake up refreshed, not groggy.

Monitors: Continuously tracks your heart rate via integrated sensors while you rest.

Analyzes: Detects the specific biometric signature of drifting from Light Sleep into Deep Sleep.

Intervenes: Gently wakes you up before you hit the "Danger Zone" (Deep Sleep), ensuring maximum energy restoration with zero sleep inertia. Powered by a vibration motor that is non-invasive and doesn't disturb those around you, so you can take HappyNappy anywhere. Who likes waking up to an alarm blaring anyway?

⚙️ How we built it We built a full IoT pipeline from scratch, bridging hardware signal processing with a modern web backend.

  1. The Hardware (The "Body") Core: ESP32 Microcontroller acting as the central nervous system.

Sensing: MAX30102 Pulse Oximeter capturing raw Photoplethysmography (PPG) data.

Feedback: An OLED display on the pillow for real-time status and a haptic motor for the silent alarm.

  1. The Data Pipeline (The "Nervous System") Sampling: The ESP32 collects IR values at 50Hz, bundling them into data packets (500 samples every 10 seconds).

Transport: We set up a local MQTT Broker (Mosquitto) to handle high-frequency data transmission between the hardware and our backend, bypassing standard HTTP latency.

  1. The Backend & Logic (The "Brain") Processing: A FastAPI Python server ingests the raw data packets.

Signal Analysis: We used HeartPy to filter signal noise and calculate the average BPM for each 10-second interval.

The Algorithm:

Calculates a dynamic Baseline BPM from the first 60 readings (approx. 10 mins).

Monitors for a specific "Deep Sleep Dip": a sustained BPM drop of >20% relative to the baseline.

Triggers the wake-up command via MQTT the moment this threshold is crossed.

  1. Visualization Dashboard: A Streamlit dashboard visualizes the live heartbeat trend, allowing users to see their "Sleep Arch" and download their biometric data for post-nap analysis.

🚧 Challenges we ran into The "Network Nightmare": The school’s enterprise Wi-Fi security & login blocked our MQTT packets. We had to pivot quickly, setting up a personal router to create a local testing environment to keep the data flowing. However, this came at the cost of losing internet connection when our device is running the MQTT broker.

Signal vs. Noise: Integrating raw hardware data with software processing was tricky. The MAX30102 is sensitive, so we had to write robust filtering logic to distinguish between a user moving their head and an actual heartbeat.

The "Data Desert": We originally wanted to train a model on public REM sleep data, but finding accessible, granular raw datasets was difficult. We pivoted to a real-time heuristic model based on BPM trends, which proved effective for our MVP.

🏆 Accomplishments that we're proud of Full-Stack IoT Integration: We successfully connected a raw hardware sensor to a Python backend and a live web dashboard—seeing that first live heartbeat on the screen was a huge win.

OLED Implementation: managing to get a functional UI running directly on the pillow's hardware.

Resilience: Pivoting from a cloud-based solution to a local router setup when the venue Wi-Fi failed us, ensuring our demo still worked perfectly.

🧠 What we learned IoT Architecture: We went from zero knowledge of MQTT to building a functioning pub/sub network.

Backend Engineering: Setting up FastAPI and understanding how to handle asynchronous data streams.

Team Git-Flow: Moving beyond "zipping files" to properly managing a multi-person codebase with hardware and software branches.

🚀 What's next for Happy Nappy Machine Learning: Moving beyond simple threshold algorithms to a trained ML model for detecting REM sleep patterns.

Cloud Integration: deploying our local backend to AWS/Azure for remote sleep tracking.

Sensor Fusion: Adding an accelerometer to correlate movement data with heart rate for even higher accuracy.

User Interface: A better, more human design

Built With

  • c++
  • esp32
  • fastapi
  • heartpy
  • max30102
  • mqtt
  • python
  • streamlit
Share this project:

Updates