IoT Laser Pet Toy

From time to time, my kitchen falls victim to a bored dog. When left unattended, skirting boards, dog beds, kitchen towels, kitchen cabinets and paintwork have all suffered. To help keep my pupper entertained while I'm at work, I developed an IoT laser pet toy to keep him occupied. In the auto mode, a laser will move around the floor in a random pattern for a period of time, after which treats are dropped to reward the pet. The reward is important so they don't get frustrated by the elusive laser and it encourages them to play!

It can be controlled manually via a smartphone, or set to auto mode. It can also be activated by voice using Google Assistant(auto mode only).

Supplies:

To build this project, you will need:

  • 2 mg995 servos
  • pan and tilt sensor mount kit
  • 1 micro servo SG90
  • protein scoop or equivalent
  • 650nm Red Laser Diode Module
  • nodeMCU
  • wire
  • pcb
  • power supply(12v 5A)
  • DC-DC 24V/12V To 5V 5A Step Down Buck Converter
  • solder
  • soldering iron
  • smartphone/Google home device
  • glue gun
  • tape/glue

The following software is also required:

  • Arduino IDE and esp8266 library
  • IFTTT
  • Blynk app and libraries
  • Google Assistant

Step 1: Hardware

  1. Assemble the servo mount kit. I taped the base of it to a pcb, long term, i will fix it to the top of my kitchen with a screw.
  2. Refer to circuit diagram for wiring. Also see images of my poor attempt at soldering :)
  3. Glue the laser to the top of the pan/tilt servos and also glue a scoop to the treat servo (I also used a second scoop as a stand for the treat servo but you can use whatever).

Notes:

The servos I used are quite bulky, you might get away with less since the workload is small.

Each servo can draw up to 1200mA (the smaller one draws less), add another ~700mA for the nodeMCU and you get a max draw of ~3100mA. This is why I used a 5A supply. I originally used a breadboard and a 1A supply, when I turned it on, the nodeMCU kept resetting. If you experience this problem, double check that your setup can supply enough current.

Step 2: Software: Blynk App

  1. Install the Blynk App: https://blynk.io/en/getting-started
  2. Follow the steps to create an account, a new project and get an auth token
  3. Select the target device when creating project(nodeMCU)
  4. Inside the project you will add 5 widgets:
    1. Button to turn on/off the laser
      1. map to D0
      2. set to switch mode
    2. Slider to adjust the tilt angle(V0, range 0-180)
    3. Slider to adjust pan angle(V1, range 0-180)
    4. Slider to adjust the treat servo(V3, range 0-180)
    5. Button to turn on/off auto mode
      1. map to V2
      2. set to switch mode

Step 3: Software: Arduino IDE

  1. Install Arduino IDE: https://www.arduino.cc/en/main/software
  2. Add blynk and esp8266 libraries
    1. Blynk: How to install Blynk library
    2. esp8266: How to Install ESP8266 Into Arduino IDE credit to mybotic
  3. Code
    1. Download or copy the code from Github(file below also)
    2. In the code, you will need to set ssid and password for your router(wifi).
    3. You will also need to set the auth token that was created for Blynk. You can request the token via email through the app.
    4. You may also want to adjust the min and max angles on the servos, these are set so that the laser will always point on the floor, during initial tests I discovered that dogs will chase the laser up the walls :) Keep it to the floor unless you want to redecorate!
    5. Note: timers are used in this project to reduce the number of requests to the Blynk cloud, if too many requests per second are made, you will be disconnected. It is also important to keep the amount of code executed in the loop() function to a minimum. Refer to this article for more info. The auto mode will move the servos randomly every 2 seconds, 10 times and then drop a treat, you can adjust this to your own needs.
    6. Connect the nodeMCU to your computer via usb.
    7. Make sure the correct board and port are selected under tools.
    8. Upload the code to the nodeMCU(right arrow button in the top toolbar).

Step 4: Software: IFTTT

In order to activate the toy using Google Assistant, you will need to create an applet using IFTTT.

  1. Create an account
  2. Go to "My Applets" > "New Applet"
  3. Click on "This" and search for Google assistant
  4. Select "Say a simple phrase"
  5. Fill in the fields as you see fit and select "create trigger"
  6. Click on "That" and search for webhooks
  7. Select "Make a web request"
  8. set url to BLYNK_IP/AUTH_TOKEN/update/V2?value=1
    1. To get the blynk IP from your country just go to the command line and enter: ping cloud.blynk.cc

    2. Update the ip and auth token fields in the url. It should look like: http://139.59.216.123/82ece8701f394bb1aad578fd96fd7a0b/update/V2?value=1

  9. Once the applet is saved, you can test the laser using Google Assistant!

Step 5: Final Thoughts

And there you have it, a voice or phone controlled IoT pet toy. To improve the project further, I would add a case for the circuitry, and also a webcam so you could watch your pet play while you are away. The voice control could be enhanced by being able to specify how long the toy runs for i.e. "turn on the laser for 5 minutes". A way to reload the treat scoop would be nice too. Enjoy building and post your progress below!

Share

    Recommendations

    • Frozen Treats Challenge

      Frozen Treats Challenge
    • Pets Challenge

      Pets Challenge
    • Beauty Tips Contest

      Beauty Tips Contest

    2 Discussions

    0
    None
    Rob4white

    15 days ago

    Great job young Sionnach!

    0
    None
    randofo

    18 days ago

    Nice! Thanks for sharing. :)