Twitch Dog Treat Dispenser

Node.js
Express
MongoDB
Arduino
MQTT

LarryBot” is an automated dog treat dispenser that let’s live viewers on Twitch.tv give treats to a good boy on command.

Why build a treat bot?

My fiancé Kim and I enjoy playing a computer game together called Overwatch. When we play, she frequently live streams our matches to Twitch for the world to see. One of the main attractions to the stream is the Larry Cam, where a live camera of our dog Larry is broadcasted. When viewers follow or subscribe, Kim will give him a treat as a reward. This has been quite popular for the viewers, they want to feed Larry!

This gave me the idea that there must be a better way…

Introducing LarryBot!

Built with some nifty software, 2 microcontrollers, an LED strip, a 3D printed auger system, an infrared beam detector, a servo, and some questionable woodworking, the LarryBot is a fully functional treat dispenser that puts the control into the hands of the Twitch viewers!

How does it work?

The Server

Running on Kim’s computer is a server (Express/MongoDB), this is the main brain of the system and is in charge of handling the communication between Twitch and the Robot. It also provides her with an administrative dashboard where she can toggle the system on/off, send the robot various commands, and see a summary of the treats given.

Dashboard

For those interested in the tech, the source code can be found at the end of this article.

If the system is enabled, Twitch subscribers can simply type the command !treat in the stream chat. This message gets intercepted by the server, but before a treat can be dispensed, a few things need to be verified:

  1. Is the system toggled on in the dashboard?
  2. Is the robot online and ready to dispense treats?
  3. Has a treat been already given in the past 30 seconds? (General cooldown)
  4. Has the user already given a treat recently? (User specific cooldown)
  5. Is the user a subscriber or a new follower?
  6. If all looks good, then let’s give a treat!

The server then sends a command using the MQTT protocol to the robot, instructing it to dispense a treat.

Chat Command

The Robot

The robot is built using 2 Node MCU ESP8266 microcontrollers that are connected to a local MQTT broker (EMQTT) over wifi waiting for messages. 1 controls the LED strip, the other controls the dispenser. This could have been combined into 1 microcontroller, however I had a pre-built proto-board designed for LED strip control from my Advanced LED Home Lighting System project left over, so I decided to use that.

*Progress photo of testing the prototype Inside the robot

*The completed build Inside the robot

The dispenser itself was 3d printed (thanks to Waltermixxx for the models) and slightly modified to fit inside the wooden box. It fits a standard sized servo perfectly. The hopper design does unfortunately cause jams to occur when filled up. We’ve opted to put less food into the hopper to avoid this.

When the robot receives the go ahead to dispense a treat, the LED’s will begin to flash and the auger servo begins to spin. Treats will be pushed out and will fall between the infrared beam sensor, into the funnel, down the tube, and into the bowl.

The beam sensor lets the robot confirm with certainty that a treat was successfully given and can stop spinning the auger. This also lets us control the amount of kibble that gets dispensed.

The robot will then respond back to the server with either a Treat Success or Treat Failure (ruh roh!), depending if a treat was given or not. This let’s Kim know when the robot has ran out of food and needs to be filled up with treats again!

Tune into Kim’s stream (https://www.twitch.tv/kbearz_) to check it out live!

Looking to build your own? The source code can be found below. Feel free to let me know if you have any questions.

Source Code


Questions or comments?