Intruder alarm system controller

From uCtrl
This page is kept for historical interest. It may document projects or methods that are obsolete and/or no longer relevant. The information here is not kept up-to-date.

This module was part of the rack box project — which was terminated when I moved out of my first apartment.
ALU installed in the Rack box

Information

ALU is a alarm central unit with two modes, see below. They can be activated with a key switch on the Rack status panel, when the key is turned green and red LED will toggle. If the key is turned again on green LED mode 1 is activated, and on red LED mode 2. Both modes can also be activated and deactivated from the User panel for alarm.

Mode 1

Away mode, this has no alarm function. When active the Rack status panel is turned off, system mute is active and lights in the apartment is turned off (via. Light control unit and Multi-purpose module 1). If it's dark in the light will turn on automatically if there is movement in the hall (via. Light control unit).

Mode 2

When activated the system counts down 6o seconds for you to leave the area. During this countdown the alarm LED and the green LED is flashing, short bursts from the buzzer. If a alarm or tamper input is active the alarm can not be turned on. If tamper should be activated during the countdown the buzzer will give long signals. When the countdown is complete the alarm is armed, the Rack status panel turns off, system mute is activated and the apartment lights is turned off (via. Light control unit).

When the alarm is triggered you have 30 seconds to deactivate, or the siren will sound. The alarm LED and red LED flash fast, long signals from the buzzer. If the tamper circuit is broken the siren will sound instantly. If it's dark in the light will turn on automatically if there is movement in the hall (via. Light control unit). If the alarm has been tripped the alarm LED will stay on until the alarm is activated again.

I/O

Inputs

  1. PD0 Key switch N.O
  2. PD1 Key switch N.C
  3. PD2 Alarm trigger N.C
  4. PD3 Buzzer trigger
  5. PD4 Trigger mode 1
  6. PD5 Trigger mode 2
  7. PD6 Tamper N.C

Outputs

  1. PB0 Alarm LED
  2. PB1 Green LED
  3. PB2 Red LED
  4. PB3 Buzzer in Rack status panel
  5. PB4 Siren
  6. PB5 Lights out to Light control unit
  7. PB6 Away mode relay
  8. PB7 Lifesignal (to Module stability monitoring unit 2)

D-Sub 9 pin

Connector 1

  1. 5V
  2. 0V
  3. In 1 (Key switch N.O)
  4. In 2 (Key switch N.C)
  5. In 3 (Alarm trigger N.C)
  6. In 4 (Buzzer trigger)
  7. In 5 (Trigger mode 1)
  8. In 6 (Trigger mode 2)
  9. +12V Status LED

Connector 2

  1. In 7 (Tamper N.C)
  2. Out 1 (Alarm LED)
  3. Out 2 (Green LED)
  4. Out 3 (Red LED)
  5. Out 4 (Buzzer in Rack status panel)
  6. Out 5 (Siren)
  7. Out 6 (Lights out to Light control unit)
  8. Out 7 (Away mode relay)
  9. Out 8 (Lifesignal)

Images

Schematic drawing

Intruder-alarm-circuit-46xxv4.png

Parts list

Qty. Part
1 AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
1 Capacitor, aluminium electrolytic, 10 µF, 25V
1 Capacitor, ceramic, 1 nF, 100V
1 D-Sub soldering cups, 9 pin female
2 D-Sub soldering cups, 9 pin male
1 DIL socket, 20-pin, 7.62mm
1 Enclosure, plastic (1591 FL), 120x65x40mm, flange
1 Fuse 5x20 mm, 400 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
1 LED 5mm coloured clear, Green, 2.1V, 20mA, 30mcd, 10°
2 LED 5mm, Red/Green, 2.0 2.1V, 10mA, 100 63mcd, 30°
3 LED holder 5mm, Black plastic
1 LED lamp 5mm, Red, Ø8.0mm, 12V, 20mA, 15mcd
32 cm2 PCB, stripboard, 100x160mm, 160cm2
10 Resistor, carbon film, 0.25W, 330 Ω, 5%
9 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
7 Resistor, carbon film, 0.25W, 10 kΩ, 5%
2 Spacer, round unthreaded, 3mm, Ø6mm, Delrin
21 Straight pin header, female, Single row, 2.54mm
23 Straight pin header, male, Single row, 2.54mm
8 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_ALU_v.1.0
' date: 07/11/2007
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
Config Portd = Input
Config Portb = Output
Config Watchdog = 1024

Dim Lifesignal As Byte , Alloff As Byte , Nokkel As Byte , Nokkel_turned As Byte
Dim Horn As Byte , Armed As Byte , Button1 As Byte , Button2 As Byte
Dim Modesel As Byte , A As Byte , Alarmled As Byte , Utlost As Byte , B As Byte

If Pind.0 = 0 Then Nokkel = 1
If Pind.1 = 0 Then Nokkel = 2
If Nokkel = 0 Then Portb.3 = 1

Do
Portb.0 = 1
Waitms 100
Gosub Doloop
Portb.0 = 0
If Nokkel_turned = 1 Then
   Nokkel_turned = 0
   Start Watchdog
   Goto Main
   End If
Waitms 100
Gosub Doloop
Loop

Main:
If Nokkel_turned = 1 And Armed = 0 Then 'key NO and NC
   Nokkel_turned = 0
   Portb.0 = 0
   For A = 1 To 7
   Portb.1 = 1
   Portb.2 = 0
   For B = 1 To 15
   Waitms 100
   Gosub Doloop
   Next B
   If Nokkel_turned = 1 Then Goto Selectmode
   Portb.1 = 0
   Portb.2 = 1
   For B = 1 To 15
   Waitms 100
   Gosub Doloop
   Next B
   If Nokkel_turned = 1 Then Goto Selectmode
   Next A
   Portb.1 = 0
   Portb.2 = 0
End If

If Nokkel_turned = 1 And Armed = 1 Then
   Nokkel_turned = 0
   Modesel = 0
   Armed = 0
   End If

If Modesel = 2 And Armed = 0 Then 'arm alarm
      If Pind.2 = 1 Or Pind.6 = 1 Then
      Horn = 10
      Modesel = 0
      Goto Main
      End If
   Utlost = 0
   For A = 1 To 60
   Portb.0 = 1
   Portb.1 = 1
   Portb.3 = 1
   Waitms 100
   Portb.3 = 0
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   If Pind.6 = 1 Then Portb.3 = 1
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Portb.0 = 0
   Portb.1 = 0
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Portb.3 = 0
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   If Nokkel_turned = 1 Then
      Nokkel_turned = 0
      Modesel = 0
      Goto Main
      End If
   Next A
      If Pind.2 = 1 Then
      Horn = 10
      Modesel = 0
      Goto Main
      End If
   Armed = 1
   Alloff = 5
   End If

If Armed = 1 Then Portb.6 = 1

If Armed = 1 And Modesel = 2 Then
   If Alarmled = 0 Then Alarmled = 10
   If Pind.2 = 1 Then Goto Alarm
End If

If Armed = 0 Then
   Portb.6 = 0
   If Utlost = 1 Then Portb.0 = 1
   If Modesel = 1 Then
      Alarmled = 10
      Armed = 1
      Alloff = 5
      End If
End If

Waitms 100
Gosub Doloop
Goto Main
End

Alarm: 'alarm triggered
   For A = 1 To 30
   Portb.0 = 1
   Portb.2 = 1
   Portb.3 = 1
   Waitms 100
   Portb.0 = 0
   Gosub Doloop
   Waitms 100
   Portb.0 = 1
   Gosub Doloop
   Waitms 100
   Portb.0 = 0
   Gosub Doloop
   Waitms 100
   Portb.0 = 1
   Gosub Doloop
   Waitms 100
   Portb.0 = 0
   Portb.2 = 0
   Portb.3 = 0
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   If Nokkel_turned = 1 Then
      Nokkel_turned = 0
      Modesel = 0
      Armed = 0
      Goto Main
      End If
   If Pind.6 = 1 Then Goto Sirene
   Next A

   Sirene:                                                  'siren
   For A = 1 To 60
   Utlost = 1
   Portb.0 = 1
   Portb.3 = 1
   Portb.4 = 1
   Waitms 100
   Portb.0 = 0
   Gosub Doloop
   Waitms 100
   Portb.0 = 1
   Gosub Doloop
   Waitms 100
   Portb.0 = 0
   Gosub Doloop
   Waitms 100
   Portb.0 = 1
   Gosub Doloop
   Waitms 100
   Portb.0 = 0
   Portb.3 = 0
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   Waitms 100
   Gosub Doloop
   If Nokkel_turned = 1 Then
      Nokkel_turned = 0
      Portb.4 = 0
      Modesel = 0
      Armed = 0
      Goto Main
      End If
   Next A
   Portb.4 = 0
   Goto Main

End

Selectmode: 'select mode
Nokkel_turned = 0
If Portb.1 = 1 Then Modesel = 1
If Portb.2 = 1 Then Modesel = 2
Portb.1 = 0
Portb.2 = 0
Goto Main
End

Doloop:
'Key turned
If Pind.0 = 0 And Pind.1 = 1 And Nokkel = 2 Then '1
   Nokkel = 1
   Nokkel_turned = 1
   End If
If Pind.0 = 1 And Pind.1 = 0 And Nokkel = 1 Then '2
   Nokkel = 2
   Nokkel_turned = 1
   End If

'Ext button 1
If Pind.4 = 0 And Button1 = 0 Then
   Button1 = 1
   If Modesel = 1 Then
      Nokkel_turned = 1
      Goto Endofbutton1
      End If
   If Modesel = 0 Then Modesel = 1
   Endofbutton1:
   End If
If Pind.4 = 1 Then Button1 = 0

'Ext button 2
If Pind.5 = 0 And Button2 = 0 Then
   Button2 = 1
   If Modesel = 2 Then
      Nokkel_turned = 1
      Goto Endofbutton2
      End If
   If Modesel = 0 Then Modesel = 2
   Endofbutton2:
   End If
If Pind.5 = 1 Then Button2 = 0

'Buzzer
If Pind.3 = 0 And Horn = 0 Then Horn = 10
If Horn = 10 Then Portb.3 = 1
If Horn = 7 Then Portb.3 = 0
If Horn > 0 Then Horn = Horn - 1

'All off
If Alloff = 5 Then Portb.5 = 1
If Alloff = 2 Then Portb.5 = 0
If Alloff > 0 Then Alloff = Alloff - 1

'AlarmLED
If Alarmled = 10 Then Portb.0 = 1
If Alarmled = 9 Then Portb.0 = 0
If Alarmled > 0 Then Alarmled = Alarmled - 1

'Lifesignal
If Lifesignal > 0 Then Lifesignal = Lifesignal - 1
If Lifesignal = 6 Then Portb.7 = 1
If Lifesignal = 1 Then Portb.7 = 0
If Lifesignal = 0 Then Lifesignal = 21

Reset Watchdog
Return
End