Silicon ChipBuild A Programmable Robot - September 2004 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: High voltage warnings err on the side of caution
  4. Feature: Voice Over IP (VoIP) For Beginners by Ross Tester
  5. Feature: WiFry: Cooking Up 2.4GHz Antennas by Stan Swan
  6. Project: Bed Wetting Alert Sounder For Toddlers by John Clarke
  7. Project: You’ve Had Your Fun – Now Make A Doorbell by John Clarke
  8. Project: PICAXE The Red-Nosed Reindeer by Clive Seager
  9. Project: Build A Programmable Robot by Thomas Scarborough
  10. Project: Oh No! Not Another CFL Inverter by Design by Branko Justic, words by Stephen David
  11. Vintage Radio: This Little Nipper was a dog by Rodney Champness
  12. Back Issues
  13. Advertising Index
  14. Outer Back Cover

This is only a preview of the September 2004 issue of Silicon Chip.

You can view 16 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Bed Wetting Alert Sounder For Toddlers":
  • Bed Wetting Alert PCB patterns (PDF download) [15109041/2] (Free)
Items relevant to "You’ve Had Your Fun – Now Make A Doorbell":
  • Doorbell Sounder PCB pattern (PDF download) [15109043] (Free)
Items relevant to "PICAXE The Red-Nosed Reindeer":
  • PICAXE-08 BASIC source code for the Red-nosed Reindeer (Software, Free)
Items relevant to "Build A Programmable Robot":
  • PICAXE-08 BASIC source code for the Programmable Robot (Software, Free)
  • Programmable Robot PCB pattern (PDF download) [07209041] (Free)

Purchase a printed copy of this issue for $10.00.

Programmable ROBOT This Programmable Robot features full manoeuvrability – forward, reverse, turn and stop, with pulse-width modulation for speed control. It also sports bump-and-respond, random motion, programmable sound, light sensing (16 levels) and EEPROM byte-wise addressing. By THOMAS SCARBOROUGH T HIS CIRCUIT lets you design your own robot to suit your own taste. It would not be difficult, for instance, to convert this design to a credible R2D2, without any modification to the PC board. With a little imagination, the possibilities would be even wider. The circuit could operate a pulley system, serve as a line-tracker or rotate motors in response to broken beams of varying intensity, without modification to the PC board. As noted, the robot is programmable. Therefore, the drive circuit is merely a slave to the software and is of a relatively simple design. The circuit is based on a PICAXE-08 micro, as has been featured previously in SILICON CHIP. Although more limited than a “raw” microcontroller, it is a small marvel nonetheless – both for cutting out the need for a costly programmer and for placing respectable power at the service of the constructor with great simplicity. All that the Programmable Robot requires in its support is a PC and a serial cable. The programming software is free (www.rev-ed.co.uk) and comes in the form of a telegram-style BASIC and flowchart programming. Note that the Programmable Robot’s memory is limited – not all the features listed above can be used at the same time. However, with careful programming, the robot will perform most dual or even triple tasks with aplomb. As an example, light-seeking, bump-andrespond and sound can all be incorporated in a single program. Table 1: PICAXE Motor Control Outputs Pin 7 (P0) Pin 5 (P2) Pin 3 (P4) High Low Both motors on Left motor backwards Right motor backwards Both motors off Left motor forwards Right motor forwards 64  Silicon Chip This table shows the most important PICAXE-08 outputs – ie, for motor control. Since the PICAXE-08 microcontroller represents the Programmable Robot’s “control room”, this is where we shall begin. Unfortunately, the PICAXE-08 is confusing in its pin numbering, which has become something of a legend in its own time – therefore we shall resort to the standard IC pin numbering here; ie, pins 1-8, with pin 1 being situated next to the small indentation on top of the IC. Circuit details The complete circuit is shown in Fig.1. The PICAXE-08’s pin 1 (+V) and pin 8 (0V) are connected to a 6V battery via switch S2 and diode D2. D2 serves a dual purpose – firstly, to prevent reverse polarity, which could do considerable damage, and secondly, to drop the supply voltage to about 5.4V, which is more suitable for the PICAXE-08. Pin 7 (P0) is designated by the manufacturers for output only and is used to switch both of the motors on or off at the same time. It may also be used to pulse the motors on and off (pulse-width modulation) for speed control or special effects. When it is “high”, the motors are on; when it is “low” they are off. siliconchip.com.au Pin 5 (P2) is designated for input or output. In this circuit, it is used for output only and controls the direction (forward or reverse) of the lefthand motor, as seen from the rear of the robot. Pin 3 (P4) is likewise designated for input or output and is used here to control the direction (forward or reverse) of the righthand motor. Note that neither pin 5 nor pin 3 will accomplish anything unless both motors are switched on first via pin 7 (P0). Both pins 5 and 3 cause a wheel to roll forwards when it is “low” and backwards when it is “high”. Pins 7, 5 and 3 together may be used not only to make the robot drive forwards or reverse but also to turn, gyrate, wiggle, judder or do virtually anything else one may think of! These motions may also be strung together sequentially, as part of a programmed sequence (within limits, since memory is at a premium). Pin 4 (P3) is designated for input only and is used to sense collisions through the Programmable Robot’s bumper bar. The robot need not only do a simple reverse-and-turn but may be programmed to respond in various ways. Pin 6 (P1) is designated for output, input or analog input. In this circuit, it is used only for output and analog input. In “output” mode, it is used to drive a piezo sounder for programmable sound. The piezo sounder will beep, play tunes or with a little ingenuity, create sound effects such as a police siren or a cat’s purr. In “analog” mode, pin 6 reads the light level at the front of the robot. Note that this first requires the correct adjustment of VR1 with the help of the LDR ADJUST program. The robot is capable of detecting sixteen levels of light which may be used for light-seeking (or light-avoidance), line tracking and day-night sensing. Several short programs are provided, including a FIGURE-8 DEMO, LIGHT & BUMP DEMO, PWM DEMO, RANDOM DEMO and WALTZING MATILDA DEMO. The WALTZING MATILDA DEMO Fig.1: a PICAXE-08 microcontroller, 10 MOSFETs and not much else comprise the circuit of this robot. All the intelligence is contained in the micro’s software. siliconchip.com.au September 2004  65 Fig.2: follow this parts layout diagram when assembling the PC board. has been designed not only for fun but as a “get you going” program during assembly, while the LIGHT & BUMP DEMO will give the best overall functionality. This seeks out light and drives towards it, reverses and turns away from obstacles, as well as having sound. For the sake of clarity, the most important PICAXE-08 outputs are listed in Table 1. Pin 7 (P0) activates both motors simultaneously via MOSFETs Q2 & Q5. These two MOSFETs are wired in parallel and these should work satisfactorily with a small heatsink for the small motors used here. While D2 can cope with two 9W motors, the prototype’s motors used about 1.6W each under load. If the drain on the battery is too Fig.3: this is the full-size etching pattern for the PC board heavy when the motors are switched on, this could lead to a voltage drop which could make the PICAXE-08 do strange things. Therefore, the battery should be suitably rated for powering the motors. The prototype used a 6V 4Ah battery. AA batteries in series are unlikely to be adequate, except for the most lightweight of motors. Pin 6 (P1), used in “output” mode, drives piezo sounder X1. Since VR1 and LDR1 are connected to the same pin, 330Ω resistors are included as protection for these components. In analog mode, pin 6 monitors LDR1 and the PICAXE-08 interprets the voltage as 16 discrete levels, between <0.22V (level 1) and >3.38V (level 16). Ideally, the darkest areas of a room should read about 3.6V at pin 6. This can be arranged by means of the LDR ADJUST program (see below). A value of 10kΩ for VR1 should prove suitable if the specified NORP12 Light Dependent Resistor (LDR1) is used. Virtually any other LDR may be used but the value of VR1 may need to be modified to match, in order to provide a voltage of about 3.6V at pin 6 when surveying the darkest areas of a room. If the resistance of the LDR in darkness is known, VR1 should be adjusted to roughly 70% of this. It might be asked what use a single LDR is, since it would seem that two LDRs would be required to compare light level from different directions. However, since LDR1 is mounted on a moving platform, light levels from different areas can be compared over time. Thus the robot measures light level in one part of the room, stores Table 2: Resistor Colour Codes o o o o o No.   3   4   1   2 66  Silicon Chip Value 47kΩ 22kΩ 10kΩ 330Ω 4-Band Code (1%) yellow violet orange brown red red orange brown brown black orange brown orange orange brown brown 5-Band Code (1%) yellow violet black red brown red red black red brown brown black black red brown orange orange black black brown siliconchip.com.au Parts List The completed PC board is secured to the base using machine screws and nuts. Note the heatsink that’s fitted to the tabs of MOSFETs Q2 & Q5. it, then turns to measure light level in another part of the room. The different light levels can then be compared and the robot can respond accordingly. Pins 3 & 5 switch two power Mosfet H-bridges (Q3, Q4 and Q9,Q10) to control the direction of the motors (forward or reverse). The two 100nF capacitors and diode D1 are included to suppress interference. Transistors Q1 and Q8 are used as inverters, so that when the “forward motion” MOSFETs are disabled, the “reverse motion” MOSFETs are activated. Pin 4 is normally held low by its 47kΩ resistor. When bump-andrespond switch S1 (the bumper bar) is closed, pin 4 is pulled high. The 10µF capacitor and the 47kΩ resistor determine how long a bump will be “remembered” and the values of these components may be modified as desired. These components are required because the software, as it executes, may need a moment to reach the program line which monitors the status of S1 – and because there is bound to be some switch-bounce, too. Pins 2 (Serial In) and 7 (Serial Out) are used for downloading programs, with pin 7 doing double duty for switching the motors, as described above. Since pin 7 does double duty, the robot’s motors may twitch a little as a program is downloaded or debugged. A 220µF capacitor provides supply decoupling and the 22kΩ bleed resissiliconchip.com.au tor ensures that the circuit powers down properly when switched off, so that there will be no unpredictable behaviour when it is switched on again. After switching off the robot, allow a few seconds for the 220µF capacitor to discharge before switching on again. PC board assembly All the parts, with the exception of the bump switch, LDR, piezo sounder and battery, are mounted on a PC board coded 07209041, measuring 92 x 67mm. The component overlay is shown in Fig.2 and the wiring details in Fig.6. PC board and hardware construction are inter-linked and both of these sections need to be read first before final construction of the robot is undertaken. The following procedure is recommended when soldering components to the PC board: (1) solder the 14 PC pins (insert these from the copper track side), as well as the wire links; (2) solder the 8-pin dual-in-line (DIP) socket (observe the correct orientation) and CON1; (3) solder the 10 resistors and preset potentiometer VR1; (4) install the two diodes and the two electrolytic capacitors, taking care with polarity; (5) install the two 100nF capacitors; (6) solder in the two transistors (Q1 & Q8) and the 10 MOSFETs; (7) fit a small heatsink to MOSFETs Q2 & Q5. Robot platform The physical construction of the 1 Masonite baseboard, 200 x 160mm 1 PC board, code 07209041, 92 x 67mm 1 piezo sounder (without integral electronics) (X1) 1 bumper switch (S1 – see text) 1 miniature toggle switch (S2) 1 10kΩ trimpot 1 NORP-12 light dependent resistor (LDR1 – see text) 1 3.5mm PC-mount stereo jack socket (CON1) 2 reversible 6V geared motors (ideally <2W each under load) 1 8-pin DIP socket 1 6V 4A.h SLA battery 2 spade connectors to suit battery 14 PC stakes 2 60mm wheels (to suit gearbox shafts) 1 40mm rear wheel 130mm 2.5mm steel wire for rear wheels 4 corner brackets for battery Semiconductors 1 PICAXE-08 microcontroller (IC1) 10 MTP3055V N-channel MOSFETs (Q2-Q7,Q9-Q12) 2 BC547 NPN transistors (Q1,Q8) 1 1N4004 silicon diode (D1) 1 1N5404 silicon diode (D2) Capacitors 1 220µF 16V PC electrolytic 1 10µF 16V PC electrolytic 2 100nF (0.1µF) MKT polyester or ceramic Resistors (0.25W, 1%) 3 47kΩ 1 10kΩ 4 22kΩ 2 330Ω Also required PICAXE Programming Editor software – available free from www.picaxe.co.uk PICAXE download cable (Part No. AXE026) – available from MicroZed 02 6772 2777; see www.microzed.com.au Programmable Robot begins with a suitable baseboard to which everything else is attached. The prototype’s baseboard measured 200mm from September 2004  67 Fig.4: a swivel wheel is used at the rear of the robot for simplicity of steering. front to back and 160mm wide. I used Masonite, a strong material that is easy to work with. Two reversible 6V DC geared motors with “through-shafts” were bolted to the baseboard. The platform of the prototype was raised a little above the motors with 10mm square wood dowels, to provide more vertical room for the rear swivel-wheel. The motors I purchased use about 250mA under load and at 6V run free at about 6000 RPM. I divided this down to 70 RPM with the gearbox and this comes down to perhaps 50 RPM under load, when the voltage drop via D2 is taken into account. 60mm diameter gear wheels were used for the two drive wheels and these could simply be pressed onto the drive shafts. The motors are mounted so that they each “face the same way” 68  Silicon Chip as they turn – that is, their drive shafts both turn the same way when the robot is moving forward. This is because there may be inequalities in the forward and reverse speeds of DC motors and this ensures that the robot will drive in a reasonably straight line when the motors are activated. Next, attach leads with spade connectors to suit the battery and connect the motors as well. That done, attach LDR1 at the front of the robot by means of suitable wires. A short tube over LDR1 is required for directionality (see below). You also need to attach bumpand-respond switch S1 (ie, the bumper bar – see below), the piezo sounder and switch S2 using suitable leads. Finally, insert the PICAXE (IC1) in the DIP socket. Once the assembly is complete, carefully check the PC board for any Fig.5: this diagram shows the details of the collision switch. solder bridges or dry joints, and check all components for correct placement and orientation. More construction detail The easiest way of working out the correct mounting of the motors will be through trial and error. First, wire them both up as shown, observing the correct polarity of the motors. That done, run the WALTZING-MATILDA DEMO. Immediately after the first line of “Waltzing Matilda”, the wheels should both roll so as to propel the robot forwards – then there should be a beep and only the left motor (viewed from the rear of the robot) should reverse. If the motors do not rotate as described, then re-orientate them so that they do. Once the drive motors have been fassiliconchip.com.au tened into place, the battery should be mounted on top of the platform – slightly back from the two drive shafts, so that the robot’s load is slightly to the rear of the platform. This gives it a good weight distribution and gives traction to the drive wheels, while not overburdening the rear swivel-wheel. Four corner brackets were used to hold the battery in place and a length of telephone wire (or a cable tie) can be used to tie it to the platform through drilled holes. The prototype used a rear swivel-wheel, and a 40mm diameter gear wheel was used for the wheel. A sturdy 130mm length of 2.5mm dia-meter steel wire, together with a metal bracket, was used to attach the wheel to the platform. Nuts were slipped over this wire and glued into place as shown, to hold the wire in the bracket, and to hold the wheel in place. It is important that this wheel should touch the ground at a point central to the other two wheels, otherwise the robot is likely to have a “lean” to it, and this is why the steel wire is curved as it is. Together with the other wheels, the swivel-wheel should also, at all times, provide a three-point base on which the robot may rest, so as not to tip over. Make sure that the swivel-wheel has the freedom to swivel through 360°. It should not, for instance, bump into the motors or the on-off switch, or be impeded by drooping wires. This robot has the potential for “wild” motion and could run into trouble if the swivel-wheel snags. Mounting the PC board The PC board is mounted on top of the platform at the back, behind the battery, with the jack socket facing the rear for easy insertion of the serial cable. For neatness, holes may be drilled in the platform beneath the PC board, so that sheathed wires may be run underneath the platform. In the prototype, the PC board was raised above the platform on bolts, which made the wiring easier, as well as making room for the piezo sounder and the screws used to secure the swivel-wheel assembly. A simple bumper bar is fixed to the front of the robot for the bumper switch S1. All that is required here is that S1’s contacts should close on collision. The siliconchip.com.au This underside view shows how the motor/gearbox assemblies are secured to two wooden rails using machine screws and nuts. Note also the rear swivel-wheel assembly. prototype used a brass strip that was “sprung” on two brass loops, making contact with a brass stub on the platform when a collision took place. Finally, switch S2, piezo sounder X1, and LDR1 are connected to the PC board. Switch S2 may be mounted on the hardboard platform. The piezo sounder may be fixed underneath the PC board with a little glue. A short tube (say 15mm in length) should be slipped over the LDR and this should be mounted on the front of the robot with a clear view in front. Without this “blinker” tube, the LDR does not have sufficient directionality to be of much use. Once the circuit is complete, piezo sounder X1 presents a quick and easy way of testing for life in the circuit. Using the WALTZING-MATILDA DEMO, only the piezo sounder and battery need to be wired up at first. Switch on the circuit, being vigilant for any sparks or abnormal heating! If the slightest problem should be sus- This close-up view shows how the LDR is housed in a short (15mm) length of tube. It sits just behind the collision switch. September 2004  69 Fig.6: follow this diagram to complete the wiring for the Robot. Power comes from a 6V 4Ah sealed lead acid battery which is mounted just behind the front axle assembly pected, switch off immediately and thoroughly re-check the PC board. Program the PICAXE-08 by means of the serial cable. This is done by opening the WALTZING-MATILDA DEMO file and then pressing F5. If the motors have been attached at this stage, the robot will wiggle briefly – then the first line of “Waltzing Matilda” will play, and the robot will drive forwards. Then it will turn and repeat the sequence. If the motors have not yet been attached, the sound of “Waltzing Matilda” will give confirmation that a good deal is already working well – the programming system, the serial cable, the PICAXE-08 IC and some of the surrounding components at the very least. To adjust the PICAXE-08 to the surrounding light level, run the LDR ADJUST program, and keep the serial cable connected while you do so. Adjust VR1 and as you do so, observe variable b3 on your computer screen. When the robot is aimed at the darkest areas of the room, b3 should read 160, while lighter areas should show lesser numbers. What is most important is that there should be maximum variation in this number (b3) as the robot surveys different areas of a room. Turning it loose! The PC board is elevated on its mounting bolts to allow the wiring to the motors, etc to pass through holes drilled through the baseboard beneath it. 70  Silicon Chip Once complete, place the Programmable Robot on a hard floor and switch on. All being well, it will wiggle, then follow the rest of its programmed behaviour. The best “general purpose” program is the LIGHT & BUMP DEMO. Place a lamp on the floor, switch off any other lights, and then switch on the robot – facing any direction at all. This demo never fails to impress, with the Programmable Robot heading for the SC light like a moth to the flame. siliconchip.com.au