Twitch Livestream Controlled Delivery Robot

by ksunayana-pai in Circuits > Arduino

2080 Views, 13 Favorites, 0 Comments

Twitch Livestream Controlled Delivery Robot

IMG_7990.jpg
short.gif
Twitch_plays_pokemon_animated.gif

Hello! I am Sunayana Pai, an interdisciplinary engineering junior at San Jose State University. I'm working with Andrew Duong, a mechanical engineering senior.

Inspired by the popular Twitch Plays Pokemon (where viewers of a stream sent commands for the game's character to follow) and various delivery robots on the market, we wanted to create a entertainment in the form of a delivery bot the viewers are challenged to control. If you've never heard of Twitch, it is a live broadcast in which people can watch and chat in real time!

We decided to call this robot TOADS, which stands for Twitch Operated (Internet) Accessible Delivery System!

Supplies

Circuit/hardware components:

  • ESP8266 (or any other microcontroller with Wi-Fi capabilities)
  • L298N dual motor driver
  • Link includes motor driver, motors, and wheels
  • Motors (x2)
  • 1.5V AA batteries or equivalent (x6)
  • You can use a higher voltage as long as the L298N can handle it. You can also use rechargeable LiPo Batteries!
  • HC-SR04 ultrasonic distance sensor
  • Wheels
  • 3/4" ball bearing (x2)
  • Jumper wires
  • Male to Male, Female to Male, and Male to Female
  • #8 Screws and Nuts
  • Screwdriver
  • Soldering Iron + Solder (Optional but recommended)

3D-printing:

  • 3D printer
  • 1kg 1.75 mm PLA filament
  • We used green so ours could look like a toad :)
  • We also used transparent filament for the bottom.

Picking Parts

Before we get started building the robot, we did lots of research on what we would need. It's great to look at examples online. We looked at various Twitch projects, Arduino Libraries, and robot cars.

At first we wanted to use an Arduino, but we also needed WiFi capability, which would require something like an ESP8266 module. However, we found that we could actually get by with just the ESP8266 as the microcontroller.

Lots of simple Arduino cars used the L298n motor drivers and just DC motors, so we opted to use those as well. In addition, they had HC-SR04 distance sensors to detect obstacles which we felt would help for our robot.

The battery power was the hardest part for us to understand. It needs to power the motors and the ESP8266, which is possible through the various power outputs and inputs on the components. A 9V battery would work, but they run out very quickly when powering motors. A better choice would be AA batteries in series or a LiPo battery, especially rechargable ones. They can provide better current and voltage. So, for that, we got a battery holder and AA batteries.

Finally, we decided that we did not need all 4 wheels driven, so for the front two we planned to use bearing ball casters.

Modeling Chassis

Chassis.PNG
2022-07-16 23-38-27.gif

First we needed a chassis to hold our components—the microcontroller, motors, motor driver, distance sensor, and battery pack.

To decide on the area, we placed all the components together and estimated the space needed, with some tolerance. We decided an area of 20 cm by 12.5 cm, would be enough so we started with that as a base. We also needed at least 42.5 cm of height from floor to top to allow components to fit. Walls were 0.25 cm thick.

Then we added features to the chassis to accommodate for our components. To hold the motor and driver in place, we added frames inside of the chassis to hold them in place. In addition, we had holes in the side so the motor axles could poke out. We also made a mount for the distance sensor. The height is necessary for the distance sensor to properly function, as it shoots sound out in a 30 degree cone to detect obstacles, and can bounce off the ground.

Finally, we needed a way to hold the chassis housing and container portions of the bot together. At first we wanted to design a snap-fit, but we found it easier to do holes for nuts and screws. These were also used on the bottom of the chassis for the bearing ball casters.

Downloads

Modeling the Container

Capture.PNG
2022-07-16 23-26-29.gif

Next we designed the container and lid, starting with the container.

The container is fairly simple as it follows the same profile as the chassis below it.

A lot of time was spent adjusting details on the hinge and how it would print and function; but ultimately, we settled for a flap lid instead. For this design, we had cylindrical extrusions on either side of the interior of the container for the lid to snap onto.

We also put a toad face on the container, alluding to the project's name of TOADS, and adding aesthetic flavor!

Modeling the Lid

2022-07-16 23-27-45.gif
Capture.PNG

Next we designed the lid, which we designed to fit snugly inside the container. It has cylindrical snaps to hinge on the container and also has a snap fit on the front which we intended to hold the lid in place without locking it.

Downloads

Modeling the Ball Transfer Unit

Capture.PNG
2022-07-17 03-46-01.gif

A bearing ball caster is a type of wheel that uses a bearing ball to roll in any direction. We thought this would be great for giving our robot stability when moving while also giving it a full range of motion. In comparison to swivel caster wheels you can buy, this does not interfere with movement when the caster swivels back and forth, and the ball caster can be adjusted to fit the height of our wheels in the final product.'


With this design, we designed it around the 3/4" bearing ball, and we did several different sizes to print to test what would fit perfecty. We added a lot of fillets to add stability to the caster when it is bent open by the bearing ball.

The Final Assembly

ASSEMBLED 3D MODEL.PNG

Here is the completed 3D assembly of the modeled parts of this project!


Starting 3D Printing

Once our models were complete in Fusion 360 we exported the files into Cura to slice them for our printers. All of our parts were printed using our Creality Ender 3 printers with 1.75mm PLA. We were able to complete all of our printing in one day using the print farm. The two main components took 18 and 24 hours each, with the bearing ball ball casters taking 30 minutes to print individually.


Bearing Ball Caster Print

9B52586E-62F0-4232-815E-4F6979EA03F6.JPG
IMG_0345.JPG

Again, we printed multiple sizes to test with the bearing balls. Upon testing, 3 out of 5 of the different sizes snapped or did not fit well. 2 of them did, which were the middle in the range of sizes, and we found that they rolled as expected.

Chassis, Container, Lid Print

Screenshot_20220628-162453_Discord.JPG
IMG_7982.png
chassis.gif
realchassis.gif
IMG_8142.jpg

The printing of all these containers went well, and we had no problems for the most part. The face on the front of the container actually came out very clearly, which was a nice surprise. For the lid we went on without the snap fit as it was not important to the overall function.

Testing Connections

IMG_7989.JPG
chassis+container.PNG
ball caster.PNG

Our #8 screws were able to attach the top module to the lower, as well as the ball bearing holders to the lower module. Once this was completed we attatched the lid to the top module to secure the delivery package. Once this was complete we tested the ball bearing capabilities as well as the lid to ensure they would work. We verified both and our model was ready for testing.

Motor and Motor Driver Placement

solder.PNG
electrical.PNG
motor fit.PNG
Capture.PNG
sanded.PNG
taped.PNG

Then we wanted to assemble the whole thing, starting with the motors and motor driver.

The first thing we did with the motors was was to solder the wire leads to the motors themselves, as the motors came with no secure way to fasten them together. You could also possibly use electrical tape, which is also important to wrap around the leads so that they don't move and break the fragile solder.

We placed the motor driver and motors into the chassis. While the motor driver fit as expected, we found that we needed to break off a piece of the wall and make some adjustment to the motors by sanding down protrusions, to fit it in. After, we taped down the motors inside the mounts with duct tape.

ESP8266, Battery Holder, Distance Sensor Placement

esp.PNG
completed.PNG

With the battery holder and ESP8266, we didn't really need to hold them down all that well. The motors of course needed to be held down because their movement depended on it, but the ESP and battery didn't move all that much and just needed light securing, which was done with- you guessed it- more duct tape! The HC-SR04 distance sensor mounted as expected on the front, with some sanding on the holes.

One thing to note is that we covered any screws and nuts with electrical tape to make sure there was no unintended conduction. As you can see in the picture, we also did the wiring, which will be elaborated on in the next step.

Create Circuit

Schematic_ESP8266_2022-07-11.png

The wiring part of this project was tricky to figure out for first time Arduino users... first time circuit creators in general, really. Some of it is straightforward, some of it is based on code.

The most important thing in the wiring is the power, because you need it to turn the thing on in the first place, and because it can easily fry your components.

The idea here is that we will power the L298n directly from the battery, then power the ESP from the L298n, then the distance sensor from the ESP.

The battery positive should go to the L298n (if the black rectangle, the jumper, is on behind the 12V, it currently doesn't take more than 12V but can take more than 5V). We did not as to not cause any accidents to begin with.

As you can see, we connect Vin to the 5V on the L298n- the Vin pin can take 5V and regulates it down to the 3V that the ESP uses. The 3V3 outputs 3V, and connects to the HC-SR04 which can run on 3V if you have the right kind.

All components should be connected to common GND to complete the circuit. All GND pins on a board are connected together. So, black battery lead to the GND of the L298n, L298n GND to the ESP8266 GND, ESP8266 GND to the distance sensor GND.

Finally, put in your batteries, and when you're ready to turn it on, insert the positive lead of the battery into the L298n 12V. If you're not going to use it, take a battery out of the holder so no accidents can happen.


Now for the other pins, a lot of it is defined in the code itself. The motors should however, go to the OUTs on the L298n, one to each side (1,2 & 3,4). Generally the ENA, ENB, IN1-4 should go to an D pin on the ESP. Which one, is defined in the code. Echo and Trig on the distance sensor is the same way.

Write Code for ESP8266

The code was written and uploaded using Arduino IDE and is designed to do the following:

  1. Connect to Wi-Fi/hotspot (only the name and password of the network are in the code; if there are extra steps involved to connect then this portion will have to be tweaked)
  2. Connect to Twitch's IRC server:
  3. this is necessary for processing commands from the chat
  4. include your generated Twitch OAuth token
  5. include your channel's name
  6. Detect when a chat message is sent and receive chat commands to control bot movement
  7. Tally incoming commands, determine the most voted for command, then move accordingly and execute any programmed actions

Reminder: the relevant libraries must already be installed, the correct Board must be selected (in our case, NodeMCU 1.0 (ESP 12-E Module))

Include this link for the board in Tools --> Preferences --> Additional Board Manager URLs:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

and install these libraries:

ArduinoIRC by Fredi Machado

NewPing by Tim Eckel

We used a state machine-driven code to organize the bot's movements. Each state has conditions to move to another state, including timers, distance sensing, and command reciving. For example, when 'forward' is sent, the bot, initially in the STANDBY state, will switch to FORWARD upon checking that the distance read by the sensor is not too little. In the FORWARD state, the bot will move and make sure it's not going past the specified time for movement by using the millis() function.

Video Demonstration of the Project

Twitch-controlled Delivery Bot in action

As you can see in the video, the robot works! We tested it with one command at a time, and also with a lot of spam. It takes the most voted for command and runs with it. We also made a little overlay for it, if we ever wanted to play with a large crowd.

In the future, for this project, it would be great to implement higher precision turning, stronger motors, and more functions like LEDs or Music.

Thanks for reading!