Cooper Detector: A Simple IoT Desk Alert System
Cooper has a habit of coming near my work desk and trying to take things when I'm not around. So I built a simple Cooper Detector using an ultrasonic sensor, ESP32, Firebase Function, and Android push notification.
Architecture
HC-SR04
↓
ESP32
↓
Firebase Function
↓
Firebase Cloud Messaging
↓
Android App Notification
What it does
- The HC-SR04 ultrasonic sensor measures distance.
- If Cooper comes closer than 10 cm, the ESP32 sends an alert to Firebase.
- Firebase then sends a push notification to my Android phone.
Example alert:
Desk Intrusion 🚨
Something moved near your desk
Components Used
- ESP32 Development Board
- HC-SR04 Ultrasonic Sensor
- Jumper wires
- Firebase Project
- Android App with FCM setup
Step 1: Connect HC-SR04 to ESP32
HC-SR04 ESP32
VCC → VIN / 5V
GND → GND
TRIG → GPIO 5
ECHO → GPIO 18
The sensor sends sound waves and calculates distance based on the echo.
Step 2: ESP32 Reads Distance
The ESP32 keeps checking the distance:
if (distance < 10) {
sendAlert(distance);
}
If the distance is less than 10 cm, it means something is close to the desk.
Step 3: ESP32 Calls Firebase Function
The ESP32 sends a POST request:
{
"distance": 8
}
to:
https://<region>-<project-id>.cloudfunctions.net/deskAlert
Step 4: Firebase Function Sends Notification
Firebase Function receives the distance value.
If distance is below 10 cm, it sends a Firebase Cloud Messaging notification to the topic:
desk-alert
Step 5: Android App Receives Alert
The Android app subscribes to the topic:
FirebaseMessaging.getInstance().subscribeToTopic("desk-alert")
When Cooper comes near the desk, the phone receives a notification instantly.
Final Result
Now when Cooper comes close to the work desk, I get an alert on my phone.
Cooper detected near desk 🐶
What I Learned
This small project helped me understand:
- Sensor reading with ESP32
- WiFi communication
- Firebase Cloud Functions
- Firebase Cloud Messaging
- Android push notifications
- IoT alert system flow
Next Improvements
I can improve this by adding:
- Notification cooldown
- Battery-powered setup
- MQTT for faster alerts
- Multiple sensors for better detection
- Camera snapshot
- Custom Android dashboard
Conclusion
The Cooper Detector is a simple but fun IoT project. It connects hardware, cloud, and mobile notification into one complete system.
Most importantly, it helps protect my desk from Cooper's mischief.