Silicon ChipThe PICAXE, Pt.5: A Chookhouse Door Controller - June 2003 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Low voltage halogen lamps are huge power wasters
  4. Order Form
  5. Feature: A Look At The 2003 Mars Rovers by Sammy Isreb
  6. Project: The PICAXE, Pt.5: A Chookhouse Door Controller by Stan Swan
  7. Project: PICAXE-Controlled Telephone Intercom by David Lincoln
  8. Project: PICAXE-08 Port Expansion by David Lincoln
  9. Project: Sunset Switch For Security & Garden Lighting by John Clarke
  10. Product Showcase
  11. Project: Test Your Reflexes With A Digital Reaction Timer by Jim Rowe
  12. Project: Adjustable DC-DC Converter For Cars by John Clarke
  13. Project: Long-Range 4-Channel UHF Remote Control by Greg Swain
  14. Vintage Radio: Building A Browning-Drake Replica by Rodney Champness
  15. Weblink
  16. Back Issues
  17. Notes & Errata
  18. Market Centre
  19. Advertising Index
  20. Book Store
  21. Outer Back Cover

This is only a preview of the June 2003 issue of Silicon Chip.

You can view 29 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.

Articles in this series:
  • PICAXE: The New Millennium 555? (February 2003)
  • PICAXE: The New Millennium 555? (February 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
Items relevant to "Sunset Switch For Security & Garden Lighting":
  • Sunset Switch PCB pattern (PDF download) [10106031] (Free)
  • Panel artwork for the Sunset Switch (PDF download) (Free)
Items relevant to "Test Your Reflexes With A Digital Reaction Timer":
  • Reaction Timer PCB pattern (PDF download) [04106031] (Free)
Items relevant to "Adjustable DC-DC Converter For Cars":
  • Adjustable DC/DC Converter for Cars PCB pattern (PDF download) [11106031] (Free)
  • Panel artwork for the Adjustable DC/DC Converter for Cars (PDF download) (Free)

Purchase a printed copy of this issue for $10.00.

MORE FUN WITH THE PICAXE – PART 5 Motors, servos and steppers: A Chookhouse Door Controller by Stan Swan An “eggsotic” barnyard electronics project, just submitted by Simon Goldstone, a rural Queensland reader, uses an “08” to control his chookhouse door for automatic sunset and dawn operation. Naturally several interlock safety features have been added, so chooks are not beheaded (“picaxed” – maybe that’s what it means ?!) or left on the wrong side of the motorised door. The score so far has the “hentertained” chooks now well ahead of the night-prowling foxes. . . I n May we introduced PICAXE control of a small 2-lead DC motor, using “08”-generated PWM to alter spin rate. Without such efficient digital power pulses, speed control would have been wasteful of supplied energy and could even lead to transistor or “pot”(variable resistor) burnout. Although the “08” is obviously a budget microcontroller, often struggling with demanding applications that its big brothers “18A” and “28A” www.siliconchip.com.au more easily tackle, its ability to handle such real world tasks justifies further motor punishment! The “big kid” in most of us naturally means that one of the most entertaining aspects of electronic circuits relates to their control of moving devices. Many of us still maybe glance admiringly as remote control garage doors and the like “do their stuff”, with even perhaps a nod to centuries of engineering developments that yielded such (now) commonplace devices. Engineering often evolves from ingenuity of course! Thus it is with this month’s application. Sick of having his chooks disappearing at the hand (mouth?) of some cunning foxes, our reader devised a way of fitting a motorised door to his henhouse which automatically closed the door at sunset and opened it up again at sunrise – times when the pesky foxes knew that June 2003  13 Again, not so much a project as an example of a PICAXE application, this shot of the chookhouse door shows how the door is raised and lowered (gravity pulling it down). The circuit diagram of the chookhouse door controller. It’s not meant to be a constructional project as such (though it will work!) but more of a source of ideas for you to experiment with. This circuit does not show the usual pin 7 program/run switch nor the pin 2 programming input. rule 0.22 might even things up. We’re not even going to try to describe the door mechanics – that's up to you, even though the photos overleaf show it in some detail – and you may care to add more code to do more things than our farmer did. First, let’s look at some of the types of “motors” you will come across. 1: Small DC motor types We know how easy it is to drive Two of the “motor” types we’re discussing in this issue. The two at left are high-revving, low-voltage DC types, geared down to a usable speed (and to gain extra torque). At right is a disassembled radio-control servo. Note that it too contains a small DC motor inside, along with control circuitry. 14  Silicon Chip a small DC motor with the PICAXE (circuit and code in last month’s issue). Such a motor was used for the chookhouse door (see photos over page). However, typical 2-lead permanent magnet DC motors usually spin at such high speeds (~10,000 RPM) that direct coupling to their rotating shafts is difficult unless gearing is used. Although hobbyist gear sets can give versatility and speeds down to only a few rpm at good torque, friction losses may be crippling unless using more costly units such as Tamiya. Exact positioning needs may be tricky but could use sensors such as LDRs (which can be influenced by stray light/dirt/insects), magnets (activating reed switches or Hall Effect devices), mechanically operated switches, ultrasonics, resistive or even capacitive proximity changes. The choice often relates to reliability. Spin direction control, however, can be as simple as swapping over supply lead polarity, perhaps via DPDT (Double Pole Double Throw) switches and relays. H bridges (named for their “stretched out” rectifier bridge style design, with a motor at the H crossbar) simplify control but cheap motor driver ICs such as the Unitrode L293D streamline even this – as used on the Rev. Ed AXE023 controller board. As they rotate, normal brush and www.siliconchip.com.au BASIC PROGRAM LISTING (This can also be downloaded from http://picaxe.orconhosting.net.nz/chookfox.bas) start: pins = 0 readadc 1 ,b0 if b0 >= 43 then raise if b0 < 43 then lower raise: low 4 high 2 pause 500 low 2 goto up up: readadc 1 ,b0 if b0 < 64 then lower if b0 <= 107 then pre high 0 pause 500 low 0 wait 30 goto up lower: low 2 high 4 pause 500 low 4 goto down down: readadc 1 ,b0 if b0 > 107 then raise if pin3 = 1 then warn if pin3 = 0 then rest goto down warn: for b1 = 1 to 20 high 0 pause 20 low 0 pause 500 next b1 pause 500 goto down pre: high 0 pause 20 low 0 pause 100 high 0 pause 20 low 0 wait 10 goto up rest: sleep 300 goto down ‘reset outputs to low ‘read ldr on pin 1 ‘this value is to kick start the system after ‘initial powerup (ie after battery charging) ‘as above ‘this routine raises the door ‘make sure the lowering output pin 4 is kept low ‘send up command from pin 2 to latching relay via up transistor ‘hold high for .5 seconds ‘send pin 2 low. Relay will have latched. ‘once door has been commanded to raise move on ‘monitoring routine of opened door ‘monitors open door and waits for pre close command ’64 is the value of the door closing command ‘this value is included to give a visual warning ‘via the LED on output 0 that door closure is approaching. ‘this is a monitor function to indicate the system is active ‘this routine lowers the door ‘ensures the raise output is kept low ‘send down command from pin 4 ‘hold pin 4 high for .5 seconds ‘return pin 4 low. relay will have latched commutator DC motors often generate appalling electrical noise which needs filtering via capacitors across the motor terminals. Without this a PICAXE may be so confused with the “hash” that it ceases responding. Separate power supplies, needed of course on more powerful systems drawing many amps, help reduce hash too. 2: 3-lead RC servos RC stands for Remote or Radio Control. Servos are very commonly used for radio controlled model aircraft and boats still contain a small DC motor. But they also have a precision gearbox, control electronics and a variable resistance (potentiometer) inside. The pot acts as a feedback device for the internal circuitry to inform of external shaft rotation angle before it “holds”. Control is by a single wire pulse width – an easy task for a PICAXE. Just as easy is the code to achieve the right pulse width. By convention, 1.5ms-wide pulses (1500µs), with 20ms pauses between, set the servo shaft to its centre, or ‘this routine monitors the door once it is down ‘commands raise routine when enough light available ‘pin 3 monitors the down microswitch. A visual ‘output on pin 0 alerts that door is not closedwhen dark ‘this line added to avoid recurring problems with ‘false triggering during darkness ‘this routine is the warning output from pin 0 ‘sets no. of flashes of LED ‘keep pin 0 high for .02 seconds ‘keep pin 0 low for .5 seconds ‘wait .5 seconds ‘this routine added to give a visual aid so one can see that the ‘system is armed for closing just before dark.Very useful ‘keep pin 0 high for 20 milliseconds ‘keep pin 0 low for .1 seconds ‘wait 10 seconds ‘the rest sequence to conserve power but mainly to stop ‘false triggering during darkness which can cause the ‘door to get spurious up commands www.siliconchip.com.au June 2003  15 H-bridge circuit operation. It looks somewhat like a “bridge” rectifier with the DC motor across the junction (of transistors in this case). The motor can be run in either direction by turning on the appropriate pairs of transistors. Turning on Q1 and Q4 makes motor current flow from +ve to -ve, rotating the motor one way, while turning on Q2 and Q3 reverses the motor current flow, also reversing the rotation. neutral, position. We use both those terms, pulse and pause, deliberately, for reasons you’ll see shortly. Pulse width variations down to 1ms turn the servo shaft in the left direction (the exact position depending on the exact pulse width). Similarly, pulse widths between 1.5ms and 2ms turn the shaft in the right direction. In the absence of any further change of pulse width, the servo holds position with good torque – the action (and sound!) is akin to aircraft flaps being extended. “Pulsout” and “Pause” The PICAXE’s “pulsout” command can give us the exact pulse length required – remember (from our March foray into PICAXE ADC) that they can be timed to microseconds – and the pause command can give us the required spacing between the pulses. Aha! Pulse and Another view inside a servo, this time from the underside. You can just see some of the control electronics under the PC board. Pause – where have we heard that before? Connecting a servo Simply connect the servo’s white control wire straight to the PICAXE-08’s output 2. The red (+) and black servo power leads, conveniently 4.8V at modest currents, need the usual back- Driving servos and steppers with the PICAXE-08 Testing a stepper here is remarkably similar to our earlier solar motor set up (last month’s issue) but with duplicated 4.7kΩ and BC547s on I/O output 1 (IC pin 6) to give two active output pins. The PICAXE-08, which is only able to source (supply) ~20mA at each output, has insufficient stepper drive capability alone of course. Here’s the testing code … A garden-variety servo (the budget DSE P-9061 – apparently generic with Futaba/Hitec, etc servos) connected to the PICNIK box for testing. The servo white (data) wire connects directly to the PICAXE I/O channel 2 (pin 5) while (red and black) power connects to the 5V lines. Note the capacitor and diode across the servo power. Here’s some PICAXE code to try it out: loop: for b1= 1 to 30: pulsout 2,100: pause 20: next b1: wait 1 ‘ 1mS pulses = L for b1= 1 to 30: pulsout 2,150: pause 20: next b1: wait 1 ‘ 1.5mS pulses =Neutral for b1= 1 to 30 :pulsout 2,200 :pause 20 : next b1: wait 1 ‘ 2mS pulses = R goto loop 16  Silicon Chip ‘code snippet to exercise Jaycar YM2752 Bipolar 4 wire Stepper with PICAXE-08 ‘motor just ”rocks” since H-bridge or translator IC etc needed for full spin ‘Runs OK on 4.5V although stepper rated 7.5V 250mA. Use small signal BC547 ‘Alter pulse periods and pause durations for different effects. Ref. article & pix too stepdemo: for b0 = 0 to 10 pulsout 1,5000:pause 500 pause 20 pulsout 2,5000:pause 500 pause 20 next b0 ‘ pulse loop ‘ Pin 1 5000 microsec pulse (= 5mS) ‘ Brief pause 20mS ‘ Pin 2 5000 microsec pulse (= 5mS) ‘ Brief pause 20mS ‘ repeat until completed www.siliconchip.com.au It’s quite easy to work out the various coil connections in a stepper motor because they are all isolated from each other. A fairly low resistance indicates a coil. Working out the start and finish of each coil is a little more difficult – the easiest way is to pulse each coil in turn and note the way the shaft turns. From this you can work out coil polarity. References and parts suppliers . . . 1. “Practical Electronics for Inventors” Paul Scherz – McGraw-Hill 2000 (DSE B1636). Much in the “Robot Builders Bonanza” style, but with superb general electronics insights and exquisite line drawings. 2. “Easy Step’n – An Introduction to Stepper Motors” David Benson – Square1Electronics www.stepperstuff.com (Jaycar BS1504). Costly but perhaps the definitive work. 3. Jaycar – 3 Volt gear and hobby motor sets (YG2730 etc), 12V DC latching relay (SY4060), limit switches (SM1308), LDR (RD3480), plus low power 4- wire stepper (YM2752 ~$15) 4. Dick Smith – general purpose RC Servo (P9061 ~$20), 3 Volt Tamiya motorised gear sets (P9057 or P9051 ~$15) and sundry parts. 5. www.cs.pitt.edu/FORTS/jim/stepmtr. htm – stepper motor animations!! 6. www.doc.ic.ac.uk/~ih/doc/stepper/ – links detailing PC disk drive steppers 7. www.nutsvolts.com – Bulletin Board for US “Nuts & Volts” monthly mag. 8. www.picaxe.co.uk Revolution Education – Forum pages especially 9. www.picaxe.com.au or www. microzed.com.au – MicroZed (official Australian agents) 10: www.technologicalarts.com/myfiles/data/L297D.pdf – L297D data sheets 11: www.picaxe.orconhosting.net.nz – author’s enthusiastic web site with many links. EMF diode and good sized (220nF?) hash-taming capacitor across them. For “getting your feet wet” with PICAXE-controlled motors, these servos look near ideal. Recommended! 3: Stepper Motors Stepper Motors, although today’s electronic workhorses, contrast with servos in their demanding external drive circuitry – they’re certainly not www.siliconchip.com.au WYSIWYG. You’ve only got to look at the “simple” stepper on Fisher and Paykel “smart washers”, then check their attached swag of drive electronics to see this! Steppers are digitally-controlled brushless motors (you can feel them “cog” when spun with your fingers) that rotate a small “step”(often 7.5o) as each clock pulse is applied via external circuitry. There are many types, with 8, 6, 5, or 4 leads – universal, unipolar and bipolar – the latter 4-wire types being cheapest but trickiest to drive. A good source of stepper motors for hobbyist experimentation is old PC disk drives. (Modern drives tend to use voice coil actuation, not steppers). All steppers tend to be power hungry and often run off higher voltages (eg, 12V on PC disk drive types), so straight control from a 4.5V PICNIK box looks dicey. However, there are 5V steppers available. They have no internal electronics – just coil pairs – so identification of the coils with a multimeter on Ohms is relatively easy when working out where all the wires go! Controller ICs abound – especially the Allegro UCN5804 Stepper Motor Translator and SGS-Thompson’s L297D Bipolar Translator. These greatly reduce the cost, bulk and inconvenience of discrete devices. For a PICAXE insight however, near direct connection with a cheap bipolar model (Jaycar YM2752 – actually a Berger Lahr RDM37/6G = Reversible Digital Motor 37mm diam/6-pole) proved possible. The unit is only “exercised” here and doesn’t spin, since pole pairs need alternating supply voltages and polarities for rotation. This diagram of a bipolar stepper (after “Practical Electronics for Inventors” [Scherz]) illustrates how the windings are connected together to achieve rotation. It is up to the drive circuitry to energise the coils at the right moment. If you’re determined to spin those wheels with this budget low power unit, it’s suggested the cheap, specialised driver ICs be used, although I’ll be delighted to hear of any “straight 8” workarounds! And don’t forget to feed those chooks! Hey, maybe a PICAXE-controlled chook feader could be next . . . SC NEXT MONTH: PICAXE data communications (with a new use for damp string!) These “08”s can also reach out, With datacomms part of their clout, They’ll even “swap notes”, Almost ANN (*refer quotes), To yield more applications – no doubt ! * ANN =“Artificial Neural Networks”. Communication networks that link much as do neurons in biological nervous systems. June 2003  17