← Back to journal

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

Example alert:

Desk Intrusion 🚨
Something moved near your desk

Components Used

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:

Next Improvements

I can improve this by adding:

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.