Building a chatbot controlled car with Raspberry Pi and remote controlled car

Stephens Xu
Fullstack Network
Published in
4 min readJul 20, 2017

--

Last night on the Fullstack Network stream, we built a twitch chatbot that controls an RC car using Node.js and a Raspberry Pi.

The idea is that we wanted to have a car that can move around following commands sent from a chatbot over the internet (twitch chatbot in our case, but can be any chatbot).

Our base car is just one of the cheapest RC car you can find on amazon which only cost $28 like this one

http://amzn.to/2tnyIqW

Nothing special about it, it comes with a remote control just like any regular RC car. The key is that there is just one button per movement. Unlike more expensive cars where you can also control acceleration.

Of course the car itself has no internet connection capability, at its current form its only capable of talking to the remote control.

This is where the Raspberry Pi comes into play, it will serve as the computing center that talks with the internet and make communications with the remote control of the car.

This is the Raspberry we are using in case you’re curious

http://amzn.to/2uiPg64

The Raspberry Pi is basically a Linux machine. Once we connect it to the WiFi/computer, we’ll be able to ssh into it and perform tasks just like any linux machine

Once connected to the internet, we’ll be able to download and install basic linux packages using apt-get

On the hardware side, we need to create a circuit that will “activate” using one of the gpio pins.

We are using an optocoupler, one side connected to ground + gpio and the other side connected to the remote.

Once these circuits are wired correctly, the Pi is able to send on/off signal to the remote control circuit board via its pins.

Now we need to write some software inside of the Pi that gives us flexibility in controlling the pins.

We use rpi-gpio for this purpose. rpi-gpio is a nodeJS library that allow us to interact with the GPIO pins on the Pi.

We use these pins to send signals to the remote control of the car so that we can control it, like so:

Here in our terminal if we do

sudo node app.js

It will trigger the on()function of the script, signaling an on signal to the pin of the Pi; after a full second, it will then trigger off() function which sends off signal to the pin. These on/off signals are passed on to the remote control by the Pi and therefore running the car.

Now we already have an interface that controls the car from the Pi, final step is allow Pi to trigger actions of the car based on messages it receives from the internet. We use tmi.js to connect with API of twitch chat channel

When we receive a message from the twitch chatFORWARD we trigger the on() function, which will then triggers the car to run.

To see the car moving in action check out the video below:

Now anyone can control the car from anywhere as long as they have internet!

This was pretty cool to me and I was super excited the moment I saw the request came in and the car’s wheels started moving.

This is still work in progress, next step we might try to figure out how to move the car back and forth with different directions and possibly add functionalities to avoid crashing into objets.

Tune in our next stream next time if this interest you!

--

--