PICAXE Project:
Identification and/or Timeout Timer

I have been interested in developing with microcontrollers for several years now and recently finished a PIC/PICAXE Development Console that I could use to develop projects using the lower end PIC microcontrollers or the PICAXE Microcontroller. I have pictures posted on my website of its construction. After seeing Geoff's article in THE EXPERIMENTER on a 555 based timer, I was thinking, “Why not use the PICAXE 8 Pin microcontroller to build a station identification and/or timeout reminder timer.” A PICAXE microcontroller based timer would have the following advantages: (1) The same number of pins as the 555 timer, (2) Less parts to build than a 555 timer, (3) Two timer modes without more parts count, and (4) The ability to change the timer parameters in the future by reprogramming the PICAXE Controller.


THE PICAXE MICROCONTROLLER. WHAT IS IT AND HOW IS IT SET UP?

The PICAXE is a PIC microcontroller with a preloaded bootstrap firmware. This firmware runs as a BASIC Interpreter. You can think of the PIC Microcontroller hardware underneath as a desktop CPU and the PICAXE BASIC Interpreter as the Operating System. You can write your own programs in PICAXE BASIC and upload them to the PICAXE microcontroller by a three wire serial connection. If you are using a modern desktop computer (running Windows 7 or Windows 8) , more than likely it does not have any “legacy” serial ports. You will need to buy or build a USB to TTL converter. Sparkfun Electronics sells a USB to TTLconverter for around $15. It is based on the FTDI FT232 USB to TTL converter. Windows 7 will automatically find the drivers for the FTDI FT232 through the Windows Driver Search feature. However, if you have Windows XP you will need to download the drivers. When you do plug in your USB to TTL interface for the first time, Windows XP will prompt you to install the drivers. These drivers are available for download from FTDI's website3.

Both the PIC microcontroller and accordingly the PICAXE based PIC microcontrollers run on 3-5 Volts DC. If you use over 5 Volts DC, you can and probably will damage or destroy the microcontroller. That is why you need to use a USB to TTL instead of a USB to RS232 interface IC. The PICAXE is well documented and supported. All of the documentation is online at the PICAXE website at http://www.picaxe.com.

There are several families of the PICAXE that go from 8 Pins to 40 Pins. Since the PICAXE is, at the current time, installed on PIC microcontrollers that are Dual In Line (DIP) package chips, you do not need to worry about surface mount techniques. Also the PICAXE can be programmed without taking the chip out of the circuit. This is referred to as In Circuit Serial Programming (ICSP) and is normal now with nearly all microcontrollers.


TIMER FUNCTION DESCRIPTION:

Timer board installed in a Radio Shack plastic case

Figure 1: Timer board installed in a Radio Shack plastic case

Figure 1 shows a picture of the timer installed in an enclosure. The timer has three Light Emitting Diodes (LED's): green, yellow, and red. Upon power being applied, the LED's will blink from green to yellow to red three times in a row. This is to let you know if the LED's are working properly and the timer is ready for use. The timer by default is in 3 minute timer mode. If you wish to use it as a 10 minute timer, simply turn off the power, hold down the timer button, and turn the power back on. Then the LED's will blink from green to yellow to red ten times in a row, instead of three. When the timer button is pressed, all three LED's will blink together once to let you know the time cycle is beginning and the green LED will turn on. When 30 seconds are left in the time cycle, the green LED turns off, and the yellow LED starts blinking on and off at about one half second intervals. When the time cycle is complete, the yellow LED turns off completely and the red LED starts blinking at about four times per second. After 30 seconds, if you do not hit the timer button, the timer will automatically reset. This is shown by all three of the LED's blinking together twice. Also you can manually reset the timer any time in the cycle by pressing the timer button and all three of the LED 's will blink twice together as well. The three LED's blinking twice indicating that the timer is has been reset successfully.


DESCRIPTION OF THE SCHEMATIC DIAGRAM

Schematic Diagram of the PICAXE 08M2 ID/Timeout Timer

Figure 2: Schematic Diagram of the PICAXE 08M2 ID/Timeout Timer

Figure 2 is a straightforward schematic diagram. The PICAXE 08M2 is the lowest end PICAXE microcontroller current available. Note that pin 1 is +Vcc and pin 8 is ground. This is reverse from many 8 pin chips where normally +Vcc is pin 8 and pin 1 is ground. The circuit uses three discrete LED's. Pin 7 is used for serial out going to a programmer. Pin 6 is the I/O port that controls the green LED, Pin 5 is the I/O port that controls the yellow LED, and Pin 3 is the I/O port that controls the red LED. Pin 4 has a 10k pullup resistor and a reset button. Pin 4 is at +Vcc (1) until you press the reset button. When you press the reset button, pin 4 goes to ground (0). Pin 2 is the serial in from the programmer. Notice the 22K resistor that is in series with pin 2 and the 10K resistor from the 22k resistor to ground. These insure that pin 2 is not floating. You must include these resistors even if you are not going to program it in circuit. These two resistors are essential for stable operation of the PICAXE. If you leave these resistors out, the PICAXE will not operate properly or at all.


DESCRIPTION OF THE SOFTWARE RUNNING THE PICAXE:

Flowchart of the PICAXE BASIC software that runs the PICAXE

Figure 3: Software Flowchart of the PICAXE BASIC Software

Figure 3 shows a flowchart of the software I wrote in PIC BASIC, which the PICAXE Basic Interpreter runs. When the program begins operation (when power is applied) the processor will blink through the LED's three times. Then the program enters the main loop and remains in this loop until pin4 goes low which occurs when S2 is depressed. When S2 is depressed, the program breaks out of the loop and starts to run the green LED loop, yellow LED loop, and red LED loop in succession. When the red LED loop is complete, the timer reset routine is executed (all LED's blink together twice) and then it goes back to the main loop. Each of the LED loops poll to see if pin4 is low, which is accomplished by S2 being depressed. If the switch is depressed, the program breaks out of that respective loop, goes to the timer reset routine, and back to the main loop again.


CONSTRUCTION OF THE TIMER:

The construction method you use to build the timer is not critical. Almost all the parts are available at Radio Shack with the exception of the PICAXE microcontroller which can be purchased from Sparkfun Electronics out of Colorado. Though you can use a perfboard or any generic prototype printed circuit board, I used a Radio Shack one IC printed circuit board (PCB) to build the timer. Figure 3 shows a picture of the finished timer circuit board. I used a battery holder instead of trying to solder directly to the battery, as I have had dubious results with that method in the past. I built the timer with a 3V CR2032 Lithium Ion Battery and battery holder to save space. I used a second one IC printed circuit board (trimmed down to fit in the case) to mount the CR2032 battery holder for improved stability.

Picture of the PICAXE 08M2 timer board

Figure 4: Picture of PICAXE timer board

Figure 4 shows the details of how I constructed the timer. I soldered the Single Pole Single Throw (SPST) main power switch, the SPST Momentary Push Button Switch, and the three LED's directly to the printed circuit board (PCB) for simplicity of construction. I put the completed PCB's into the small enclosure, used the #6-32 Machines screws and nuts to form PCB standoffs, and spaced the board so the enclosure lid would fit on the switch shafts properly. You can build the timer with, or without the enclosure. If you do not use an enclosure you will need to use a bigger PCB to include the battery and use some kind of standoffs for the timer to sit on your desk.


OPTIONS FOR CONSTRUCTION OF THE TIMER

Here are some variations on this project you may try for yourself to suit this timer to your particular needs.

  • If you use a CR2032 style Lithium Ion Battery to power the timer and are going to use it in a mobile environment, you may wish to install a 100uF electrolytic capacitor across the power input to the timer. This is to compensate for extreme vibration that can cause intermittent contact in the battery holder terminals. The capacitor will hold a charge long enough to operate the timer when the battery holder may have intermittent contact, which only lasts a few milliseconds in duration on average. This will prevent the PICAXE from inadvertently rebooting and causing the only problem I observed. In a base station environment this will not be necessary.

  • Any voltage source from +3VDC to +5VDC is adequate to power the PICAXE if it can supply 50 m A of current or more. Therefore, you may wish to build yours with a 3V AA Battery holder but you will need a slightly larger case than the one I used in building this one.

  • You can use an external power supply as long as the PICAXE voltage requirements are met and not exceeded. The schematic diagram contains a suggested power regulator circuit for an external power option. The 78L05 has enough current capacity to operate the timer and all LED's.

  • You do not have to use all the LED's in the schematic. If you wish to simply have the yellow and red LED's or just the red LED you may simply omit the LED and limiting resistor from construction. Just leave that port pin on the PICAXE open.


PROJECT RESOURCES LIST:

Schematic Diagram - BMP Format
Schematic Diagram - DesignSpark Schematic File
Flowchart Diagram - BMP Format
PICAXE BASIC Source Code - Text Format

If you have any suggestions or feedback on how this timer can be improved please email me or fill out the contact form on the main page of my website. I will be glad to correspond with you. Coming soon, I will be making this project available in kit form, with a small printed circuit board.