What it teaches
The course follows Embedded Uno, so the Uno, the
Serial Monitor, buttons and millis() are already known. The servo is
explained from nothing. Seven lessons in three chapters:
- Two servos: what is inside a servo, the 50 Hz pulse that steers it, the angle to pulse width math (45 degrees is 1008 us), and where the dot lands on the floor (distance = height / tan(angle below level)).
- Make it play: random spots that only look random, a fixed seed that
makes every run the same, glide speed timed with
millis(), the servo's own speed limit, and pauses that make a cat pounce. - Safe, timed and kind: laser classes in real milliwatts, a tilt limit that keeps the beam pointing down, a kill switch, a session timer that never blocks, a rest between games, and the project: a full play session that ends with the dot parked on a real toy.
Open it at /learn/path/build-cat-laser-toy.
The circuit
Every lesson opens the gallery's Cat laser toy circuit: a KY-008 laser module on pin 7, the pan servo on pin 9, the tilt servo on pin 10, and a button from pin 2 to ground. The breadboard's top rails carry 5 V and ground. Tilt 90 points the beam level and tilt 180 straight down; the turret is taken to sit 100 cm above the floor.
Three programs run on it:
claserjogaims by hand from the Serial Monitor (pan 45,tilt 135,aim 60 150,laser on,home), prints each pulse width and where the dot lands, and refuses any tilt under 120.catlaseris the gallery sketch: a minute of random glides, then rest until the button is pressed.claserplayis the play engine: warm up, chase, cool down and toy, timed bymillis(), tuned withsession,speed,pause,testandseed.
Laser safety
The simulated KY-008 is the module sold as 5 mW, which is class 3R. For a real cat toy, buy a module labeled class 2 (under 1 mW) or class 1, mount the turret high and pointing down, never aim it at a face (a cat's included), and keep a kill switch within reach. Play only while someone is in the room.
Troubleshooting
- Nothing happens when I type: click in the Serial Monitor first, and press Enter after the command.
- The tilt will not go up: that is the floor limit.
claserjogrefuses anything under 120 andclaserplaystays between 130 and 165. - The button does nothing in the gallery sketch: its round is a
whileloop that only reads the button between rounds. The play engine reads it on every pass ofloop(). - The seed step shows a different spot: change only the line
randomSeed(analogRead(A0));torandomSeed(42);, and keep the pan range as it was until the next step.