11
PICAXE PIC1
2014 Amherst Railroad2014 Amherst RailroadHobby ShowHobby Show
Dave BodnarDave Bodnar
January 23, 2014January 23, 2014
Amherst, MAAmherst, MA
Electronics, Microcontrollers & Trains
Electronic Gizmos, Gadgets, Tips, Tricks & More!
This presentation isavailable on-line at:
www.trainelectronics.com or www.davebodnar.com
Revised 01-20-14
22
PICAXE PIC2
ObjectivesObjectives• Demonstrate various devices & projects that
utilize microcontroller operation …
• … and lots of tips & tricks and other things that do not!
• (Hopefully) Excite you with the possibilities and
enable you to begin experimenting and enhancing your railroad!
33
PICAXE PIC3
Topics to be CoveredTopics to be CoveredPart 1Part 1
• PICAXE overview – What is it? Why use it? How do we use it?
• Build & program a number of PICAXE projects
• Explore a sprinkling of Tips, Tricks, Tools and new & improved gizmos & gadgets
44
PICAXE PIC4
Topics to be CoveredTopics to be CoveredPart 2Part 2
• Animations & other PICAXE based projects
• …More Tips, Tricks, Tools
• …More new & improved gizmos & gadgets
55
PICAXE PIC5
Working Hypothesis 1Working Hypothesis 1
We all have an interest in how things work and We all have an interest in how things work and many of us have enough knowledge of basic many of us have enough knowledge of basic electronics to know that something can be electronics to know that something can be done…done…
we just need a bit of help putting all of the parts we just need a bit of help putting all of the parts together to make it happen!together to make it happen!
66
PICAXE PIC6
Working Hypothesis 2Working Hypothesis 2We already know about & have experience with
many of these things:• Batteries & power supplies• Track wiring & motors• AC, DC, voltage, amperage & resistance• LEDs & incandescent bulbs • Series & parallel circuits• Switches, relays & transistors• Simple Programming
77
PICAXE PIC7
Working Hypothesis 3Working Hypothesis 3
Inexpensive microcontrollers allow us to leverage the basic electronics and programming knowledge that we have so that we can do some amazing
(and personally satisfying)
things!
88
PICAXE PIC8
PICAXEPICAXE
• What can it do?– Intelligently control &
automate many aspects of operating your railroad
– Operate lights, motors, animations and other electrically powered devices
99
PICAXE PIC9
PICAXEPICAXE
• Best choice in terms of:– Capability– Ease of use– Size– Cost– Support
• [email protected]• Many PICAXE articles www.trainelectronics.com • Several Books available on Amazon – Search for PICAXE
1010
PICAXE PIC10
PICAXE - What You NeedPICAXE - What You Need1. Windows computer with
serial port or …
USB to serial adapter or …
USB programming cable
2. Windows computer running free PICAXE software
3. Power source– 3 @ AA cells = 4.5 volts
– Note:AxePad software is available for Mac & Linux computers – fewer features than PC software
1111
PICAXE PIC11
TipTip
USB to Serial Adapter
Spark Fun sells PICAXE cable – part # PGM-08312 for about $26.00
Or
Spark Fun’s USB to Serial – part # PGM-09260 for about $15.00
Details on use at www.trainelectronics.com
1212
PICAXE PIC12
TipTip
• Peter Anderson (PHAnderson.com) has PICAXE chips & accessories
• Amazon & eBay – search for PICAXE
• SparkFun.com
1313
PICAXE PIC13
First Project:First Project:Flashing Crossing LightsFlashing Crossing Lights
• Design objectives:• Alternately flash two red LEDs • Operate from battery power• Alter timing and other characteristics from
software
1414
PICAXE PIC14
First Project:First Project:Flashing Crossing LightsFlashing Crossing Lights
• Then we will modify the circuit to:• Start from a button push• Do other “flashing” things by making minor
changes in hardware & software
1515
PICAXE PIC15
Tip - Testing LEDsTip - Testing LEDs
• Just about any LED can be tested with a 3 volt lithium battery 2032, 2025, etc
• Touch the anode (longer wire) to the “+” side of the battery
• Touch the cathode (wire by notch in LED)
to the “-” side
White LEDs are OK for long use at 3+ volts, Red, Green, Amber are not
A great use for old watch batteries!
1616
PICAXE PIC16
LED InformationLED Information
• LED Related Articles:– A Simple Constant Brightness LED – LEDs 101 - Introduction & Overview – LEDs 102 - Using them Onboard Trains – LEDs 103 - Turning them On and Off – LEDs 104 - A Better Constant Brightness
Circuit for LEDs
1717
PICAXE PIC17
Flashing Crossing LightsFlashing Crossing Lights
Parts:Cost:
Less than
$10.00
1818
PICAXE PIC18
Flashing Crossing LightsFlashing Crossing LightsSoftware: free from www.picaxe.com
1919
PICAXE PIC19
Flashing Crossing LightsFlashing Crossing Lights
Our wiring plan is in the form of a schematic - a drawings of what we need to build and how it is wired togetherRemember: Don’t use a 9 volt battery
or 4 fresh 1.5 volt AA cells!
5.5 volts maximum!
2020
PICAXE PIC20
Not sure about…???Not sure about…???
• A resistor’s value…
• Or a battery’s voltage…
• Or if a wire is broken…
• There is a tool for that!
2121
PICAXE PIC21
I was blind and now I see…I was blind and now I see…
• Volt / Ohm Meters are right up there with indoor plumbing.
• Less than $10.00
• Sometimes free
• Use two to give both volts & amps
•See Trainelectronics.com for details
2222
PICAXE PIC22
Tip – Tiny Volt MeterTip – Tiny Volt Meter• Powered from voltage
being measured – 4 to 30 volts
• Approx 1” x ½” x ½”• Search eBay for:
“Ultra Mini size LED Volt Meter”
• $5.99 (or less) + $0.00 shipping
2323
PICAXE PIC23
Tip – Step Down Voltage ConverterTip – Step Down Voltage Converter
• Suntekstore.com • < $8 shipped – some times on sale for less• http://www.suntekstore.com/goods-14007039-adjustable_step-down
_dc-dc_power_module_with_voltmeter_display.html
• Up to 2 amps without heat sink
• Includes digital meter!
• Adjust voltage withscrewdriver
2424
PICAXE PIC24
Tip – Step Down Voltage ConverterTip – Step Down Voltage Converter
• Can easily be modified to use a larger potentiometer
• Inexpensive speed control for a small layout
2525
PICAXE PIC25
Flashing Crossing LightsFlashing Crossing Lights
Radio Shack board # 276-002 $15.00
2626
PICAXE PIC26
Flashing Crossing LightsFlashing Crossing Lights
2727
PICAXE PIC27
Flashing Crossing LightsFlashing Crossing Lights
Program 1:
Notes:– “start” is just a label telling the “goto” where to go– the program remains in the chip’s memory until it is
manually erased or overwritten.
high 1 ‘turn on LED 1 - pin out1low 2 ‘turn off LED 2 - pin out2
start: pause 500 ‘wait ½ second toggle 1 ‘switch LED 1 on pin out1 toggle 2 ‘switch LED 2 on pin out2goto start: ‘do it again
2828
PICAXE PIC28
Flashing Crossing LightsFlashing Crossing LightsProgram 2: modified to flash for 10 seconds and turn
off for 10
seconds
start:high 1 ‘turn on LED 1low 2 ‘turn off LED 2
For b0=1 to 20 ‘repeat 20 times pause 500 ‘wait ½ second toggle 1 ‘switch LED 1 toggle 2 ‘switch LED 2next b0 ‘back to looplow 1 ‘turn LED 1 offlow 2 ‘turn LED 2 offpause 10000 ‘stay here 10 secondsgoto start: ‘do it again
2929
PICAXE PIC29
Flashing Crossing LightsFlashing Crossing Lights
• Program simulation is built in!• You can write and test programs without any
hardware…• Give it a try tonight!
3030
PICAXE PIC30
Flashing Crossing LightsFlashing Crossing LightsHardware modification for button or reed switch
activation:
3131
PICAXE PIC31
Flashing Crossing LightsFlashing Crossing LightsProgram 3: modified to flash 5 seconds on each
button push start:low 1 ‘turn off LED 1low 2 ‘turn off LED 2if pin3 = 1 then start: ‘if switch off go to top
flash: high 1 ‘LED 1 on low 2 ‘LED 2 offfor b0= 1 to 10 ‘do this 10 times pause 500 ‘wait ½ second toggle 1:toggle 2 ‘switch lights next b0 ‘do next of 5 loopsgoto start: ‘start from very top
3232
PICAXE PIC32
Two Sensors for CrossingTwo Sensors for Crossing• Add a second sensor so that the light goes
on when it passes one sensor…
• And goes off when it hits the other sensor.
Sensor 1 Sensor 2
3333
PICAXE PIC33
Flashing Crossing LightsFlashing Crossing LightsProgram 4: modified to flash when one switch is
hit and stop after a 2nd switch is hit
Either of the
two switches
can be hit
first & it will only
stop after the
other switch
is hit.
PauseBeforeStart:'prevents detecting slow button push
low 1 : low 2 ‘turn off both LEDs
pause 1000 'pause 1 second
CheckButtons:
b1=0:b2=0
if pin3 = 1 and pin4 = 1 then CheckButtons
if pin3=0 then
b1=1 : goto flash ‘ set b1 to show it was hit first
endif
b2=1 ‘set b2 to 1 to show it was hit first
Flash:
high 1 : low 2 ‘LED 1 on & LED 2 off
FlashAgain:
for w3= 1 to 250 'check for button before changing lights
if b2=1 and pin3=0 then PauseBeforeStart
if b1=1 and pin4=0 then PauseBeforeStart
next w3
toggle 1:toggle 2 ‘switch lights
goto FlashAgain: 'continue checking buttons
3434
PICAXE PIC34
Tip - Reed SwitchesTip - Reed Switches• Two small metal
plates touch when near a magnet closing acircuit
• Contained withina glass vial – VERY Fragile!
• Many sizes available
3535
PICAXE PIC35
Tip – Magnets for Reed SwitchesTip – Magnets for Reed Switches• Deal Extreme 10mm x 1mm Magnets (part
#13516)
• Very strong – 100 for $12.80 delivered!
3636
PICAXE PIC36
Tip – Magnets for Reed SwitchesTip – Magnets for Reed Switches• Harbor Freight magnets
3737
PICAXE PIC37
Tip – Magnets for Reed SwitchesTip – Magnets for Reed Switches• SunTekStore magnets
3838
PICAXE PIC38
Tip - Free MagnetsTip - Free Magnets
• Salvaged from old Hard Drives
• Virtually all computer hard drives have strong (rare earth) magnets in them
• Remove case & carefully remove platters and other parts that are in the way
• NOTE: some platters are GLASS & are very, very fragile and easily converted to SHARP pieces!
3939
PICAXE PIC39
Tip – Magnets as ClampsTip – Magnets as Clamps
• I recently had to glue a sign to the middle of a building…– Putting a rare earth magnet on the front and
another on the back made it a snap!
• Also great – with “1, 2, 3 block” behind magnets– as couplers– to hold bodies on cars
4040
PICAXE PIC40
Latching Reed SwitchesLatching Reed Switches
• Pass a magnet over one end – it is ON
• Pass a magnet over the other end – it is OFF
• Great for turning battery powered lights on/off with a magnet on a stick
4141
PICAXE PIC41
Tip - ConnectorsTip - Connectors
We are always looking for ways to connect electrical devices together– For low current
use:– Deal Extreme
item # 15234– $2.99 for 10
pair includingshipping!
4242
PICAXE PIC42
Tip – ConnectorsTip – Connectors
• Connectors:– High current for
track and batteryconnections:
• Deal Extreme item # 10788
• $6.37 for 10pair includingshipping!
4343
PICAXE PIC43
Tip – ConnectorsTip – Connectors
• 3 wire Servo Cables have lots of uses• Can be used as is for 3 conductors or back-to-
back for 6 conductors• This is the type of connector that I use for
programming the PCAXE• Ideal for tender / loco connections in larger
scales• Ebay - $3.43 for 10 long extensions
http://www.ebay.com/itm/10pcs-150mm-Servo-Extension-Lead-Wire-Cable-For-Futaba-JR-/151082981725?pt=Radio_Control_Parts_Accessories&hash=item232d3f595d
4444
PICAXE PIC44
Tip – ConnectorsTip – Connectors
• Multi pin cables with sockets
• Great for connecting cars to one another, tenders to locos, etc
• Available in 2 pin 8 pin
4545
PICAXE PIC45
Tip – ConnectorsTip – Connectors
• Search eBay for jst 1.25 to find the smallest connectors
4646
PICAXE PIC46
Tip – Tiny MotorTip – Tiny Motor• Gear head motor a bit larger than a penny• Surprisingly high torque• http://www.suntekstore.com item # 14002627 • Less than $7.00
shipped• Ideal for many
animations• Phil’s Narrow Gauge, too
4747
PICAXE PIC47
Useless Gizmo AnimationUseless Gizmo Animation
4848
PICAXE PIC48
Tip – Dubro CollarsTip – Dubro Collars
• Ideal for connecting to motor shafts & to join piano wire for servos
• http://shop.dubro.com/c/aircraft_collars
4949
PICAXE PIC49
Tip – Heat Shrink TubingTip – Heat Shrink Tubing• Excellent for insulating joints & making
repairs• Soldering wires first is recommended but
not mandatory• Available in many colors – great trick for
identifying wires• Available in many diameters, too• Fry’s has an excellent supply, BangGood,
too!
5050
PICAXE PIC50
Garden Railways Garden Railways PICAXE ArticlePICAXE Article
April 2013 Issuepages 54-59
Contains a detailed introduction to the PICAXE and several projects
5151
PICAXE PIC51
PICAXE ArticlePICAXE Article
Shows how to build:• Single LED
Lighthouse• Single LED Mars
Light• Morse Code Beacon
All using the same circuit
5252
PICAXE PIC52
Custom Circuit BoardCustom Circuit Board
5353
PICAXE PIC53
Lighthouse BeaconLighthouse Beacon
• One of my most popular projects
• More complex than just on & off!
5454
PICAXE PIC54
Lighthouse BeaconLighthouse Beacon
• Parts– Adds one resistor and one transistor to the
flasher circuit so that the PICAXE can control a high current bulb or more LEDs
– The most significant changes are to the software
5555
PICAXE PIC55
Lighthouse Beacon – 4 LEDsLighthouse Beacon – 4 LEDs
5656
PICAXE PIC56
Lighthouse Beacon – Halogen BulbLighthouse Beacon – Halogen Bulb
5757
PICAXE PIC57
How does a pin that is normally either ON or OFF provide variable voltage?
Lighthouse BeaconLighthouse Beacon
Pulsed
Width
Modulation
0 volts
1.25 volts
2.5 volts
3.75 volts
5 volts
Something about this should be bothering you!
?
5858
PICAXE PIC58
PICAXE ArticlePICAXE Article
Single LED Lighthouse
#NO_DATA 'speeds up programming
#Picaxe 08M2 'identify the chip
SETFREQ m32 'speed it up to 32 MHz
SYMBOL Loopie = b2 'label variable b2 as Loopie
SYMBOL Brightness = b1 'label b1 as Brightness
SYMBOL Dlay = 150 'set constant Dlay to 150
Start:
For Loopie = 0 to 100 step 1 '100 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie 'use PWM to brighten the LED
pause Dlay 'pause a bit
next loopie 'get the next item in for/next
pwmout c.2, 255,1023:pause 1000 'flash to full bright briefly
for loopie = 100 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
pause Dlay
next loopie
pause 2000 'pause a bit with LED off
goto start 'do it again!
5959
PICAXE PIC59
PICAXE ArticlePICAXE Article
Single LED Mars light
#NO_DATA 'speeds up programming
#Picaxe 08M2 'identify the chip
SETFREQ m32 'speed it up to 32 MHz
SYMBOL Loopie = b2 'label variable b2 as Loopie
SYMBOL Brightness = b1 'label b1 as Brightness
SYMBOL Dlay = 2 'set constant Dlay to 2
Start:
Gosub ShortFlash 'do the shorter flash routine
Gosub LongFlash 'do the longer flash routine
GOTO Start: 'repeat
ShortFlash: 'a label
For Loopie = 0 to 100 step 1 '100 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie 'light the LED
pause Dlay
next loopie
for loopie = 100 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
sertxd (#loopie, " ")
pause Dlay
next loopie
return 'return to the point where the routine was called
LongFlash: 'do the longer flash
For Loopie = 0 to 255 step 1 '255 steps from off to bright
brightness=255-loopie
pwmout c.2, brightness, loopie
pause Dlay
next loopie
for loopie = 255 to 0 step -1 'repeat above backwards
brightness=255-loopie
pwmout c.2, brightness,loopie
pause Dlay
next loopie
return
6060
PICAXE PIC60
PICAXE ArticlePICAXE Article
Morse Codebeacon
6161
PICAXE PIC61
PICAXE ArticlePICAXE Article
• Article #2 includes:– Working with multiple LEDs (up to 6)– Working with trigger inputs– Working with variable inputs (potentiometer)– Lots of projects / programs
6262
PICAXE PIC62
Article #2Article #2Custom Circuit BoardCustom Circuit Board
• I designed and had boards fabricated that support– up to 6 LEDs– 2 trigger switches – 2 potentiometers– 6 power transistors– 5 volt regulator
6363
PICAXE PIC63
Article #2 - ProgramsArticle #2 - Programs
• Crossing signal with two triggers
• Traffic light
• Emergency vehicle lights
• High power LED ditch lights
• School bus strobe light
6464
PICAXE PIC64
PICAXE ArticlePICAXE Article
• Article #3 to include:– Moving animations with servos– Controlling motors
6565
PICAXE PIC65
AnimationAnimation
• Animation adds fun and excitement to your layout
• Moving things is easy with the PICAXE as it knows how to talk to model airplane servos
6666
PICAXE PIC66
AnimationAnimation• By sending precisely timed pulses the
PICAXE can set the servo’s arm to a specific position and hold it there.
6767
PICAXE PIC67
AnimationAnimation• Only three wires go to the servo
– Two for power and 1 for control pulses– The SERVO command is built into the
PICAXE
6868
PICAXE PIC68
Simple Servo ProgramSimple Servo Program'd. bodnar 6-2-13 'Servo Demo
symbol ServoPin = 5b2=225:b3=75 ‘the range is 75 to 225
start: gosub cw: pause 1000: gosub ccw: pause 1000: low ServoPingoto start
cw:for b0= b2 to b3 step -1 servo ServoPin, b0 pause 50next b0return
ccw:for b0=b3 to b2 step 1 servo ServoPin, b0 pause 10next b0return
6969
PICAXE PIC69
Servo ExamplesServo Examples
• Elephant used at Children’s Hospital
7070
PICAXE PIC70
AnimationAnimation• Playmobil elephant from Pittsburgh’s
Children’s Hospital layout
7171
PICAXE PIC71
Servo ExamplesServo Examples
• Outhouse
7272
PICAXE PIC72
Servo ExamplesServo Examples
• Water Spout
7373
PICAXE PIC73
Servo ExamplesServo Examples• Prairie Dogs
7474
PICAXE PIC74
Servo ExamplesServo Examples
• Scanning Spotlight
• Uses brightLED
• And twoServos
7575
PICAXE PIC75
Servo ExamplesServo Examples
• Bears– Two servos on large
bear– One each on others
7676
PICAXE PIC76
Servo ExamplesServo Examples
• Eggliner
7777
PICAXE PIC77
Servo ExamplesServo Examples• Children’s Hospital Searchlight
– Rotates back & forth via servo– Only works when train is running and lights
are dim
7878
PICAXE PIC78
Servos Come in Many SizesServos Come in Many Sizes
• Standard
• 9 gram
• 4.3 gram
• 1.5 gram
7979
PICAXE PIC79
Tip - MPJA Power SupplyTip - MPJA Power Supply
• Excellent tool for testing circuits
• Also works well for testing locomotive and other train related devices
• Dual meters (volts / amps) provide very valuable information
8080
PICAXE PIC80
Pendulum AnimationPendulum Animation• An acrobat is
substituted for the pendulum
• A microcontroller starts & stops the acrobat and changes the speed of his swinging
• A very simple circuit operates our last animation
• The pendulum swings because of a magnet at the bottom & a coil under the base that gives a shove each time it goes by
8181
PICAXE PIC81
Tip – Learn to Solder!Tip – Learn to Solder!
• With some practice and the right tools you can be an expert in no time!
8282
PICAXE PIC82
Tip - SolderingTip - Soldering• A good iron makes you a better solderer!
– MPJA.com
– Item #ZD 929C – $46.95– Digital
temperature readout
– Replacement handle assembly $6.95
8383
PICAXE PIC83
Tip - SolderingTip - Soldering• A clean tip makes all the difference.• http://www.dealextreme.com
• Item 34154 • $6.65• MPJA has something
similar
8484
PICAXE PIC84
Tip - Tip - Plumber’s PuttyPlumber’s Putty
• I find Plumber’s Putty to be ideal for holding parts while I solder them
• Easy to remove and reasonably inert
8585
PICAXE PIC85
Speaking of Soldering ThingsSpeaking of Soldering Things
• Torch - # 42099from Harbor Freight
• Typically less than $10
• Frequently on salefor ½ of that
8686
PICAXE PIC86
#1 Tip EVER - Adhesive#1 Tip EVER - Adhesive
Great for quick temporary or permanent connections– Similar to the “goo” on the
back of a new credit card– I use it in place of hot melt
glue– DOTS brand– Michaels (don’t forget the
40% off coupon!)
8787
PICAXE PIC87
Sound adds to Animations!Sound adds to Animations!• Inexpensive sound cards can play back your own
sound files• plugs directly into a computer's USB port for sound
downloads • utilizes the most
common type of sound files, MP3's
• costs about $13.00
http://www.trainelectronics.com/MP3_USB/
8888
PICAXE PIC88
USB / MP3 SystemUSB / MP3 System• records up to 75 seconds of sound • Easily connects to external speaker systems • Easily triggered by a push button, reed switches or
radio control systems• Notes on use on
trainelectronics.com
http://www.trainelectronics.com/MP3_USB/
8989
PICAXE PIC89
Newer USB / MP3 SystemNewer USB / MP3 System• Records up to 300
seconds of sound • Direct connection to
external speaker systems • Easily triggered by a push
button, reed switches or radio control systems
• Has 4 separate triggers for 4 different sounds
• About $16.00
http://www.trainelectronics.com/USB_sound_4/
9090
PICAXE PIC90
Laser SensorLaser Sensor
• Although reed switches and magnets work well as sensors …
• … we sometimes need something more capable
• … like a laser shining down or across the track to detect a train
• … just like those that protect bank vaults in the movies!
9191
PICAXE PIC91
Laser SensorsLaser Sensors• Sensors at each end of the module’s main
line were used to stop the mining train when a train on the main line approached
• They worked most of the time but could easily be tricked
main main
mining
mining
9292
PICAXE PIC92
Laser SensorsLaser Sensors
•A redesign has a laser beam shooting right down the center of the main line•Any train on the main interrupts the laser beam
9393
PICAXE PIC93
Laser SensorsLaser Sensors
• The only problem that remained was the bright laser light that was quite visible as it was shining on the train & its cars
• … not too prototypical!
• Since a microcontroller was in charge of the laser being on or off some experiments were in order
9494
PICAXE PIC94
Laser SensorLaser Sensor
• Designing such a system is pretty easy using a photo transistor and a laser
• … but the laser “dot” is rather visible and distracting and may be harmful to visitors or pets!
9595
PICAXE PIC95
Laser SensorsLaser Sensors
sensor laser
• I decided to redo the circuit putting a microcontroller in charge of the laser.
• I started doing some experiments having the PICAXE turn the laser on and off
• … figuring it would be better
• … but it was even more visible when flashing!
9696
PICAXE PIC96
Laser SensorsLaser Sensors• The length of “on” time was gradually decreased• I was hoping that the sensor would still detect
brief laser light pulses• 1/10 second on / 1/100 second off
– OK
• 1/100 second on / 1/100 second off– OK
• 1/1000 second on / 1/100 second off – still OK!
9797
PICAXE PIC97
Laser SensorsLaser Sensors
• The time was decreased till it hit the fastest pulse that the controller could produce – less than 1/10,000 second
• Still OK
• And….
• It produced a nearly invisible laser beam
9898
PICAXE PIC98
Laser SensorsLaser Sensors
Top:
HIGH laser ‘turn on laser
PAUSEUS 1 ‘pause 1/1,000,000 second
IF PhotoTran=1 THEN ‘if detected then do stuff
HIGH led1:HIGH relay ‘LED & RELAY on
ELSE ‘if not do other stuff
LOW led1:LOW relay ‘LED & Relay off
ENDIF
IF SWBright=1 THEN LOW laser 'if switch on dim Laser else leave on full
PAUSE 10 ‘leave laser off 1/10 second
GOTO Top ‘do it again
9999
PICAXE PIC99
Laser SensorsLaser Sensors
• A switch was added to keep the laser on at full brightness while aiming the laser and aligning it with the sensor…
• … making setup-alignment a snap!
100100
PICAXE PIC100
Laser SensorsLaser Sensors
• It even works with a mirror on the other side of the track reflecting the laser dot back to the sensor
101101
PICAXE PIC101
18 Pin PICAXE Chip18 Pin PICAXE Chip
• Prior seminars focused on the PICAXE 08M - 8 pins – about $3.00 each
• A new 18 pin chip, the PICAXE 18M2 -about $5.00 and has much more capability– Faster– 15 pins available for input & output– Much more memory– Low voltage operation (as low as 2 volts!)– Built in timer
102102
PICAXE PIC102
18 Pin PICAXE Project18 Pin PICAXE Project
• We will be using the new PICAXE chip to create a completely solid state track side or on-board speed controller…
• …that has a really cool trick up its sleeve…
• …that can be modified to do a host of other things
• …that can be modified to supply up to 12 amps of DC power!
103103
PICAXE PIC103
PICAXE Speed ControllerPICAXE Speed Controller
• Objectives:– Controls DC track power: speed & direction– Manages smooth acceleration / deceleration– Never changes direction when power is on– Controlled by inexpensive television IR remote
control– Can handle several amps
104104
PICAXE PIC104
Speed ControllerSpeed Controller
• Parts:– PICAXE 18M2– Single chip “H-Bridge”– IR Receiver chip– 18+ volt power supply
105105
PICAXE PIC105
Speed ControllerSpeed Controller
• Other circuits use relays to reverse direction and a single transistor to control speed
• This circuit uses a single L298N to do both jobs
106106
PICAXE PIC106
Speed ControllerSpeed Controller• The first version of the controller operates
a simple layout using the IR remote control to vary track power
• It can be used as a basic speed / direction controller
• …or it can be programmed to change direction based on time (easy point-to-point controller!)
107107
PICAXE PIC107
How Do We Control the Controller?How Do We Control the Controller?
• Speed and other settings can be modified with a simple TV remote control
– Set min & max speed– Set rate of deceleration– Set time to wait at ends on point-to-point
& IR sensor
108108
PICAXE PIC108
IR Control Built into PICAXEIR Control Built into PICAXE
• PICAXE program to display IR codesSymbol IRSense = b.2 'pin 8
Symbol InfraRED = b12
#TERMINAL 4800
IRTEST:
Irin [50, IRTEST],IrSense, InfraRED
SERTXD("InfraRED Code = ",#InfraRED,13,10)
GOTO IRTEST
109109
PICAXE PIC109
Control OptionsControl Options• Remote Control Buttons
– Channel UP - Increase speed – Channel DOWN - Decrease speed – Volume UP - Change direction to forward (if not
already going forward) – Volume DOWN - Change direction to backwards (if
not already going backwards) – MENU - stop the train remembering the current
speed - press MENU again to restart at the same speed and in the same direction
110110
PICAXE PIC110
Additional Control OptionsAdditional Control Options
– Press the RETURN button to change settings1. Change Maximum Speed
2. Change Minimum Speed
3. Change Run Time
4. Change Acceleration / Deceleration rate
111111
PICAXE PIC111
Train RecorderTrain Recorder• One day I had an idea.
• Rather than entering places to have the trolley stop with the TV remote…
• … wouldn’t it be cool if it could be programmed to learn the route that I wanted it to take?
112112
PICAXE PIC112
Train RecorderTrain Recorder• I tried it and it worked…
• … giving birth to the most exciting version that automatically records (at a rate of 50 recordings per second) a train’s movements so that you can play them back over & over
• Total record time of up to 20 minutes
• A rather unusual but very cool thing to do!
113113
PICAXE PIC113
Train RecorderTrain Recorder
• Additional Components:– A memory chip to store activity (can store up
to 20 minutes!)– A potentiometer to control speed & direction– A relay to control a “stop block” that keeps
things in “sync”
116116
PICAXE PIC116
LED Coach LightsLED Coach Lights
• I recently received an email from a garden railroader who wanted to illuminate his passenger cars with battery powered LEDs
• After some discussion and experimentation a solution was designed that provides us with many options for using and powering LED lighting
117117
PICAXE PIC117
Prewired LED Strip LightsPrewired LED Strip Lights• Meant for under cabinet lighting in
kitchens and similar applications
• 12 volts
• Can be cut into short sections
• Many colors available
• Self adhesive back
• A great product but not for his low voltage application!
118118
PICAXE PIC118
LED Coach LightsLED Coach Lights
• Design called for battery operation and enough lights to illuminate g-scale coaches
• First units were built on popsicle sticks to get layout and spacing right
• All of the LEDs are wired in parallel to keep operating voltage down
• Adding parallel resistors increases brightness & decreases run time
100 ohm resistors
Resistance (ohms)
mA to LEDsHours /w 2000 mAh cells
one 100 20 100
two 50 40 50
three 33.3 60 33.3
four 25 80 25
five 20 90 20
119119
PICAXE PIC119
LED Coach LightsLED Coach Lights
• Lights can be turned on and off by a latching reed switch
• Pass a magnet over one end of the reed switch and the LEDs go on
• Pass it over the other end and they go off
• The reed switch can be placed against the top of the car so nothing is seen and no holes are drilled in the car
120120
PICAXE PIC120
LED Coach LightsLED Coach Lights
• A custom circuit board was designed
• And sent off for manufacture
121121
PICAXE PIC121
LED Coach LightsLED Coach Lights• The circuit board
– Is about 13” long
– can accommodate • up to 25 LEDs• a latching reed switch• current limiting resistor
122122
PICAXE PIC122
Tip – CA AcceleratorTip – CA Accelerator
Most of us have used cyanoacrylic glue (super glue)
But have you also used CA accelerator which dries CA in seconds?
123123
PICAXE PIC123
LED Coach Lights Power OptionsLED Coach Lights Power Options
• A power board was added that accommodates track power – DC or DCC– Bridge rectifier – gives consistent polarity– Voltage regulator- gives consistent 5 volts– Capacitors – no flicker on dirty track
124124
PICAXE PIC124
LED Coach Lights with Super Caps!LED Coach Lights with Super Caps!
• Super Caps can keep lights going for minutes after the power is removed
125125
PICAXE PIC125
LED Coach Lights with DCC PowerLED Coach Lights with DCC Power
• The circuit was modified to put groups of LEDs in series to accommodate higher voltages such as from DCC
• The power supply board was modified as well
126126
PICAXE PIC126
It’s more fun to make it yourself than to buy it ready to go!
"I am always doing that which I "I am always doing that which I cannot do, in order that I may cannot do, in order that I may learn how to do it."learn how to do it."Pablo PicassoPablo Picasso
Remember:
127127
PICAXE PIC127
Your Ideas?Your Ideas?
• Questions?
128128
PICAXE PIC128
129129
PICAXE PIC129
130130
PICAXE PIC130