Multi Alarm Clock

Authentic

New Member
Hi all,

Excuse my newbieness in this, i'm just getting started in this whole electronics thing. I am building an automatic feeder for a friends farm to feed animals when they go on holiday. Essentially the electronics part is an alarm clock, I have a PICAXE 18 high power project board with L293D motor driver hooked up to a motor which operates the feeder.

The supply to the board (and motor) is 12V from a general everyday battery with a 5V 1A regulator to power the chip.

I also have a Serial OLED display with clock module installed.

What I would like to achieve is to have 2 alarms; say one at 8:00am and one at 16:00pm when the motor will activate until a microswitch is pressed when the feeder mechanism moves round to the "fed" position.

My code is as follows

B.7 is the serial output to the OLED module and embedded alarm clock
C.7 is the serial input from the OLED module that goes high for 5 seconds when the alarm time is reached
B.4 and B.5 are motor outputs
C.0 is the microswitch intended to stop the motor


My problem is as follows: how can I implement the second alarm? Originally I was thinking when one alarm goes off, it cancels said alarm and reprograms the next time. Then when that time is reached, it cancels the alarm and reprograms it for the original time. Have some sort of variable (b0 in the code) that alternates?

Also I would like the motor to effectively "latch" once the alarm has gone off since the pin only remains high for 5 seconds.

The microswitch must return the whole circuit to the "waiting for next alarm input"


Apologies if anything is unclear, would appreciate some advice here!

Thanks,

Code:
start1:

init: 
pause 500 'initialise display

serout B.7,N2400, (253,8,"00/00/00 08:00  ") 'set morning alarm time to 08:00
pause 500


main1: 
serout B.7,N2400, (254,1) 'clear display to indicate that this code is running and the time is updating
pause 500
serout B.7,N2400, (1) 'display predefined message 1 
pause 100
serout B.7,N2400, (0) ' display time 
pause 4900 
goto main1 'loop 



start2:

main2:

let b0 = 1

if pinc.7 = 1 and b0 = 1 then gosub alarmam 'if variable b0 is 1 then morning alarm will activate
if pinc.7 = 1 and b0 = 2 then gosub alarmpm ' if variable b0 is 2 then afternoon alarm will activate

goto start2 'loop
	
	alarmam: 'morning alarm
 high b.4 'start motor
 low b.5
 
if pinc.0 = 1 then low b.4 'wait for alarm cancel switch then switch off motor
endif

goto start2

	alarmpm: 'afternoon alarm
high b.4
low b.5

if pinc.0 = 1 then low b.4 'wait for alarm cancel switch then switch off motor
endif

goto start2

end
 
Last edited by a moderator:

rossko57

Senior Member
I don't think I'd use the RTC's simple alarm at all; just use it as a clock. The picaxe has nothing better to do than check the time anyway, why not let it manage the alarms internally.
This also does away with worrying about synching up in the first place, i.e. deciding which alarm time to reprogram into the RTC next.

Having started the motor running, wouldn't you wait for the microswitch to go 'off' (as the mechanism moves from park) and then wait for it to go on again?
 

1968neil

Senior Member
simpler way to think about it :

Use what you already have,

I2C clock is quite easy to use, connect it up to your Picaxe 18 only needs three connections SCL,SDA and ground and two 4k7 pull up resistors. (possibly already on the display board ? Never used that particular display personally.)

If you program the Picaxe as a regular clock so the time is displayed on the Display (see axe133 datasheet)
You can set the time on the DS1307 clock chip using the datalogger wizzard.

Program format : (this is not the actual program just an idea of the format to use)

Main:

Read time
display time
if time = 08:00 then goto Alarm 1
if time = 16:00 then goto Alarm 2
Goto main

Alarm1:
Start motor
do
loop until microswitch=0
goto main

Alarm2:
Start motor
do
loop until microswitch=0
Goto main

You could add as many alarms as you wanted, if you used the day of the week you could also miss weekends if needed etc
This is the format i would start with to keep it simple and then fettle it from there.
Just my opinion ?
 

jims

Senior Member
Authentic .... Micro switch contacts are notorious for "bounce". Don't forget to handle this either with software or some hardware. I've been caught on this several times (tend to forget from one project to the next). Jims
 

rossko57

Senior Member
There is a bigger trap associated with the switch. I'm completely making this up in the absence of info, but suspect the switch is following a cam on the feeder mechanism. This would mean that when the mechanism is parked, the switch is actuated.
When you start the motor, the switch is still actuated and takes a finite time to go off as the mechanism moves. If you start the motor and immediately look for the switch to be actuated ... it is already. It's all over in a millisecond and no feed takes place.
You must either run the motor until the switch goes off, or for a minimum time, before looking to see if the switch is actuated.

Looking ahead to a later phase of the project, if you run for a short time and then check the switch .... if it hasn't gone off as expected, then you know there's been a jam and you can save a fire in the motor. You'd want to limit the total run time likewise, to detect a jam during the rest of the cycle. Bearing in mind this is running unattended.
 

Authentic

New Member
Thanks for all support and advice, key points then:

Use i2c for clock interface and alarms
Switch bounce
Detection of jamming, with this point though I was planning to continue to run the motor for 5 secs after switch activated to get it past the cam point.
 

westaust55

Moderator
If you only require two alarm times, then an option is to consider thei2c interfaced DS3231 or DS3232 RTC chips.
These chips are also identified by Maxim (manufacturer) as "Extremely Accurate" parts.
This have two inbuilt alarms that can be configured to repeat on various selectable intervals.
If of interest try a forum search for an RTC comparison and Getting Started type tutorial which I posted some time ago with program examples.
 

jims

Senior Member
Authentic ...Here's a circuit you could use for "latching" as well as providing a "test" function for your feeder. Jimsfeeder circuit.JPG
 
Top