How to Create a Laser Cat Toy with ESP8266

MAKER:seasider1960/ Translator: Fun Endless

Previously, we introduced “Petoi Nybble: A Blessing for Raspberry Pi Cat Owners” and “DIY Laser Cat Toy with Arduino”.

This time we add a new gameplay, which is an upgraded version of the latter, supporting wireless control of the LaserKitty laser cat toy via mobile phone. It’s time to find some new fun for our feline friends!

Features of this cat toy: 1. Fully smartphone-controlled, with manual, automatic, and scheduled modes. 2. Custom application interface, with synchronized system status between multiple web clients. 3. Configurable parameters for panning and tilting range. 4. A settings page for clear configuration. 5. NTP time synchronization. 6. WiFi manager for easy setup on new networks. 7. Tone generator plays a cat’s mission theme before each game: your cat may appreciate it or ignore it. 8. Popup notifications for all devices when a new play session starts. 9. Configurable location for the cat bed, with game time ending at feeding points or fixed toy points. 10. All settings are stored in EEPROM, so data won’t be lost during power outages.

More new features await your development!

Material List

Mini gimbal × 1, Mini motor × several, Enclosure × 1, ESP8266 development board × 1, Laser emitter × 1, Passive buzzer × 1, 12-channel relay × 1, 15V DC power supply × 1, Resistor × several, LED lights × several, Wires × several, Heat shrink tubing × several, Soldering iron × 1, Hot glue × 1, Circular socket × 1, Multimeter × 1, Drill bit × 1, Stickers × 1 (to decorate it to suit your cat’s preferences)

Preparation of Accessories

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

1. Find a suitable enclosure. Consider the necessary accessories in advance and leave space as shown. If you don’t use a relay, you can use a smaller box.

2. Install the gimbal inside the box. Make sure to install it as close to the lid side as possible, so that the enclosure itself does not interfere with the beam emission at high tilt angles. Ideally, the laser should be installed perpendicular to the short side, rather than along the long side as I did.

3. Mount the NodeMCU on the perfboard for easy positioning. This allows easy connection of the micro USB connector from the side or back slots. You can update the software without opening the lid.

My initial idea was to use the Over-The-Air (OTA) library for updates; you will see that my code includes that functionality, but it has been commented out. That’s because the tone generator and OTA do not work well together (NodeMCU resets repeatedly while playing songs).

This issue could have been resolved, but I couldn’t successfully update SPIFFS without connecting the USB interface, which would have solved the problem.

But by the time I thought of it, I had already mounted the NodeMCU on the perfboard, meaning I had a lot of work to do.

4. Align the RGB LED with the red “power on” LED. (This way, you can directly observe the mode of the cat toy through the RGB LED indicator without looking at the application.)

5. Drill holes for the rectangular part of the panning motor.

6. Drill three holes for the power socket, buzzer, and the entrance points for the tilt motor and laser wiring. All holes are round.

Everything is secured in place with hot glue (except for the panning motor, which is fixed to the lid using a motor mounting tool).

Gimbal Installation

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

Assemble according to the instructions provided with the gimbal. After all assembly is complete, ensure it maintains a panning angle of 180 degrees on the surface of the enclosure before powering on.

Wiring

How to Create a Laser Cat Toy with ESP8266

Ensure the brightness of the laser is the brightest in indoor light but not too strong. Therefore, it can be powered from the 3.3 VDC pin on the NodeMCU, with a 22-ohm resistor in series.

Theoretically, it consumes about 10mA of current. Of course, you can also power it directly from the GPIO pin, but even without a resistor, the light is too dim.

1. The laser has very limited ability to change focus (collimated light); I use it to make the point larger, thereby dispersing the laser energy.

2. Isolate the motor from the power supply completely. Since the relay has two channels, I think it can switch the laser (the purple wire is the control signal from the MCU).

You can also use other solutions, such as powering the relay directly from a 5V DC power supply, with the NodeMCU powering the dual-channel relay directly, but it’s not necessary to take that risk.

If you have already used a relay, please remove the jumper between JD-VCC and VCC before use.

3. The RGB LED has a 220-ohm current-limiting resistor for red and green, and a 100-ohm current-limiting resistor for blue.

The red “power on” LED has a 450-ohm resistor because it is powered by 5V DC instead of 3.3V DC. These are approximate settings to achieve sufficient brightness and reasonable lifespan.

4. The buzzer sounds normally. You may need to add a resistor on the signal line to reduce the volume. The tone can be completely turned off via software, but something in between might be nice.

Code

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

The required code files are provided in the project file repository:

https://maker.quwj.com/project/93

For the automatic mode of the laser’s movement, please click to download.

https://github.com/fluxaxiom/Arduino_AutoCatLaser

You can also use a 3D printer to create some components.

The code (found on GitHub) is divided into three main parts.

https://github.com/seasider1960/LaserKitty

1. Arduino sketch, HTML files containing some Javascript for application content, and relevant CSS files for templates.

I use this project to learn all these programming elements, starting from a very low foundation, especially in terms of application interfaces. The code uses Websockets for bidirectional communication between the NodeMCU server and connected clients.

After downloading from GitHub, paste the entire file into a folder, upload the sketch to the MCU, and then upload the contents of the “data” subfolder to SPIFFS.

2. Using Pushbullet notification feature requires an API access token first. (API access token ) It is located at line 88 of the Arduino code.

Pushbullet works very well. However, if you are setting up an account on your phone for the first time, you must log in, log out, and log back in to get notifications to display according to the settings on your phone.

3. There are three web pages: the startup screen, the actual application interface, and the settings page. Separating the settings page makes the user interface feel more like an application, especially with a lot of configuration options.

To enable the NodeMCU to serve multiple pages, I had to place all image files directly in the data folder.

If placed in subfolders, it won’t work. In the GitHub repository, the hardware contains all the images used, ready to go, and you can also replace them with your own images.

Completion and Testing

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

How to Create a Laser Cat Toy with ESP8266

The HTML file of the startup screen contains an icon to add to the iPhone’s home screen.

Finally, I have two points to remind cat slaves about the defects of the laser cat toy. 1. The laser may blind or damage the cat’s eyes.

2. For cats, the laser cat toy cannot fully satisfy them, as they can never catch or “kill” it.

In the end, you must decide whether this project or any other laser toy is suitable for your cat. I address the first issue by dimming the laser as much as possible. Additionally, ensure that the cats do not stare directly at the laser itself but at the point it emits.

Regarding the second issue, I save the setting of the “original position,” so the laser returns to a preset endpoint after running. You can set it to a fixed toy or the cat’s bowl. If you have better methods, feel free to share.

All the source code and resources used in this project are available for download in the project file repository:

http://maker.quwj.com/project/93

via instructables.com/id/LaserKitty/

Links in the text can be clicked to read the original text at the end

How to Create a Laser Cat Toy with ESP8266

More exciting content

Raspberry Pi Drawing Robot

DIY “Click” Sound Control Switch with Raspberry Pi

Making a “Pocket TV” with Raspberry Pi

Raspberry Pi 3 Model A+ Released

Making an LED Scrolling Display with Arduino

DIY Rechargeable 18650 Lithium Battery Pack with Unlimited Expansion

How to Create a Laser Cat Toy with ESP8266

Leave a Comment

×