Debugging a Robot


This note is for a Basic STAMP robot, but the same principles apply for an Arduino robot.

Robot doesn't work? Try these ideas. In general. when debugging, isolate, reduce and test one thing at a time. Do not use your main robot code for debugging, but rather write 3-4 line (no more) temporary programs to debug one part of the robot. For example, when a motor doesn't work, write a three line program to turn the motor on for 1 second. When a switch doesn't work, write a two line program that prints the switch state on your PC.

Debug Idea: Gather the proper tools

Debugging tools: Stamp board, programming cable, DMM, extra 22g wire, wire stripper/cutter. A schematic is handy.

 

Debug Idea: Check power supplies

Checking Stamp battery (while plugged in).

Checking Stamp +5V (Vdd).

Not shown, but equally important is checking external batteries that run motors. Check battery voltage while plugged in.

Debug Idea: Check grounding

The ground (minus) of all external batteries must be connected to Stamp board ground (Vss). While the external battery is connected, use your DMM to measure from the battery minus to Vss on the Stamp. Should read zero volts.

Debug Idea: Motor check

Check the wiring. Check the battery voltage. If using a TIP120 for control, check that the emitter (right) pin goes to ground, the collector (center) pin goes to the motor and the base (left) pin goes to the Stamp control pin via a 1K resistor.

Write and run this three line program (assuming the motor is controlled by Stamp pin 1):

high 1
pause 2000
low 1

Did the motor run? If not, run the program while measuring pin 1 voltage as shown below.

Did the voltage change to +5 (or something near) for 2 s? If not, remove the connection from Stamp pin 1 to the 1K resistor, then run the program while measuring the voltage at the Stamp pin as shown below.

Still no change in voltage? It may be a bad Stamp pin. Try another pin. If no pin seems to work, remove all connections from Stamp pins 0-15 and from all the Stamp Vdd, Vin and Vss ports and try again.

If the pin changes voltage but the motor does not run. there is most likely a wiring error. As a quick check, with all batteries connected, short the collector to the emitter as shown below. This connects the motor directly to the battery.

If the motor runs, there either is a wiring error goint to the transistor base or the transistor is bad.

If nothing seems to work, disconnect the motor from the circuit and see if it runs when connected directly to the battery.

Debug Idea: Switch check

This debugging method applies to any kind of switch including push button, toggle, micro and IR light beam. First, check the wiring. One end of the switch goes to ground and the other end goes to +5 V through a 10K resistor. The other end also goes to the Stamp pin.

Write and run this debug program (assuming the switch connects to Stamp pin 4):

L1: debug dec in4
pause 100
goto L1

A stream of 1's and 0's should printed on the PC screen, changing as you open and close the switch as shown below.

Do the 1's and 0's change as you open and close the switch? If not, measure the voltage at the Stamp pin as shown below. As you open and close the switch, the voltage should change between 0 V and 5 V.

If the voltage changes the Stamp pin may be bad. Try another pin. If the voltage does not change there is either a wiring error or a loose connection or a bad switch.

If you suspect the switch is bad, change your DMM to resistance measurement mode. Disconnect all wires from the switch and measure resistance across the two switch terminals.

The resistance should change between 0 (or close to zero) and something very big as you close and open the switch.

Debug Idea: Proceed in stages

If the debug programs work but the robot does not work, build up to your complete robot program in stages. This way you can isolate the error. You can do this either by writing a series of two or three line stub programs or you can comment out all the lines of your main program except the section you want to test.

Debug Idea: Bidirectional motor control with a relay

Check the wiring. Check the battery voltage. Assume the motor on/off control line is connected to Samp pin 1 and direction control line is connected to pin 2. Write and run this program.

high 1
pause 1000
low 1

Did the motor run for 1 s? If not, there is most likely a wiring error or a loose connection. If the motor ran, run this program.

high 2
pause 1000
low 2

Did you hear the relay click? If not, check the wiring to the relay coil. A common problem is attempting to drive a 12 V relay coil from a 9 V battery.

If the motor runs and the relay clicks, run this program.

high 1
pause 1000
low 1
high 2
high 1
pause 1000
low 1
low 2

If the motor runs 1 s in either direction, everything is fine.

If the motor turns the first direction and not the other, there is a chance that a voltage spike at the first "low 1" command is causing the Stamp computer to crash. Try inserting a brief pause between each high and low command, like this.

high 1
pause 1000
low 1
pause 10
high 2
pause 10
high 1
pause 1000
low 1
pause 10
low 2

If noise spikes seem to still be a problem, try soldering a 0.47uF, 100V noise suppression capacitor (see robot store) across the motor terminals. If noise spikes are still a problem, you may have to opto-isolate the motor using the opto-isolators from the robot store and the circuit found in the motor control notes (PDF file).

Debug Idea: Hot transistors

When powering a motor circuit for the fisrt time, pinch the control transistor while motor runs. Warm is OK but too hot to touch is not. A large motor running off a 12 V battery may draw too much current for a TIP120 transistor. The TIP120 has a 2 V drop between collector and emmitter. If the motor draws 1 A of current than the TIP120 must dissipate 2 W as heat.

If the transistor gets hot, but not too hot to touch, adding a heat sink may be enough to keep the transistor cool. You can purchase a heat sink as shown in the photo below, but any thin heat conductor with lots of surface area bolted to the transistor tab will also work. Thin sheets of aluminum are the best, but a small chunk of steel or copper also works. The transistor tab is electrically connected to the collector so be careful that the heat sink does not touch any other part of the circuit or any other heat sink.

Debug Idea: Ask

Don't be afraid to ask. Far better to get advice than to beat your head against the wall for hours and hours trying to chase down a bug.