Lessons and the learning game

Build a gesture magic wand

A wand that turns flicks into spells: MPU6050 angles, a time window and a state machine that recognize spells, LED effects and an IR cast that opens a box.

What it teaches

Six lessons in three chapters:

  • Gestures: pitch and roll from gravity (asin and atan2), poses past a threshold with a dead band, a 300 ms window that tells a flick from a slow tilt, a small state machine that strings flicks into spells, a spellbook lookup, and dynamic time warping explained in words.
  • Light and casting: lumos, nox and a flickering incendio on eight WS2812 LEDs, a spell of your own, and an NEC code at 38 kHz through an IR LED that a second board decodes to move a servo latch.
  • Build it: reading the LiPo cell on A0, a current budget for the LEDs, dimming on a low cell, sleep when idle, and the project: a box that opens only for your secret three-move spell.

Open it at /learn/path/build-magic-wand.

The circuit

Magic wand and spell box: two boards. The wand is an Uno standing in for the XIAO ESP32-C3 a real wand uses: an MPU6050 on A4 and A5, a stick of eight WS2812 LEDs on pin 6 powered from a 500 mAh LiPo (whose + also goes to A0), and an IR LED on pin 3 through 220 ohms, running wandcore. The box is a second Uno running wandbox: a VS1838B receiver on pin 2 and a servo latch on pin 9. A wire from the IR LED's BEAM to the receiver stands for the air between them.

Gestures are tilts

The simulated MPU6050 feels only gravity, never a push, so every gesture is a quick tilt: tip the sensor's pitch (UP, DOWN) or roll (RIGHT, LEFT) past 35 degrees and back to flat. Real wands work best on tilts too, because a tilt says which way, where a jolt does not.

Troubleshooting

  • Nothing happens: the move was too slow (over 300 ms from flat) or did not pass 35 degrees. Tip it further, faster.
  • Two flicks become two spells: they were more than SPELL_GAP_MS apart.
  • A flick is not counted: the wand has to come back within 15 degrees of flat between flicks.
  • The box does not open: check the spell's moves in the spellbook and that it has IR command 1.