| .vscode | ||
| doc/pdf | ||
| include | ||
| lib | ||
| src | ||
| test | ||
| .gitignore | ||
| GIT_WORKFLOW.md | ||
| platformio.ini | ||
| README.md | ||
| WIRING.md | ||
🤖 Useless Box - ESP32 Edition
An advanced, entertaining "Useless Box" with multiple personality modes, animated robot eyes, and interactive features. When you flip the switch ON, a mechanical arm emerges from the box to turn it back OFF - because that's all it does!
But this isn't just any useless box - it has 7 different entertaining modes with unique personalities, emotions displayed through animated robot eyes on an LED matrix, and even an interactive distance-sensing game mode.
🎭 Features
- 7 Unique Modes: Each interaction is different! The box randomly selects from 7 distinct behavior patterns
- Animated Robot Eyes: LED matrix displays expressive robot emotions (neutral, angry, sad, evil, squinting, winking, scanning)
- Interactive Distance Sensing: Mode 6 features an ultrasonic sensor that tracks your hand movement
- Text Display: Shows messages like "Flip switch...!", "Happy Birthday", "Hi!", and "You win... :-("
- Flag Waving: A white flag appears when the box "gives up" (Mode 5)
- ESP32 Powered: Originally designed for Arduino Nano, now upgraded to ESP32 for enhanced capabilities
📦 Hardware Components
Electronics
Actuators
- 3x Micro Servo SG90 (Lid, Switch arm, Flag)
Sensors
- HC-SR04 Ultrasonic Distance Sensor (for Mode 6 interactive game)
Display
- 64-LED Matrix Display (3x 8x8 MAX7219 modules for robot eyes)
Input
- Toggle Switch (the "useless" switch that triggers all the action)
🎪 The 7 Modes Explained
Mode 0: Classic Observer 👀
"I see you..."
- Eyes: Neutral → Look Up
- Behavior: Waits 2-5 seconds, looks up at you, opens lid, presses switch, closes
- Personality: Patient, observant
Mode 1: Quick Wink 😉
"Fast and cheeky!"
- Eyes: Wink
- Behavior: Winks at you, then quickly opens lid and presses switch in one swift motion
- Personality: Playful, efficient
Mode 2: Evil Slowpoke 😈
"Savoring the moment..."
- Eyes: Neutral → Evil
- Behavior: Waits 1-2 seconds with neutral eyes, then switches to evil eyes, opens lid slowly, holds the switch down for 2-3 seconds (ominously), releases slowly
- Personality: Menacing, theatrical
Mode 3: Fake-Out Artist 🤪
"Left? Right? Psych!"
- Eyes: Scanning Left-Right
- Behavior: Scans surroundings, opens lid slowly, fake-out arm movements (back and forth), then finally presses
- Personality: Mischievous, unpredictable
Mode 4: Angry Teaser 😠
"Stop it! STOP IT!"
- Eyes: Angry
- Behavior: Rapidly opens and closes lid 3 times in frustration, then aggressively presses the switch
- Personality: Impatient, irritated
Mode 5: The Surrender 🏳️
"Okay, you win..."
- Eyes: Neutral → Sad
- Behavior: Opens lid fully, waves white flag, displays "You win... :-(" on LED matrix, then reluctantly presses switch
- Personality: Defeated, dramatic
- Special: Only appears after 5+ interactions (blocked before 5th interaction)
Mode 6: Interactive Distance Game 🎮
"Come closer... if you dare!"
- Eyes: Squint → Neutral
- Behavior:
- Opens lid fully
- For 15 seconds, tracks your hand position with ultrasonic sensor
- Arm position follows hand distance (far/near/close)
- Teases you by moving the arm as you approach
- Finally presses the switch
- Personality: Interactive, playful
📍 ESP32 Pin Configuration
| Component | Function | ESP32 GPIO | Notes |
|---|---|---|---|
| Servos | |||
| Lid Servo | PWM | GPIO 13 | Opens/closes the lid |
| Switch Servo | PWM | GPIO 14 | Presses the switch |
| Flag Servo | PWM | GPIO 27 | Waves white flag |
| Ultrasonic Sensor | |||
| HC-SR04 TRIG | Output | GPIO 26 | Distance measurement trigger |
| HC-SR04 ECHO | Input | GPIO 25 | Distance measurement echo |
| LED Matrix (SPI) | |||
| SPI CLK | Output | GPIO 18 | VSPI SCK (hardware SPI) |
| SPI DATA | Output | GPIO 23 | VSPI MOSI (hardware SPI) |
| SPI CS | Output | GPIO 5 | VSPI CS (hardware SPI) |
| Input | |||
| Toggle Switch | Input | GPIO 32 | Detects switch position |
Migration Note: This project was originally designed for Arduino Nano ATmega328 (see v1.0.0 for the original Arduino version) and has been migrated to ESP32. All pin mappings have been updated to use ESP32-safe GPIOs, avoiding strapping pins and input-only pins.
🔧 Building the Project
Prerequisites
- PlatformIO (recommended) or Arduino IDE
- ESP32 board support installed
Compilation
# Clean build
platformio run --target clean
# Build firmware
platformio run
# Upload to ESP32
platformio run --target upload
# Monitor serial output
platformio device monitor
Libraries Used
All libraries are included locally in the lib/ folder for offline building:
- Servo (v1.3.0) - arduino-libraries/Servo
- HCSR04 (v2.0.0) - martinsos/HCSR04
- MD_MAX72XX (v3.5.1) - majicdesigns/MD_MAX72XX
- MD_RobotEyes (custom) - Robot eyes animation for LED matrix
- SPI (built-in) - Hardware SPI communication
🎮 How It Works
- Power On: Box initializes, eyes appear on LED matrix
- Flip Switch ON: Triggers a random mode selection
- Watch the Show: Box performs one of 7 entertaining behaviors
- Switch Returns OFF: Box closes and waits for next interaction
- Text Mode: Randomly displays text messages when switch is OFF
Mode Selection Logic
- Modes are randomly selected without immediate repetition
- Mode 6 (Distance Game) only appears after 5+ interactions
- Mode 5 (Surrender) can be forced on the 7th interaction
- After all modes are played, the selection pool resets
🛠️ Customization
Adjust Servo Positions
Edit values in src/servos.h:
#define LID_SERVO_INIT 80 // Lid closed position
#define SWITCH_SERVO_INIT 100 // Switch arm rest position
#define FLAG_SERVO_INIT 50 // Flag down position
Change Display Text
Edit the text array in src/modes.h:
const char* displayTexts[3] = {"Flip switch...!", "Happy Birthday", "Hi !"};
Enable/Disable Modes
Modify the modes array in src/modes.h:
bool modesUsed[7] = {true, false, false, false, false, false, false};
// Set to 'false' to disable a mode initially
Distance Sensor Thresholds
Adjust ranges in src/distanceMeter.h:
if(d <= 200 && d > 130) // H_NEAR
if(d <= 130 && d > 80) // H_CLOSE
if(d > 200) // H_FAR
🐛 Debugging
Production Build (Default)
The default esp32dev environment runs the box in autonomous mode with no serial
output.
pio run -e esp32dev -t upload
Debug Build
For development and testing, use the esp32dev-debug environment which enables:
- Serial debugging output at 115200 baud
- Interactive mode selection via serial commands
- Detailed execution logs
- Manual triggering of modes
pio run -e esp32dev-debug -t upload
pio device monitor -e esp32dev-debug
Debug Commands
When running in debug mode, open the serial monitor (115200 baud) to access these commands:
| Command | Description |
|---|---|
0-6 |
Select specific mode (0-6) |
t |
Trigger the currently selected mode |
txt |
Trigger text display mode |
i |
Show current system info (mode, state, counters) |
s |
Show switch state (ON/OFF) |
r |
Reset modes array and play counter |
h |
Display help menu |
Example Debug Session:
========================================
DEBUG MODE - COMMAND MENU
========================================
Mode Selection:
0-6 : Select specific mode (0-6)
t : Trigger selected mode
txt : Trigger text mode
Info Commands:
i : Show current mode info
s : Show switch state
r : Reset modes array
h : Show this help menu
========================================
> 3
✓ Mode set to: 3
Type 't' to trigger this mode
> t
✓ Triggering mode: 3
Trigger Action...
-----------------
Mode: 3
Mode3.0 Init...
Mode3.0 -> SCAN_LR
Mode3.1 SCAN_LR done...
...
Note: In debug mode, the box does NOT trigger automatically when the switch is flipped. You must use serial commands to test modes.
📸 Robot Eye Emotions
The LED matrix displays various emotions during operation:
E_NEUTRAL- Default calm expressionE_BLINK- Both eyes blinkE_WINK- One eye winksE_LOOK_U/E_LOOK_D- Eyes look up/downE_LOOK_L/E_LOOK_R- Eyes look left/rightE_ANGRY- Angry eyebrowsE_SAD- Sad expressionE_EVIL/E_EVIL2- Evil expressionsE_SQUINT- Suspicious squintE_SCAN_LR/E_SCAN_UD- Scanning animations
⚡ Power Requirements
- ESP32: 3.3V logic, powered via USB or 5V supply
- Servos: 5V, ~500mA peak per servo (1.5A total recommended)
- LED Matrix: 5V, ~200mA
- HC-SR04: 5V, ~15mA
Recommended: 5V 2A power supply for stable operation.
🔮 Future Enhancements
- WiFi connectivity for remote triggering
- Web interface for mode selection
- Sound effects via WTV020SD16P module (hardware present but unused)
- Additional modes and Easter eggs
- MQTT integration for IoT control
- Battery operation with sleep mode
📜 License
This project is open source. Feel free to modify, enhance, and share!
🙏 Acknowledgments
- Inspired by the classic "Useless Box" concept
- Special thanks to the Arduino and ESP32 communities
- Library authors: MD_MAX72XX (majicdesigns), HCSR04 (martinsos), Servo (Arduino)
Remember: This box serves absolutely NO practical purpose whatsoever... and that's exactly the point! 🎉