No description
Find a file
2025-12-01 08:18:06 +01:00
.vscode lib updates, make libs static included 2025-11-24 09:15:04 +01:00
doc/pdf switch to esp32 2025-11-24 09:36:36 +01:00
include initial commit 2019-10-07 08:56:46 +02:00
lib switch to esp32 2025-11-24 09:36:36 +01:00
src update and finalize 2025-11-29 12:42:38 +01:00
test initial commit 2019-10-07 08:56:46 +02:00
.gitignore lib updates, make libs static included 2025-11-24 09:15:04 +01:00
GIT_WORKFLOW.md update 2025-11-27 17:38:19 +01:00
platformio.ini update, add test routines 2025-11-27 19:01:18 +01:00
README.md dbg mode update 2025-11-24 20:20:36 +01:00
WIRING.md update pins to one side 2025-11-29 12:05:32 +01:00

🤖 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

  • AZDelivery ESP32 NodeMCU Module WLAN WiFi Dev Kit C (with CP2102)

Actuators

Sensors

Display

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

  1. Power On: Box initializes, eyes appear on LED matrix
  2. Flip Switch ON: Triggers a random mode selection
  3. Watch the Show: Box performs one of 7 entertaining behaviors
  4. Switch Returns OFF: Box closes and waits for next interaction
  5. 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 expression
  • E_BLINK - Both eyes blink
  • E_WINK - One eye winks
  • E_LOOK_U / E_LOOK_D - Eyes look up/down
  • E_LOOK_L / E_LOOK_R - Eyes look left/right
  • E_ANGRY - Angry eyebrows
  • E_SAD - Sad expression
  • E_EVIL / E_EVIL2 - Evil expressions
  • E_SQUINT - Suspicious squint
  • E_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! 🎉