Arduino Project 8: Stompy the robot (part 1)

Arduino Project 8: Stompy the robot (part 1)

 

APC's Stompy the robot masterclass
Stompy the walking robot. Isn’t he cute?

Our first Arduino robot called Rolly in our February issue proved to be a popular project. Powered by an Arduino Uno board it was easy to put together and cost very little. In this project we upped the ante again with our first walking robot appropriately called Stompy. He’s a quadruped a four-legged walker and he’s physically about as simple as you can make a walking robot.

If you look online there are plenty of six- and even eight-legged robots but the one thing they all have in common is that they usually cost a small fortune – upwards of $300 and typically closer to $500. We’ve found a much lower-cost alternative called the Dagu Quadbot designed by Australian Russell Cameron available from RobotGear for $55 including shipping. For that price you get the main plastic chassis the leg pieces and eight tiny plastic-gear servo motors; the rest including the electronics that drive it is up to you.

Plastic-gear motors mean you won’t be tackling Mt. Everest with this little guy although he should be enough to pique your interest and save you a fortune buying something else.

Parts list

Part Cost Source
Arduino Uno R3 $13.20 eBay
Arduino Sensor Shield V5.0 $4.86 eBay
Dagu Quadbot chassis kit $55 eBay
DC-to-DC converter $3.14 eBay
SPST toggle switch $1.95 eBay
HC-SR04 sensor $1.88 eBay
TowerPro SG90 servo motor $2.37 eBay
470uF/16VW electro capacitor $0.75 Jaycar
TOTAL COST $83.15  

 

Our design

Normally servo motor-based robots require a specialised controller board designed for the purpose and there are a few around. You can also use a standard Arduino Uno board although because Arduino and servo motors have different voltage requirements you typically see Arduino-based bots with two batteries: the standard four AA cells for the servo motors and a 9V battery for the Arduino board itself. However we’ve come up with a unique design that sticks with an ordinary Arduino Uno board and only needs the basic four AA-cell battery.

The basic problem we’ve overcome is that the Arduino’s ATMEGA328P chip needs 5VDC power but you need to feed it at least 7VDC to allow the onboard voltage regulator enough head room to generate the clean 5VDC needed. That’s a problem because the lightweight servo motors in this kit will blow up if they’re fed with 7VDC. What’s more the Arduino’s regulator can’t drive the servo motors directly.

 

Arduino Sensor Shield V5.0

We’re introducing another Arduino expansion board this month called the Arduino Sensor Shield. It’s a low-cost (under $8 shipped) board that allows you to connect a range of sensors to your Arduino using easy-to-attach jumper cables. It’s a simple board with no electronics on it other than a couple of resistors and an LED. Its main role is to supply those header pins to make it easier to attach external devices like our servo motors.

 

Heavy load

Stompy requires nine servo motors all up: two for each leg and one for the neck; however the electrical demands of powering those motors puts a heavy load on the power supply. Given we’re using four AA Nickel Metal Hydride (NiMH) rechargeable cells we have plenty of power yet not much voltage – around 5.5VDC at best under no load. As soon as we ask the battery to handle those motors its voltage begins to sag to below 4.5V. As soon as that happens the Arduino Uno drops below its operating voltage and resets itself. This results in Stompy starting and stopping starting and stopping as the battery voltage yo-yos up and down.

The quick and dirty solution is to use two batteries: four NiMH cells to deliver 4.8-5.2VDC for the motors and a small single-use PP3/9V battery to power the Arduino. Personally we hate that solution – it’s just dodgy. You’ve now got two power sources to check and you’re using a battery that was designed for transistor radios in the 1950s not driving microcontrollers. What we need is a solution that fixes the voltage reset issue without needing that PP3 battery.

 

DC-to-DC converter

The solution is a tiny little circuit board the size of a postage stamp. It costs around $3 including shipping on eBay and solves the problem perfectly. It’s called a DC-to-DC converter. They’re normally sold inside cases to act as emergency USB power for charging phones or on their own with a USB Type A socket on the end although you can buy the circuit board separately and use it to deliver 5VDC at up to 1000mA from as little as 2.5VDC input.

How it works will take more space than we’ve got but here’s the abridged version. It uses a charge pump that switches a small inductor on and off at a high 1MHz frequency. Inductors are weird components that try to maintain their electrical field when the current is switched off by raising their voltage. The voltage is dumped into a capacitor through a fast-recovery blocking diode and regulated by the switching circuitry to a very steady 5VDC.

So instead of powering the Arduino Uno directly from the battery we solder a connecting wire from the DC-to-DC converter’s output directly to the 5VDC pin of the Arduino and bypass the onboard regulator. While the battery voltage varies significantly under the load of the motors the converter provides a regulated 5VDC output that keeps the Arduino happy. Most importantly the whole thing is powered by just one battery.

However there’s one other issue: the servo motors are driven by the sensor shield and the shield is connected directly to the battery. The shield is also connected to the Arduino with our DC converter voltage. In order for all of this to work we need to separate the voltage rail of the shield from the Arduino as the DC converter creates a new 5VDC voltage rail we have to respect.

The solution is supplied by the sensor shield. Right near the battery input terminal block there’s a PC board jumper. Remove it and the 5V supply rails are now separated and everything works. Make sure your sensor shield has this jumper otherwise the robot won’t run. Finally we only need three wires to the converter: DC voltage in the 5VDC output and the common ground (0V) line that goes to the battery ground and the Arduino’s ground plane. The fact that it’s a common ground means we only need one ground connection to the DC converter. Apart from wiring up the power switch connected to the battery the only soldering you need is the three wires to the converter.

 

Turning heads

We’ve borrowed the same basic eyes and neck from our first robot Rolly and used them here to give Stompy some corrective feedback. The HC-SR04 ultrasonic sensor sends out 40kHz bursts and measures the time for the echo to return to give us an accurate distance in front. By putting the sensor on top of another servo motor we can rotate the sensor and scan the surroundings without having to move the whole robot in that direction.

 

Power

Finally to keep things compact we’ve used a basic four-cell battery holder stuck to the underside of the Perspex base and included a single-pole single-throw (SPST) switch to quickly control power.

 

Use NiMH rechargeables

Single-use AA batteries are convenient but a waste. They’re also Stompy’s Kryptonite. Standard AA batteries deliver around 1.6VDC voltage with no load. Add four together and you’re looking at 6.4VDC which is too much for our DC-to-DC converter. With an input voltage that high the output becomes the input minus the blocking diode voltage drop (0.6V) which can be as much as 5.8VDC. Connect that directly to the Arduino and it’ll blow up. At best NiMH cells deliver 1.4VDC or 5.6VDC in a four-cell block. Take away that 0.6V diode drop in the DC converter and the highest voltage output you’ll get is 5V flat. As the voltage drops the DC converter kicks in and ensures the output stays at 5VDC and the whole thing runs happily. So just remember NiMH cells only.

 

How to build Stompy

The first step to putting Stompy together is obviously gathering the parts. All up without batteries it shouldn’t cost more than around $80 which is as cheap as you’ll find for a quadruped.

Russell Cameron's Quadbot chassis
The Quadbot chassis developed by Russell Cameron is available for $55.

The Quadbot kit comes with a basic yet functional manual showing how to mount the servo motors onto the leg mounts and the legs onto the chassis. You’ll need a small 3mm Phillips-head screwdriver and to keep track of the screws – they’re quite small.

The toughest part is ensuring that you install the servo motor attachments with the motor in the middle of its travel. Servo motors like this have a 180° turn arc and to make Stompy work properly each motor needs to be mounted so that it’s sitting halfway through its spin arc. You don’t need to be exact (we can fix this with software) but you need to be at least in the same postcode as the middle. Turn the motor with the attachment on but don’t force it – plastic gears are easy to strip.

 

Install the switch & battery pack

In our build the curved end of the Perspex chassis is the rear and there’s a neat 6mm hole in the centre which is just perfect for a SPST toggle switch for the power. The four-AA cell battery holder is just a basic barebones type with two flying leads which you can get from eBay (Jaycar doesn’t stock this one) and we used 3M mounting tape to stick it to the bottom of the Perspex chassis just north of the switch (remember to remove the protective plastic from the Perspex first). The red wire is positive volts while the black is 0V. Solder the red wire to one side of the switch. Next create a short lead using hookup wire solder one end of that to the other side of the switch and connect the other end to the VCC terminal on the Sensor Shield’s terminal block.

Battery holder on Stompy
The four-AA battery holder is attached to the bottom of the chassis with double-sided tape.

 

Installing & wiring the DC converter

The most pressing thing you need to attend to is working out the location of the Arduino and DC converter boards. The Arduino should be in the centre just north of the switch. Looking from the back place the DC converter on the right-hand side as that’s the side the Arduino’s 5V pin is located. You need to solder three short hookup wires to the DC converter: one for the input voltage from the terminal block one for the 0V plane and finally the output voltage; the other end of this wire you carefully solder to the 5VDC pin on the Arduino. Use gold PCB pins on the DC converter to make it easier to solder and unsolder the wires (you can get these from Jaycar).

Stompy's DC converter
The DC converter sits on the right as you look from the rear near the Arduino’s 5V pin.

Since most budget Arduino Uno boards use DIP (dual in-line package) ATMEGA328P chips you’re not soldering onto a surface mount point so it shouldn’t be too difficult to do. Just keep your soldering iron clean pre-tin the wire you’re soldering to that point and it should go like clockwork. If you’re worried you could use a pair of needle-nose pliers to lift the ATMEGA328P chip out of the socket first solder the wire and put the chip back in but that shouldn’t be necessary.

Once you’ve got the wires soldered into place it’s time to mount the boards to the chassis. Again double-sided 3M mounting tape FTW.

 

Installing the ultrasonic sensor

We use the same mechanism here that we used for our Rolly robot. Use double-sided tape on the bottom of the front servo motor the long straight servo attachment and under the two ultrasonic sensors and mount it onto the servo attachment. Four female-to-female Dupont wires are needed to connect the ultrasonic sensor to the UFR01 inputs on the sensor shield. Just follow the wiring table to ensure you get the connection right.

Stompy's ultrasonic sensor head
Stompy’s ultrasonic sensor attaches to the servo motor arm with double-sided tape.

HC-SR04 wiring table

Sensor pin Sensor Shield’s URF01 port pin
Vcc 1 (+)
Trig 2
Echo 3
GND 4

 

Connecting the servo motors

The most complicated task is connecting the servo motor header connectors to the sensor shield board – not because it’s difficult but simply because there are so many and they have to go in the right location otherwise Stompy will look more like he’s crawling out of a pub at 4am. We’re using the main row of connectors on the sensor shield.

Stompy's servo motors
The servo motors plug into the sensor shield (use the table for numbering).

You’ll notice at the end the letters G V and S: G is ground/0V V is Vcc or V+ and S is signal. Basically each servo motor will have three wires: orange red and brown. The brown wire end of the header should go into the ground G side of the header pins. Follow the wiring table to ensure you get the motor connectors into the right pin row.

Servo motor table
Servo motor Short form Shield jumper set
Front-left hip FLH 5
Front-left foot FLF 4
Front-right hip FRH 6
Front-right foot FRF 7
Rear-left hip RLH 9
Rear-left foot RLF 8
Rear-right hip RRH 11
Rear-right foot RRF 10
Neck N 3

 

Connect wires to the terminal block

The big blue/green terminal block on the sensor shield is pretty simple: two screws mash down onto individual metal plates jamming the wires pressed into the openings. Just make sure you tin the wires before inserting them into the block otherwise the thin copper strands will fray and blow away in the wind. We’re cheating a little because we’re using the block to take the battery power as well as the wires feeding the DC converter. You only need to use basic hookup wire for this (check out Jaycar) as the DC converter only needs to supply around 50mA to the Arduino board so there’s no need to make them thicker than that.


This overlay diagram lacks the voltage select jumper but shows where everything else fits.

 

Stompy source code

The source code is a modified version of Russell Cameron’s original release. It was designed for the $40 Dagu Micro Magician microcontroller and an infra-red distance sensor. We’ve modified it to use the standard Arduino Uno board an HC-SR04 ultrasonic sensor added the extra servo motor for the neck and integrated the neck movement into the operation of the bot. We’ll look at installing the code into the Arduino board next time (you can find the code at our Arduino web page at apcmag.com/arduino.htm).

Stompy block diagram
This block diagram shows how Stompy works.

 

Next time

In the second part of this project we’ll look at more troubleshooting. We’ll also show you how to get the code into the Arduino and how you can modify it change the walk speed and give Stompy a personality.