LaserChase
A smart cat laser toy with manual or automatic movement patterns.
Author: Ghiță Alexandru
GitHub Project Link: GitHub
Description
LaserChase is a smart, interactive laser toy for cats, powered by a Raspberry Pi Pico 2W. The laser is mounted on two servo motors that allow it to move across two axes. It can operate in automatic mode - following 4 pre-programmed motion patterns (horizontal line, vertical line, rectangle or circle) plus a random pattern, or in manual mode - controlled by the joystick. Mode and pattern switching is done via async button presses, making the experience more dynamic and engaging. The goal is to mimic the unpredictable movement of real prey, keeping your cat entertained and active.
Motivation
I wanted to create something practical and enjoyable for my personal use at home. As a cat owner, I thought this project would be a perfect blend of utility and fun-bringing joy to my pet while allowing me to experiment with hardware and software in an engaging way. Building LaserChase has given me the opportunity to explore electronics, real-time control, and embedded programming, all while making my cat happy.
Architecture
The main software components of the project include:
- Control Module: Handles manual input from a joystick (ADC) and async button presses (GPIO) to switch modes and patterns while keeping the laser in motion.
- Mode Manager: Keeps track of the current operating mode and pattern count and interprets input accordingly.
- Movement Generator: Generates movement signals, from one of the 5 different patterns (automatic mode) or transformed from joystick input (manual mode).
- Servo Driver: Sends PWM signals to the two servo motors inside the 2-axis 3D printed stand to move the laser pointer mounted on top of it.
These components interact as follows:
- Input (buttons/joystick) -> Control Module -> Mode Manager -> Movement Generator -> Servo Driver -> Laser
Modes and Patterns
Switching between modes and patterns is done via two GPIO buttons:
Mode | Description |
---|---|
Manual | Joystick controls the laser |
Auto Pattern 0 | Horizontal sweep |
Auto Pattern 1 | Vertical sweep |
Auto Pattern 2 | Rectangle tracing |
Auto Pattern 3 | Circular path (uses sin/cos) |
Auto Pattern 4 | Random hops (using self implemented rand32 ) |
Log
Week 5 - 11 May
Found out what how to connect and get input from buttons and joystick and how to power the laser and move the servo motors using the labs as example. Got the rest of the needed components and a second Raspberry Pi Pico 2W as a debug probe for easier programming of the main controller.
Week 12 - 18 May
Completed the schematic with a better understanding of how it should look like. Connected all of the harware components together and made sure they work. Added a picture of the hardware in its current form. Played around with the code to start things up for the software part.
Week 19 - 25 May
Finished setting up all of the needed hardware and started implemented the software. After correctly connecting the joystick to the servos and getting async input from the buttons, I started testing different options for the patterns. The final patterns that remain implemented are: horizontal line, verical line, rectangular motion, circular motion and my personal favorite, (pseudo-)random motion. Started building the final "product" to make the project good-looking for the PM fair presentation.
Hardware
- Raspberry Pi Pico 2W: LaserChase uses a Raspberry Pi Pico 2W as the main controller.
- SG90 Servo (x2) + Laser Pointer: Two SG90 servos are used to move the laser pointer on two axes.
- Joystick Shield: Control is done via a joystick shield and mode and pattern switching through push buttons.
- 9V Battery + Holder + DC-DC Step Down Module: Power is supplied through a 9V battery regulated by a step-down module to 5V.
- Breadboard + Wires: Components are connected using wires and a breadboard.
Hardware progress
Schematics
Bill of Materials
Device | Usage | Price |
---|---|---|
2x Raspberry Pi Pico 2W | Main microcontroller + debug probe | 80 RON |
2x SG90 Servo Motors | Control the X/Y axes of the laser | 24 RON |
Joystick Shield V1.A | Manual control of laser via joystick + buttons | 20 RON |
DC-DC Step Down Module | Voltage regulation from 9V to 5V | 13 RON |
9V Battery + Holder | Power source | 10.3 RON |
2x Breadboard | Circuit connection | 9 RON |
Wires | Connections between components | 8 RON |
Micro USB Cable | Power and programming cable | 4 RON |
2x Header Pins | Connection to breadboard | 4 RON |
Laser Pointer | Red colored laser | 2.6 RON |
TOTAL | --- | 174.9 RON |
Software
- Main task updates PWM every 25 ms based on current mode
- Each pattern is implemented as a separate function (except auto-sweep which incorporates 2 patterns):
auto_sweep()
- moves in a horizontal or vertical line based on tickrectangle()
- moves in a rectangle shape using phasespattern_circle()
– moves in a circle using trigonometrypattern_random()
– jumps to random valid positions
- Buttons are handled in separate async tasks with debouncing
- Shared state is safely updated using
AtomicU8
Library | Description | Usage |
---|---|---|
embassy | Async HAL & runtime | Core framework enabling async embedded development |
embassy-executor | Async task executor | Runs async tasks concurrently on the microcontroller |
embassy-rp | Raspberry Pi Pico HAL | Provides peripheral access (ADC, GPIO, PWM, etc.) |
defmt | Logging & debug output | Efficient logging for embedded targets |
defmt-rtt | RTT backend for defmt | Transfers logs from the device over RTT (Real-Time Transfer) |
embassy-time | Async timers and delays | Enables non-blocking timers with Timer::after() and Duration |
libm | Lightweight math library | Used for sinf and cosf in pattern generation |
fixed | Fixed-point math utilities | Provides traits for numeric conversions (ToFixed ) |
panic-probe | Panic handler for embedded | Minimal panic handler used for debugging |
core::sync::atomic | Atomic operations | Thread-safe state sharing between async tasks |