Focus: Real-time vertical displacement sensing, fail-safe motor isolation, and remote emergency orchestration.
Ceiling fans are a high-risk point in institutional and residential safety. This project transforms a standard mechanical fixture into an intelligent sensor node. By utilizing Non-Blocking I/O and a Deterministic State Machine, the system ensures that safety interrupts are processed with microsecond precision, independent of network latency or cloud synchronization.
- The Problem: Environmental noise and air turbulence from fan blades can cause "jitter" in ultrasonic readings, potentially triggering false panic states.
- The Solution: Implemented a Moving Average Filter in the
Sensor.cpplogic. The firmware establishes a calibratedbaselineDistanceupon boot and requires a sustained vertical displacement of >5.0 cm across multiple samples before triggering a lockout.
- The Problem: Traditional AC motors have significant inertia and are difficult to stop instantly.
- The Solution: Pivoted to a Stepper-based Drive (NEMA 17) utilizing the A4988 driver. This allows the firmware to execute an instantaneous "Hard Kill" by pulling the
Enablepin high and stopping the step pulse train, providing a mechanical lockout the moment a risk is detected.
- The Problem: If a panic event occurs, the system must not be reset by simply power-cycling the device.
- The Solution: The system utilizes a Cloud-Stored Lockout State. Upon reboot, the ESP32-C3 fetches its last known status from the Firebase Real-time Database. If the status is "Locked," the hardware remains in a blocking safety loop until an authorized administrator manually clears the flag.
- Proximity Monitoring: 1D spatial mapping using HC-SR04 to establish a ceiling-to-fan baseline.
- Auditory Alerting: High-intensity active buzzer and LED indicators integrated directly into the ESP32-C3 interrupt routine.
- RESTful Telemetry: Uses HTTP/SSL to push critical
Suicide: trueflags and real-time telemetry to Firebase. - Remote Dashboard: A Vercel-deployed web application providing centralized monitoring and authorized recovery controls.
| Component | Specification |
|---|---|
| MCU | ESP32-C3 (RISC-V Single-Core) |
| Sensing | HC-SR04 Ultrasonic (2cm - 400cm range) |
| Drive | NEMA 17 Stepper (1.8° step angle) |
| Connectivity | Firebase REST API / HTTP SSL |
Anti_Suicide_Fan/
├── Firmware/ # Embedded C++ (ESP32-C3)
│ ├── sketch.ino # Deterministic state machine & safety loops
│ ├── Sensor.cpp / .h # Noise-filtered proximity logic
│ └── CloudManager.cpp / .h # Firebase orchestration & WiFi recovery
├── Web App/ # Management Dashboard (HTML/JS)
└── vercel.json # Deployment configuration
This project was a significant exercise in reliability engineering for life-safety applications:
- The Pivot: Early prototypes utilized standard PIR motion sensors, which proved insufficient for detecting specific vertical displacement. Transitioning to Ultrasonic 1D Mapping allowed for the creation of a "Digital Fence," providing a far more reliable and deterministic trigger for life-safety intervention.
- Future Refinement: I am currently designing a Dual-Sensor Fusion model for the next iteration. By integrating Load Cells into the fan mounting bracket, the firmware will be able to cross-reference distance data with physical weight displacement, virtually eliminating the possibility of false positives.
Ritul Raj Bhakat
Firmware Developer | Embedded Systems Architect
- Deep Dive: View My Full Portfolio
- Professional: LinkedIn
- Direct: Email Me
© 2026 Ritul Raj Bhakat. Engineered for life-safety intervention.

