Sunday, 11 October 2015

Simple Arduino Robots for Kids - Part 1

Simple Arduino Robots for Kids - Part 1

I want to share this series of articles on fun things to do with a simple tricycle-layout robot with two drive wheels.

I start by building a basic remote control car, then use this to engage kids' interest in adding autonomous behaviours and more components.

Simple Arduino Robot

Ask your kids what they they want to add next, they might surprise you.

The robot is based around the "Differential Drive" layout, where there are two independently driven wheels, and steering is achieved by varying wheel speed.

You see this pattern in a lot of places, for example:

  • Star Wars' R2D2
  • Roomba and imitators
  • Most small e-bay robot chassis (see below)
  • Tanks and other tracked vehicles (including WALL-E)
  • Segways and other self-balancing vehicles

The advantages of this arrangement are simplicity (only two motors, no steering linkage) and nimbleness (can turn on the spot). The disadvantage is that if the wheels aren't turning at the same speed, the vehicle will not run straight. The disadvantage can be overcome using closed loop feedback of some kind.

Simplest possible case - two motors, no feedback

You can get a long way with two well matched motors and no feedback (and if your motors aren't matched, you can maybe get away with correcting for the mismatch in software).

We will use this arrangement as a starting platform to be embellished in future articles. For now, we will build a working robot with the least number of parts.

Assemble your chassis

The chassis kit from ebay comes with decks, spacers, screws, wheels and motors. Kids can assemble it with minimal help.

Basic Chassis kit from eBay Chassis rear view Chassis Underside

You will need to solder some short wires (about 8cm) to the motors.

Begin fitting the electronics

All the electronic parts can be found at or other hobby electronics supplier.

You need an Arduino board, a Battery pack, some breadboards, a dual-channel motor controller, and a Bluetooth module. You'll also need some breadboard jumper wires. There are links to parts sources above.

Electronic Parts

Fit the motor controller

Start by connecting the motor wires to the motor controller, using a small screwdriver.

Connecting the motor drive Motor driver connected

Fit six female-to-male jumper wires to the motor controller, and secure it in place with a cable-tie. You can put it in any position that is easy to secure.

Jumper wires for motor driver

Fit the battery

Secure the battery box over the front wheel using a cable tie. Feed the wire up to the top deck through one of the holes.

Fit the battery

Connect the Arduino

Here I use a small 5x5 breadboard as a power distribution bus, but you can dispense with this, and use spare rows on a single breadboard if you prefer.

I'm using an Arduino Nano compatible, but there is room for a full-sized board such as Arduino Uno if that's what you have.

Connect the motor driver

Connect your battery to the VIN pin on the Arduino. This will use the Arduino's on board regulator to reduce the battery voltage to the 5v needed by the microcontroller.

To reiterate the power connections

  • Battery connects to ground and VIN
  • Motor controller connects to ground and VIN
  • Bluetooth connects to ground and 5v
  • Anything else should connect to ground and 5v

Program the Bitlash firmware

Install the bitlash library from Open the "bitlashdemo" example by following the Arduino IDE menus to File -> Examples -> bitlash -> bitlashdemo. Select your board and port and program the sketch.

Connect the arduino serial monitor and you should see "Bitlash Here" plus more information and a command prompt. The bitlash demo defaults to 57600 bits per second as the serial port speed. If you have trouble with bluetooth later on, try changing the bitlashdemo script to use 9600 bps.

Connect the Bluetooth Module

You won't have much fun tethered by a cable, so we are going to use a Bluetooth radio to replace the USB cable.

The Bluetooth module has 4 pins, Power, Ground, Transmit and Receive. Connect power and ground to the 5v pin on the Arduino (NOT the unregulated battery nor VIN). The TX pin on the Bluetooth goes to RX on the Arduino, and vice-versa.

If you hook up a USB cable to your Arduino, you should temporarily unplug the Bluetooth module first, so that the Bluetooth and the USB bridge do not "fight" over the TX and RX pins.

Simple Arduino Robot

Pair the bluetooth module

Start out using your PC to talk to the bluetooth module. You can use a PC, Mac, Linux or Android. Unfortunately iPhone and iPad don't have general purpose bluetooth serial connectivity; later in this series we will look at other ways to use an iPhone to control the robot.

Use your operating system's bluetooth settings to pair the device. Then use the Arduino serial monitor, or any serial terminal program to connect to it. Pair your bluetooth module

To use the terminal app on Mac or Linux, you can do

$ screen /dev/tty.HC-06.Dev-B

On windows, try Hyperterminal.

Program some simple commands in Bitlash

The motor controller will drive each motor in forward or reverse, using two pins, A and B. The motor controller lables its pins IA1 IB1 (inputs A and B for motor 1) and IA2 IB2 (inputs A and B for motor 2).


At this point, it may turn out we hooked up one of the motors backwards. If the motor runs in the wrong direction, loosen the terminal block screws and reverse the wires.

Arduino Pins 2 and 3 are the A and B outputs for the left wheel

Arduino pins 4 and 5 are the A and B outputs for the right wheel.

Later in this series we will use Pulse-width-modulation and the analogWrite function to control speed of the wheels. For now, we have stopped and full speed.

We define six basic bitlash commands to control the motors

  • lfwd - left motor forwards rotation
  • lrev - left motor reverse rotation
  • lstp - left motor stopped
  • rfwd - right motor forwards rotation
  • rrev - right motor reverse rotation
  • rstp - right motor stopped

Paste these commands into bitlash, put the robot up on a block (or disconnect the wheels) and try them out. Make sure you run 'iosetup' first. You may need to stop and rewire the motors if the wheels turn in the wrong direction.

function iosetup { d2=d3=0; pinmode(d2,1); pinmode(d3,1); d4=d5=0; pinmode(d4,1); pinmode(d5,1); }

function lfwd {d2=1;d3=0}
function lrev {d2=0;d3=1}
function lstp {d2=d3=0}

function rfwd {d4=1;d5=0}
function rrev {d4=0;d5=1}
function rstp {d4=d5=0}

Once you are satisfied that the motors are working, we can move on to some higher-level behaviours:

function fwd {lfwd;rfwd}
function rev {lrev;rrev}
function stp {lstp;rstp}
function ltr {lrev;rfwd}
function rtr {rrev;lfwd}

function navsetup {a=40; b=120}
function l90 {ltr; delay(b); stp}
function r90 {rtr;delay(b);stp}
function l15 {ltr; delay(a); stp}
function r15 {rtr;delay(a);stp}

function startup {iosetup; navsetup}

Since we are going to do without motor feedback for now, we will achieve controlled turns by guessing how long to run the motors. I arrived at 40ms for a 15 degree turn, and 120ms for a 90 degree turn. Adjust the values of variables a and b until you get good results.

Try to drive your robot around using the bitlash commands. I got quite good at this after a bit of practice.

Control the robot with an Android phone

You can replace "fast typing and crashing a lot" with an Android phone. Download the BlueTooth Serial Controller app, which lets you define buttons to send each of the commands above.

Set up Android app to control

Use the app settings (spanner icon) to name and configure the buttons as shown. Each button should send the command, plus a new line.

To connect to your robot, tap the magnifying glass icon and look for your bluetooth device. When you have connected the light on the bluetooth module will stop flashing and become solid red.

Have fun!

Now you have a robot that you can drive around.

What next?

In future articles we will look at some variations and improvements

  • Using a hobby radio control transmitter and receiver instead of bluetooth
  • Using and internet connection and an iPhone
  • Implementing closed-loop feedback for more precise steering
  • Adding sonar and infrared collision sensors
  • Adding First Person View video camera
  • Scaling up to bigger platforms
  • Becoming autonomous, and more


Unknown said...

Awesome, thanks for this great write up. Im in the process of building on of these and have added solar panel powered ability too. The Android software to control it is something I have to look into. Thanks!
rc boats

Unknown said...

Can u plz give the full code with everything in it u used? I'm doing the same project but having trouble programing it.

nabilkader said...

Always maintain this in mind, especially if you love taking part in} slots with progressive jackpots. When you decide to play wagering video games, you should first establish a gaming budget. This will permit you to gamble guilt-free because of|as a result of} it's not prudent to squander your money before your money owed and routine prices are met. Your casino budget may also assist you in deciding which activities you can to|you presumably can} and cannot probably play. Slot machine fans are in luck when it comes to of|in relation to} on-line casinos {because|as a result of|as a result of} 카지노 사이트 추천 these video games have one of the best bonuses. For the best rating, we want a candy welcome bonus mixed with reload bonuses, tournaments, jackpots, time-sensitive bonus rounds, free spins, and more.