3 Zone Alarm using PICaxe 14M2 OLED and up-down-select switches

kando

Senior Member
Hi,

I wanted to have an alarm system to work on three separate areas it was actually two separate buildings and a garage. Each zone (building) would be covered by N/C Normally closed switches reed magnetic ones but equally they could be changed for whatever fits the zone.

I wanted to have an lcd screen and I chose an OLED 16x2 lines screen the budget one from RevEd. I tried to get the program to fit on an 08M2 but there is just not enough pins to do the job so I splashed out for a 14M2 Which just works with a couple of input pins left over.:rolleyes:

I wanted to be able to have two sirens. One that I could here inside and one that was external. I wanted the internal one to wake me but on a switch that I could turn off so I could hear my self think while dealt with the alarm. I wanted the external alarm to switch off after a set amount of time so as not to annoy the neighbours.

I wanted to be able to switch off one of the zone areas if I wanted to but still have the others alarmed and this to be shown on the OLED screen.

Now I am not saying I have achieved all this but it's pretty close. I have left the switching off of the external alarm after a certain amount of time because I haven't got around to it yet and I can't decide how best to do it. But hey, the rest seems to work so here it is.

Circuit diagram
Basic program in two halves because of limitations of forum.

I hope you enjoy dissecting it. Please tell me if you have other ways to do it.

Ken.:eek:

Code:
;directives
	#picaxe 14m2
;pinouts
;	                       +V |¯¯¯|0V
;		  serial in  ->c.5|===|b.0-> serial out *
;			*   <->c.4|===|b.1<->   *
;			*    ->c.3|===|b.2<->   *
;			*   <->c.2|===|b.3<->   * 
;			*   <->c.1|===|b.4<->   *
;			*   <->c.0|___|b.5<->   *
							;    * = pin used (Interrupts only on pins c.0,c.1,and c.2)
;OLED 16x2 screen positions				
;	|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|	
;	|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|	
;	|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|	
;	|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|
;	|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|

;for information this is stored in the 18M2 chip on the OLED board by Axe133.bas file
;EEPROM $20, ("Entry in Zone 1 ") 	;2 store msg in the EEPROM memory
;EEPROM $30, ("Entry in Zone 2 ") 	;3 store msg in the EEPROM memory
;EEPROM $40, ("Entry in Zone 3 ") 	;4 store msg in the EEPROM memory
;EEPROM $50, ("Code Not Correct") 	;5 store msg in the EEPROM memory
;EEPROM $60, ("All Zones Secure") 	;6 store msg in the EEPROM memory
;EEPROM $70, ("Monitoring Zones") 	;7 store msg in the EEPROM memory
;EEPROM $80, ("  Check Zones   ") 	;8 store msg in the EEPROM memory
;EEPROM $90, (" Alarm Disabled ") 	;9 store msg in the EEPROM memory
;EEPROM $A0, (" Alarm Enabled  ") 	;10 store msg in the EEPROM memory
;EEPROM $B0, ("This is msg 11  ") 	;11 store msg in the EEPROM memory
;EEPROM $C0, ("This is msg 12  ") 	;12 store msg in the EEPROM memory
;EEPROM $D0, ("This is msg 13  ") 	;13 store msg in the EEPROM memory
;EEPROM $E0, ("This is msg 14  ") 	;14 store msg in the EEPROM memory
;EEPROM $F0, ("This is msg 15  ") 	;15 store msg in the EEPROM memory
				
;constants
	symbol oled =	b.0			;OLED out pin
	symbol baud =	N2400
	symbol home = 	128			;leftmost position on topline OLED
	symbol base = 	192			;leftmost position on bottom line OLED
	symbol Siren=	b.4			;goes to internal siren speaker PWM out on this pin
	symbol LED1	=	b.5			;insecure zones LED
	symbol SirenSW =	pinc.4		;siren switch while dealing with alarm
	symbol sirenX  =	b.3			;Xternal siren on a relay

;variables
	symbol Slct	=	b0			;button selection
	symbol nPos	=	b1			;new position
	symbol oPos =	b2			;old position
	symbol Slct2=	b3			;enable/disable menu selection
	symbol Up	=	pinb.1		;input switch up button
	symbol Down	=	pinb.2		;input switch down button
	symbol btnS	=	pinc.3 		;input switch select/enter button
	symbol Z1	=	pinc.0		;input zone1 switches
	symbol Z2	=	pinc.1		;input zone2 switches
	symbol Z3	=	pinc.2		;input zone3 switches
	symbol Z1f	=	b20			; zone 1 tick or cross
	symbol Z2f	=	b21			; zone 2 tick or cross
	symbol Z3f	=	b23			; zone 3 tick or cross
	symbol Z1disabled=b24			;zone 1 has been disabled if true
	symbol Z2disabled=b25			;zone 2 has been disabled if true
	symbol Z3disabled=b26			;zone 3 has been disabled if true
;boolean
	symbol true = 	1
	symbol false =	0
;initialise variables
	nPos = 127
	oPos = 143
;initialise CGRAM characters
	pause 1000
;	serout oled,baud, (254, 112, 33, 33, 33, 35, 51, 59, 46, 38);14 tick
	pause 1000
;	serout oled,baud, (254, 120, 49, 42, 36, 36, 36, 42, 49, 32);15 cross
	pause 1000
init:

	if Z1 = 0 and Z2 = 0 and Z3 = 0 then			;if zone switches are closed then zone ok
		serout oled,baud, (254,1)				;clear display when reset
		pause 30
		serout oled,baud,(254,home)				;set position for eeprom message
		serout oled,baud,(253,6)				;display message from eeprom in 18m2 to the oled
		;or use this instead serout oled,baud, (254,home,"Hello Zone Alarm");show reset entry message
		Pause 1000		
		setint or %00000111,%00000111				;set interupt on c.0 or c.1 or c.2 high interrupt
		serout oled,baud,(254,base)				;set position for eeprom message
		serout oled,baud,(253,7)				;display message from eeprom in 18m2 to the oled
		;or use this instead serout oled,baud, (254,home," Select menu >  ")
	else
										;One of the Zones are Insecure
		serout oled,baud,(254,home)				;set position for eeprom message
		serout oled,baud,(253,4)				;display message from eeprom in 18m2 to the oled
		;serout oled,baud, (254,home,"Zone/s Insecure ")
		pause 5
		serout oled,baud, (254,base)				;set position for eeprom message
		serout oled,baud, (253,8)				;Check zones display message from eeprom in 18m2 to the oled
		High LED1
		pause 5000
		reset
	endif
	
	gosub enabled	;tests whether zone switches are closed or open and stores result Z1f Z2f Z3f
	gosub welcome	;displays the first zone menus

main:	
	; select button pressed
	if down = 1 then
		Slct = Slct + 1
		if Slct > 2 then
			Slct = 0
		end if
		gosub position
	end if
	
	if up = 1 then
		Slct = Slct - 1
		if Slct > 2 then
			Slct = 2
		end if
		gosub position
	end if
	if btnS = 1 then
		on Slct gosub Zone1, Zone2, Zone3
	end if
	
	goto main
end
Subroutines in next message...
 

Attachments

kando

Senior Member
Next bit of program.....

Code:
;subroutines under here 
;==================================================================

interrupt:
	pause 20
	low LED1 				;One of the zones is now insecure
	pause 200
	High LED1
	
	serout oled,baud, (254,1)				;clear display
	pause 30
	serout oled,baud,(254,home)				;set position for eeprom message
	pause 5
	if 	  Z1=1 then
		serout oled,baud,(253,2);entry in zone 1
		pause 30
	else if Z2=1 then
		serout oled,baud,(253,3);entry in zone 2
		pause 30
	else if Z3=1 then
		serout oled,baud,(253,4);entry in zone 3
		pause 30
	endif
	
	;next bit is for switch to turn off sound while dealing with alarm
	if SirenSW = 1 then 
		pwmout siren,off			;turn internal siren off 
		goto interrupt
	endif 
	
								;xternal siren could be latched on at relay 
								;or write some code to put in timings
	if Z1 = 0 and Z2 = 0 and Z3 = 0 then 	;all zone switches are reset 
		setint or %00000111,%00000111 	;reset interrupt on zones looking for highs
		low LED1 					;turn off insecure zones LED1
		pwmout siren,off				;turn off internal siren
		low sirenX;					;turn Xternal siren off
		gosub welcome
		return 					;come out of interrupt
	endif 						;go back to normal
	
	;switch on Xternal siren
	high sirenX
	;how long should it stay on for? 
	;5 minutes on then 5 minutes off then 5 minutes on then off altogether.
	; code to do this here...
	
	
	
	'sound internal siren
	for w0 = 160 to 80 step -1 
		W1 = w0 * 3
	      pwmout pwmdiv4, siren, w0, w1
	      pause 5
	next
	for w0 = 80 to 160 
		W1 = w0 * 3
	      pwmout pwmdiv4, siren, w0, w1
	      pause 5
	next
	
	setint or %00000111,%00000111 ; reset interrupt on zones
	return
return
	
Zone1:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z1disabled=true then ;zone is disabled
		Z1f=15
	endif   
	serout oled,baud, (254,home,"Zone 1  [Set ",Z1f,"]")
	pause 5
	
	select case Z1f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return
	
Zone2:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z2disabled=true then ;zone is disabled
		Z2f=15
	endif   
	serout oled,baud, (254,home,"Zone 2  [Set ",Z2f,"]")
	pause 5
	
	select case Z2f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return
	
Zone3:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z3disabled=true then ;zone is disabled
		Z3f=15
	endif   
	serout oled,baud, (254,home,"Zone 3  [Set ",Z3f,"]")
	pause 5
	
	select case Z3f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return

enabled:
	if Z1 = 0 then 
		Z1f = 14 
		if Z1disabled=true then 
			Z1f=15
		endif   ;zone is disabled
	else 
		Z1f = 15
	endif
	if Z2 = 0 then 
		Z2f = 14
		if Z2disabled=true then 
			Z2f=15
		endif   ;zone is disabled 
	else 
		Z2f = 15
	endif
	if Z3 = 0 then
		Z3f = 14
		if Z3disabled=true then
			Z3f=15
		endif   ;zone is disabled
	else
		Z3f = 15
	endif
return	

welcome:
	pause 10
	serout oled,baud, (254,1)		;clear display after reset entry message
	pause 30	
	;show the menus for zones
	serout oled,baud, (254,129,"Zone 1",254,137,"Zone 2",254,193,"Zone 3",254,201,"1 2 3 ")
	gosub enabled ;tests whether zone switches are closed or open and stores result Z1f Z2f Z3f
	serout oled,baud, (254,201)
	serout oled,baud, ("1",Z1f,"2",Z2f,"3",Z3f);put ticks or crosses in the display
	gosub position						;shows the blinking >
return

enable_disable_menu_btns:
	do until btnS = 1
	; select button pressed
	if down = 1 then
		Slct2 = Slct2 + 1
		if Slct2 > 1 then
			Slct2 = 0
		end if
		gosub position2
	end if
	
	if up = 1 then
		Slct2 = Slct2 - 1
		if Slct2 > 1 then
			Slct2 = 1
		end if
		gosub position2
	end if
	loop
	on Slct2 gosub EnableDisableZone, welcome
return

position:						;shows the blinking char on first zones menu
	lookup Slct, (128,136,192,200),nPos ;home line,base line
	serout oled,baud, (254,oPos,32,254,nPos,62); 32=space " ";62= ">"
;	serout oled,baud, (254,nPos,254,13); simulated lcd does not have blink character command
	let oPos = nPos
	pause 500
	
return

position2: 						;shows the blinking > in the second zone menu
	lookup Slct2, (192,201),nPos		;note only base line
	serout oled,baud, (254,oPos,32,254,nPos,62); 32=space " ";62= ">"
;	serout oled,baud, (254,nPos,254,13)	;simulated lcd does not have blink character command
	let oPos = nPos
	pause 500	
return

EnableDisableZone:
	serout oled,baud, (254,1)
	pause 30
	select case Slct ;which zone are we talking about
	case 0 ;zone1
		if Z1F=14 then 			;tick enabled change over to cross and disable zone
			Z1f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z1f,"]")
			pause 5
			Z1disabled=true
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000110,%00000110 ; set interrupt on zone
		else
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z1disabled=false
			setint or %00000111,%00000111 ; reset interrupt on zone
		endif
	case 1 ;zone2
		if Z2F=14 then 			;tick enabled change over to cross and disable zone
			Z2f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z2f,"]")
			pause 5
			Z2disabled=true
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000101,%00000101 ; set interrupt on zone
		else
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z2disabled=false
			setint or %00000111,%00000111 ; reset interrupt on zone
		endif	
	case 2 ;zone3
		if Z3F=14 then 			;tick enabled change over to cross and disable zone
			Z3f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z3f,"]")
			pause 5
			Z3disabled=true
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;Alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000011,%00000011 ; set interrupt on zone
		else
			serout oled,baud, (254,base)				;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z3disabled=false
			setint or %00000111,%00000111 ; reset interrupt on zone
		endif
	end select
return
 

westaust55

Moderator
Well done on achieving your working project and thank you for posting the details.

From time to time, forum members come looking for information on building alarm systems and this may form a starting point for them.

You may even wish to add a few photos and put your project into the Monthly Projects Competition:
http://www.picaxe.com/Project-Gallery/Submit
 

kando

Senior Member
Thanks for that Westy,
I have actually revamped the program and it works better now. I took Alley-cats direction on the interrupt making it hand back control to the main program as soon as possible. In this case it was within one line!

I will post the finished version on line later today.
It has some improvements over the old one.
Ken.:)
 

kando

Senior Member
3 Zone Alarm

Works with 3 separate zoned areas (3 rooms, 3 buildings etc) Each zone should have two wires returning to the micro control box. Each zone should have it&#8217;s own Normally closed switches on the windows /doors areas to be protected.

It has an OLED lcd 16x2 screen for messages to be displayed from the program.
It uses the OLED for a small Menu system. A simple 3 button up-down-select system.

A two position thumb slide switch to turn off the internal alarm siren and to reset the alarm system when needed.

Sometimes one area needs to be disabled while keeping the other areas still working. This is achieved through the 3 button up-down-select menu. The area disabled is shown with a cross on the first menu screen when disabled otherwise all zones are shown with a tick.

The external alarm siren now shuts off after a certain time changed within the program if needed. It will start and stop this external alarm siren so you have &#8220;On&#8221; for a time then &#8220;off&#8221; for a time. This happens 3 times before it stops altogether. The number of times can be changed within the program.

The Circuit diagram is the same as before.

The Basic program is in two halves because of limitations of forum. The second half has the subroutines.

Some pictures after that.

I hope you enjoy trying it. Pulling it apart for your own use and coming up with some other ideas.

First part of code...
Code:
;directives
	#picaxe 14m2
;pinouts for information
;		               +V |¯¯¯|0V
;		  serial in  ->c.5|===|b.0-> serial out *
;			*   <->c.4|===|b.1<->   *
;			*    ->c.3|===|b.2<->   *
;			*   <->c.2|===|b.3<->   * 
;			*   <->c.1|===|b.4<->   *
;			*   <->c.0|___|b.5<->   *
							;    * = pin used (Interrupts only on pins c.0,c.1,and c.2)
							;	PWM on B.4
;OLED 16x2 screen positions for information				
;	|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|	
;	|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|	
;	|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|	
;	|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|
;	|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|

;for information this is stored in the 18M2 chip on the OLED board by Axe133.bas file
;EEPROM $20, ("Entry in Zone 1 ") 	;2 store msg in the EEPROM memory
;EEPROM $30, ("Entry in Zone 2 ") 	;3 store msg in the EEPROM memory
;EEPROM $40, ("Entry in Zone 3 ") 	;4 store msg in the EEPROM memory
;EEPROM $50, ("Code Not Correct") 	;5 store msg in the EEPROM memory;not used in this program, (reserved)
;EEPROM $60, ("All Zones Secure") 	;6 store msg in the EEPROM memory
;EEPROM $70, ("Monitoring Zones") 	;7 store msg in the EEPROM memory
;EEPROM $80, ("  Check Zones   ") 	;8 store msg in the EEPROM memory
;EEPROM $90, (" Alarm Disabled ") 	;9 store msg in the EEPROM memory
;EEPROM $A0, (" Alarm Enabled  ") 	;10 store msg in the EEPROM memory
;11 to 15 not used
				
;constants
	symbol oled =	b.0			;OLED out pin
	symbol baud =	N2400			;Baud rate set for ease of programming
	symbol home = 	128			;leftmost position on topline OLED
	symbol base = 	192			;leftmost position on bottom line OLED
	symbol Siren=	b.4			;goes to internal siren speaker PWM out on this pin
	symbol LED1	=	b.5			;insecure zones LED
	symbol SirenSW =	pinc.4		;siren switch while dealing with alarm
	symbol sirenX  =	b.3			;Xternal siren on a relay

;variables
	symbol Slct	=	b0			;button selection
	symbol nPos	=	b1			;new position
	symbol oPos =	b2			;old position
	symbol Slct2=	b3			;enable/disable menu selection
	symbol Up	=	pinb.1		;input switch up button
	symbol Down	=	pinb.2		;input switch down button
	symbol btnS	=	pinc.3 		;input switch select/enter button
	symbol Z1	=	pinc.0		;input zone1 switches
	symbol Z2	=	pinc.1		;input zone2 switches
	symbol Z3	=	pinc.2		;input zone3 switches
	symbol AlarmInput=b16			;alarm flag for entry to zones
	symbol AlarmOn   =b17			;alarm already activated flag
	symbol Z1f	=	b18			; zone 1 tick or cross
	symbol Z2f	=	b19			; zone 2 tick or cross
	symbol Z3f	=	b20			; zone 3 tick or cross
	symbol Z1disabled=b21			;zone 1 has been disabled if true
	symbol Z2disabled=b22			;zone 2 has been disabled if true
	symbol Z3disabled=b23			;zone 3 has been disabled if true
	symbol TimeOff =	b24			;toggle flag for off/on  external alarm
	symbol TimeFlag = b25			;Number of times to sound external alarm
;boolean
	symbol true = 	1
	symbol false =	0
;initialise variables
	nPos = 127
	oPos = 143
	AlarmInput=false
	AlarmOn=false
	TimeOff=false
	timeFlag=0
;initialise CGRAM characters
	pause 1000
	serout oled,baud, (254, 112, 33, 33, 33, 35, 51, 59, 46, 38);14 tick; does not work in simulator
	pause 1000
	serout oled,baud, (254, 120, 49, 42, 36, 36, 36, 42, 49, 32);15 cross; does not work in simulator
	pause 1000
init:
		;NOTE: messages stored in 18M2 eeprom do not display in simulator
	if Z1 = 0 and Z2 = 0 and Z3 = 0 then			;if zone switches are closed then zone ok
		serout oled,baud, (254,1)				;clear display when reset
		pause 30
		serout oled,baud,(254,home)				;set position for eeprom message
		serout oled,baud,(253,6)				;display message from eeprom in 18m2 to the oled
		;or use this instead serout oled,baud, (254,home,"Hello Zone Alarm");show reset entry message
		Pause 1000		
		setint or %00000111,%00000111				;set interupt on c.0 or c.1 or c.2 high interrupt
		serout oled,baud,(254,base)				;set position for eeprom message
		serout oled,baud,(253,7)				;display message from eeprom in 18m2 to the oled
		;or use this instead serout oled,baud, (254,home," Select menu >  ")
	else
										;One of the Zones are Insecure
		serout oled,baud,(254,home)				;set position for eeprom message
		serout oled,baud,(253,4)				;display message from eeprom in 18m2 to the oled
		;serout oled,baud, (254,home,"Zone/s Insecure ")
		pause 5
		serout oled,baud, (254,base)				;set position for eeprom message
		serout oled,baud, (253,8)				;Check zones display message from eeprom in 18m2 to the oled
		High LED1
		pause 5000
		reset
	endif
	
	
	gosub enabled	;tests whether zone switches are closed or open and stores result Z1f Z2f Z3f
	gosub welcome	;displays the first zone menus

main:	
					;which buttons up-down-select are being pressed
	if down = 1 then
		Slct = Slct + 1
		if Slct > 2 then 
			Slct = 0
		end if
		gosub position
	end if
	
	if up = 1 then
		Slct = Slct - 1
		if Slct > 2 then
			Slct = 2
		end if
		gosub position
	end if
	if btnS = 1 then
		on Slct gosub Zone1, Zone2, Zone3	;when the select button is pressed then go to one of these
	end if
	
					;if AlarmInput = true then the interrupt has been triggered
	if AlarmInput=true then gosub startAlarm	;one of the zone switches have been opened
	
	goto main
end
 

kando

Senior Member
second part of code...
Code:
;subroutines under here 
;==================================================================

interrupt: ;for info. Bug in system... pause does not work under interrupt in multi processing
		;start0,start1 etc.
AlarmInput =true ;set alarm flag because entry to zones has been made
return	;hand control back to main program

; end of interrupt routine  =================================================

startAlarm:
	if alarmon = true then 				; alarm already activated
		select case Timeoff
			case  true 
							; make first number of time 20 less than the Time on value below
							;second number is number of times external alarm will sound
			if time >= 30 and timeFlag <= 2 then ;2=sound 3 times only
				gosub soundXternalAlarm
				timeoff = false
				inc timeflag
			endif
		endselect
		
		gosub SoundInternalAlarm 		;sound the internal alarm
								;next bit is for slide switch to turn off sound and reset alarm
		if SirenSW = 1 then 
			pwmout siren,off						;turn internal siren off 
				if Z1 = 0 and Z2 = 0 and Z3 = 0 then 	;all zone switches are reset 
					setint OR %00000111,%00000111 	;reset interrupt on zones looking for highs
					low LED1 					;turn off insecure zones LED1
					low sirenX					;turn Xternal siren off
					AlarmInput = false			;reset
					AlarmOn=false				;reset
					timeFlag=0					;reset			
					gosub welcome				;reset
				endif			
		endif	
			if time >= 50 then 			; time on before switch off 300=5 mins
				timeoff = true			;toggle flag for off /on of external alarm
				gosub alarmtimeout		; switch off external alarm for set period
				
			endif
	return
	else
		gosub soundXternalAlarm	
	endif						

	High LED1							;switch on insecure zone LED
	
	serout oled,baud, (254,1)				;clear display
	pause 30
	serout oled,baud,(254,home)				;set position for eeprom message
	pause 5
	if 	  Z1=1 then
		serout oled,baud,(253,2)			;entry in zone 1 words from 18M2
		pause 30
	else if Z2=1 then
		serout oled,baud,(253,3)			;entry in zone 2 words from 18M2
		pause 30
	else if Z3=1 then
		serout oled,baud,(253,4)			;entry in zone 3 words from 18M2
		pause 30
	endif
	
	setint or %00000111,%00000111 			; reset interrupt on zones to keep checking
return

SoundInternalAlarm:
;#rem if not using internal siren then remark out
	'sound internal siren PWM on pin "siren"
	for w0 = 160 to 80 step -1 
		W1 = w0 * 3
	      pwmout pwmdiv4, siren, w0, w1
	      pause 5
	next
	for w0 = 80 to 160 
		W1 = w0 * 3
	      pwmout pwmdiv4, siren, w0, w1
	      pause 5
	next
return
;#endrem

soundXternalAlarm:
	high SirenX   				; sound the alarm
	AlarmOn = true				; flag to mark that alarm has been triggered
	time = 0 					; set system variable "time" to zero
return

alarmtimeout:
	low SirenX					; turn off the external alarm
	time = 0 					; set system variable "time" to zero
return	
	
	
Zone1:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z1disabled=true then 		;zone is disabled
		Z1f=15
	endif   
	serout oled,baud, (254,home,"Zone 1  [Set ",Z1f,"]")
	pause 5
	
	select case Z1f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return
	
Zone2:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z2disabled=true then 		;zone is disabled
		Z2f=15
	endif   
	serout oled,baud, (254,home,"Zone 2  [Set ",Z2f,"]")
	pause 5
	
	select case Z2f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return
	
Zone3:
	serout oled,baud, (254,1)
	pause 30
	gosub enabled
	if Z3disabled=true then 		;zone is disabled
		Z3f=15
	endif   
	serout oled,baud, (254,home,"Zone 3  [Set ",Z3f,"]")
	pause 5
	
	select case Z3f
	case 14 	serout oled,baud, (254,base," Disable")
			serout oled,baud, (254,201," Back")
	case 15 	serout oled,baud, (254,base," Enable ")
			serout oled,baud, (254,201," Back")
	endselect
	gosub position2				;display the blinking character >
	gosub enable_disable_menu_btns
	gosub welcome
return

enabled:
	if Z1 = 0 then 
		Z1f = 14 
		if Z1disabled=true then 
			Z1f=15
		endif   				;zone is disabled
	else 
		Z1f = 15
	endif
	if Z2 = 0 then 
		Z2f = 14
		if Z2disabled=true then 
			Z2f=15
		endif   				;zone is disabled 
	else 
		Z2f = 15
	endif
	if Z3 = 0 then
		Z3f = 14
		if Z3disabled=true then
			Z3f=15
		endif   				;zone is disabled
	else
		Z3f = 15
	endif
return	

welcome:
	pause 10
	serout oled,baud, (254,1)		;clear display after reset entry message
	pause 30	
							;show the menus for zones
	serout oled,baud, (254,129,"Zone 1",254,137,"Zone 2",254,193,"Zone 3",254,201,"1 2 3 ")
	gosub enabled ;tests whether zone switches are closed or open and stores result Z1f Z2f Z3f
	serout oled,baud, (254,201)
	serout oled,baud, ("1",Z1f,"2",Z2f,"3",Z3f);put ticks or crosses in the display
	gosub position						;shows the blinking >
return

enable_disable_menu_btns:
	do until btnS = 1
					;which buttons up-down-select are being pressed on the second menu screen
	if down = 1 then
		Slct2 = Slct2 + 1
		if Slct2 > 1 then
			Slct2 = 0
		end if
		gosub position2
	end if
	
	if up = 1 then
		Slct2 = Slct2 - 1
		if Slct2 > 1 then
			Slct2 = 1
		end if
		gosub position2
	end if
	loop
	on Slct2 gosub EnableDisableZone, welcome ;when the select button is pressed got to one of these
return

position:								;shows the blinking char on first zones menu
	lookup Slct, (128,136,192,200),nPos 		;home line,base line
	serout oled,baud, (254,oPos,32,254,nPos,62)	; 32=space " ";62= ">"
	serout oled,baud, (254,nPos,254,13)			; does not work in simulator (CGRAM Char)
	let oPos = nPos
	pause 200
	
return

position2: 								;shows the blinking > in the second zone menu
	lookup Slct2, (192,201),nPos				;note only base line
	serout oled,baud, (254,oPos,32,254,nPos,62)	; 32=space " ";62= ">"
	serout oled,baud, (254,nPos,254,13)			;does not work in simulator (CGRAM Char)
	let oPos = nPos
	pause 200	
return

				;NOTE: messages stored in 18M2 eeprom do not display in simulator
EnableDisableZone:
	serout oled,baud, (254,1)
	pause 30
	select case Slct 						;which zone are we talking about
	case 0 ;zone1
		if Z1F=14 then 					;tick enabled change over to cross and disable zone
			Z1f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z1f,"]")
			pause 5
			Z1disabled=true
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000110,%00000110 	; set interrupt on zone
		else
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z1disabled=false
			setint or %00000111,%00000111 	; reset interrupt on zones
		endif
	case 1 ;zone2
		if Z2F=14 then 					;tick enabled change over to cross and disable zone
			Z2f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z2f,"]")
			pause 5
			Z2disabled=true
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000101,%00000101 	; set interrupt on zone
		else
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z2disabled=false
			setint or %00000111,%00000111 	; reset interrupt on zones
		endif	
	case 2 ;zone3
		if Z3F=14 then 					;tick enabled change over to cross and disable zone
			Z3f=15 ;cross
			serout oled,baud, (254,home,"Zone 2  [Set ",Z3f,"]")
			pause 5
			Z3disabled=true
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,9)		;Alarm disabled display message from eeprom in 18m2 to the oled
			pause 5
			setint or %00000011,%00000011 	; set interrupt on zone
		else
			serout oled,baud, (254,base)		;set position for eeprom message
			pause 3
			serout oled,baud,(253,10)		;alarm enabled display message from eeprom in 18m2 to the oled
			pause 5
			Z3disabled=false
			setint or %00000111,%00000111 	; reset interrupt on zones
		endif
	end select
return

Pictures
First of Test Rig I used. This shows the black Piezo sounder used as internal siren with PWM code White Piezo sounder working through blue relay. This is used as the external siren and is powered by the 9Vpp3 battery. On a real outside siren you may have to add oscillating electronics or buy one with those already in the siren.

The next set of pictures shows the working OLED menu system. 1.Startup screen menu, 2. Disable alarm screen menu, 3, Start screen again showing that one of zones has been disabled.

Picaxe Test Rig.jpgOLED startupscreen.jpg
 
Last edited:

kando

Senior Member
Another picture showing what happens when one of the zones is entered. The slide switch will turn this off and reset to the first screen after you have seen the problem.
OLED Entry in zone.jpg
 

kando

Senior Member
Zone1, Zone2 and Zone3 can be attached to magnetic switches or infra-red or any other type of monitoring of the zones. (some extra power may be needed if you want to use movement sensors etc.). The external siren can be of a type you choose as it is attached to the CN1 connection shown on this attached diagram. Again the power source will be suitable for that siren and attached to CN2. I have shown this as 8 to 12V. It all fits onto a pretty small strip board and there is not a lot of soldering.

Here is the Schematic using Circuit wizard.
If anyone wants the cwz file I can send it to you.
Picaxe 3 zone alarm using 14M2.jpg
 
Last edited:

jhowe

New Member
Kando,

Thanks for posting this, I have been thinking about playing around with making a home security type system. The only thing I would add, and I have been trying to do is add a (EOLR)End Of Line Resistor to a system.

I have been trying the DAC commands and FVR, but can't seem to make anything happen. This is probably a little advanced for me, but seeing this post I thought I would pose the problem to you.
 

hippy

Technical Support
Staff member
You shouldn't need to use DAC or FVR to create an EOLR zone sensor setup. Just add the resistor network for each zone sensor and then read the signal via a READADC command. Something like below, though I am not sure of ideal resistor values ...

Code:
                               ___
        )-----------------.---|___|--- +V
   N/O              ___   |
        )------.---|___|--'
               |               ___
               }--------------|___|---> ADC
               |    ___
        )------^---|___|--.
   N/C                    |    ___
        )-----------------^---|___|--- 0V
Usefulness of EOLR is debatable and it has to be done well to detect all possible bypass attempts. EOLR systems may detect simple cutting and shorting wires attacks but may not catch others.
 

zorgloub

Member
Good evening to the Community,

I stumble upon this Post after performing a search on a simple alarm system.
This post is a good base but, unless I'm mistaken, I do not see in this program the procedure to determine the delay to arm the system when leaving the area, nor the time setting to disarm it when an authorized person enters into the zone.

Do you have something like that in your brain?

Thanks
-------------------------------
 
Top