Picaxe Timer Project

whitemills

New Member
Hi all,
I've recently renewed my interest in Electronics as a hobby having lapsed from the hobby for a number of years , I'm now 60 years of age. Also I've only very recently discovered picaxe controllers and I find the whole topic fascinating.As I'm only new to basic programming I wonder would someone be able to supply me with a basic code programme to get me started to do the following:

I need a timer to do the following:
Using picaxe controller -08M2
Total timed period is 10 minutes to be indicated by a flashing led.
Timing triggered by pressing a push button.
The output to drive a relay.
The last 2 minutes of timing to be indicated by an intermittent buzzer sounding.
When the 10 minute time period is up the timer cannot be retriggered again for a further 5 minutes.
Would appreciate any help on this to get me started on my hobby again.
 

sghioto

Senior Member
OK whitemills, welcome to the Forum.:cool:
This request sounds a little advanced for a newcomer. Is this a something you're actually wanting to build or do you just need a program to verify it could work as designed? I don't think anybody will want to do your homework so the best thing to do in order to get some help would be to study the on-line manuals and try and posts your own code. Even if it's terrible:eek: this is will get the "ball rolling" then we can offer suggestions/corrections. :)

Steve G
 

whitemills

New Member
Thanks Steve G for your reply.Yes I know its best to learn this way but I need to get this project built before winter sets in as I need this as part of a garden project.I have been doing some projects from the manuals which are very good but if I could get this one project going I think that would also be a good learning experience.
Regards,
Whitemills
 

eclectic

Moderator
snip
but I need to get this project built before winter sets in as I need this as part of a garden project.

snip

but if I could get this one project going I think that would also be a good learning experience.

Please tell us more. :- )

What is the project?

e
 

hippy

Technical Support
Staff member
Welcome to the forum.

As a template for your project you could use something like this, relying on the inbuilt 'time' variable to keep track of elapsed time ...

Code:
Do
  Wait until button pushed
  time = 0
  Turn the relay on
  Do
    8 minute period of flashing the LED
  Loop until time > 8*60
  Do
    2 minute period of beeping the beeper
  Loop Until time > 10*60
  Turn the relay off
  Do
    5 minutes of button push lock out
  Loop Until time > 15*60
Loop
You can reasonably easily convert that to actual PICAXE code ...

Code:
#Picaxe 08M2
Do
  Gosub WaitUntilButtonPushed
  time = 0
  Gosub TurnTheRelayOn
  Do
    Gosub FlashingTheLED
  Loop until time > 480
  Do
    Gosub BeepingTheBeeper
  Loop Until time > 600
  Gosub TurnTheRelayOff
  Do
    Gosub DoNothing
  Loop Until time > 900
Loop

WaitUntilButtonPushed:
  Return

FlashingTheLED:
  Return

BeepingTheBeeper:
  Return

DoNothing:
  Return

TurnTheRelayOn:
  Return

TurnTheRelayOff:
  Return
That handles the timing, then it's a question of what to put in those subroutines at the bottom to do what you need to do.
 

whitemills

New Member
Hi eclctic thanks for your reply.
I'm building a timer to turn on and off a water valve for a gardening project which I'm making, gardening being the second hobby.
As I said the timer must turn on for 10 minutes, timing to be indicated by an LED permanently on. The last 2 minutes of timing to be indicated also by a buzzer sounding.
When the 10 timing is up the timer must lockout then for 5 minutes , this to be indicated by the timing led flashing.
WHITEMILLS
 

The bear

Senior Member
@whitemills,
What sort of valve, what voltage to operate it.
Garden irrigation stuff is quite cheap now. I don't want to spoil your project.
Are you related to Bushmills?
Regards, Bear..
 

StigOfTheDump

Senior Member
Not elegant but simple code that would do it. The counts for the loops need increasing to the values in comments (I set them small for the simulator.) If you are using PE6 you should be able to start the simulation then click the C.3 tab in the simulation window to simulate the button being pressed. (don't forget to click it again to turn it off. again) The output pins should light up to represent relay, led and buzzer coming on and off.

This follows your original spec where the led flashes for 10 minutes but you should be able to figure out how to make it steady then flash for 5 mins. The whole process can be speeded up or slowed down by altering the 250 and 750 pauses.

I will leave the connections side to somebody else if you need that explaining as well.

Code:
[color=Blue]Symbol [/color][color=Purple]PressButton [/color][color=DarkCyan]= [/color][color=Purple]pinC.3[/color]
[color=Blue]Symbol Relay [/color][color=DarkCyan]= [/color][color=Blue]C.1
Symbol LED [/color][color=DarkCyan]=[/color][color=Blue]C.2
Symbol Buzzer [/color][color=DarkCyan]= [/color][color=Blue]C.4[/color]
[color=Black]Main:[/color]
[color=Green]'If button isn't pressed loop until it is[/color]
[color=Blue]If [/color][color=Purple]PressButton [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then goto [/color][color=Black]Main  [/color][color=Green]'wait for button press[/color]
[color=Blue]High Relay                    [/color][color=Green]'Relay on
'8 mins of flashing[/color]
[color=Blue]For [/color][color=Purple]w0 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]48              [/color][color=Green]'8 mins = 480 seconds[/color]
[color=Blue]High Led                      [/color][color=Green]'LED on[/color]
[color=Blue]pause [/color][color=Navy]250                     [/color][color=Green]'Wait 1/4 second        [/color]
[color=Blue]Low Led                 [/color][color=Green]'LED off[/color]
[color=Blue]Pause [/color][color=Navy]750                     [/color][color=Green]'Wait 3/4 second  [/color]
[color=Blue]next [/color][color=Purple]w0                       [/color][color=Green]'Do it again
'2 mins of flashing and buzzing[/color]
[color=Blue]For [/color][color=Purple]w0 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]12              [/color][color=Green]'2 mins = 120 seconds[/color]
[color=Blue]High Led                      [/color][color=Green]'LED on[/color]
[color=Blue]High Buzzer                   [/color][color=Green]'Buzzer on[/color]
[color=Blue]pause [/color][color=Navy]250                     [/color][color=Green]'Wait 1/4 second  [/color]
[color=Blue]Low Led                       [/color][color=Green]'LED off[/color]
[color=Blue]Low Buzzer                    [/color][color=Green]'Buzzer off[/color]
[color=Blue]Pause [/color][color=Navy]750                     [/color][color=Green]'Wait 3/4 second [/color]
[color=Blue]next [/color][color=Purple]w0                       [/color][color=Green]'Do it again
'5 mins of waiting[/color]
[color=Blue]Low Relay                     [/color][color=Green]'Relay off[/color]
[color=Blue]For [/color][color=Purple]w0 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]30              [/color][color=Green]'5 mins = 300 seconds [/color]
[color=Blue]pause [/color][color=Navy]1000                    [/color][color=Green]'Wait 1 second[/color]
[color=Blue]Next [/color][color=Purple]w0                       [/color][color=Green]'Do it again[/color]
[color=Blue]Goto [/color][color=Black]Main                     [/color][color=Green]'Go to beginning, do it all again         [/color]
 

whitemills

New Member
Hi Bear,
I intend operating a 12 volt relay with mains rated contacts to turn on on and off a solenoid valve, 220 volt 5w.
No relation of Bushmills but I do like their whiskey and by the way Whitemills is the name of my local.
 

whitemills

New Member
Hi Stig
This looks like what I need and my knowledge of picaxe commands so far all fit in with your solution. I can manage connections and the hardware side of things myself.
Many thanks.
Whitemills
 

whitemills

New Member
Hi Stig
Have been trying out your code on the simulator, if I set the 10 minute timer as: For w0 = 1 to 480 ' 8 minutes timing, when I start the simulation and check with my stopwatch the "for- next" loop takes 11 minutes and 16 seconds.Similiarly with the other 2 loops , ie the 2 minute loop and the 5 minute loop the time takes longer than what" for- next" loop is programmes for.
I've tried different values and each loop seems to be a lot longer than required when I do a simulation. Any ideas. Whitemills
 

StigOfTheDump

Senior Member
I don't think the simulator is very accurate for testing timing. Every process takes a bit of time (on the chips and in the simulator). I would not be surprised if the simulator speed was affected by how fast your PC is running and how many other programs are running. You could test this. You would need to tune the timing values until they get to what you need. I think they will remain quite accurate once you have set them. External forces such as temperature can also cause small changes.

There are lots of ways you could write your code, some will be more true to your expectations than others, but can be less easy to understand.
 

whitemills

New Member
Thanks for that Stig.This makes sense as I would have 2 or 3 progs running together.Will try it on my breadboard and see how that goes.
Regards,
#Whitemills
 

AllyCat

Senior Member
Hi,

Note that it's a code simulator, not a PICaxe (hardware) emulator, so you should not expect timings to be accurate. But in any case, code as shown in #10 will tend to run "slow" because all the instructions add extra delays, in addition to those specified by the 250 and 750 ms pause commands.

Therefore, IMHO using the "time" variable as shown by hippy in #6 is a better solution. But look at his PICaxe code version (in the second "code" box) rather than the "pseudocode" (in the first box) which uses some "reserved words" that might confuse a beginner.

Cheers, Alan.
 

inglewoodpete

Senior Member
I've used the system "Time" variable in a recent project and it is proving to be quite accurate. I am using an 08M2 and the timer has been +/- 3 minutes per day - that's accurate to 0.21%!
 
Top