Security keypad with programmable PIN

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.
Security keypad with programmable PIN

Information

UPA is a user panel for Alarm unit, where the user can enter his/her PIN and activate mode 1 (away mode) or 2 (intruder alarm). The module is monitored by Module stability monitoring unit 2 and a tamper circuit, this will give instant alarm if disconnected. It's not possible to activate mode 2 (intruder alarm) if UPA is disconnected. The PIN is stored in EEPROM and saved trough a power loss.

Mode 1

To activate mode 1 enter PIN + *, a one second green light indicates approved PIN and confirms command.

Mode 2

To activate mode 2 enter PIN + #, a two seconds green light indicates approved PIN and confirms command.

Change PIN

To change PIN enter current PIN + 0, yellow light indicates programming mode. The new PIN is entered and confirmed with #, green light. Any other button will reject the new code and keep the old one, red light indicates this.

When entering wrong PIN

When the wrong PIN is entered you get a red light. If the wrong PIN is entered three times the panel will not be usable for one minute. The red light will flash during this period.

I/O

Inputs

  1. PD2 Keypad 1
  2. PD3 Keypad 2
  3. PD4 Keypad 3
  4. PD5 Keypad 4

Outputs

  1. PB0 Keypad 1
  2. PB1 Keypad 2
  3. PB2 Keypad 3
  4. PB3 Channel 1
  5. PB4 Channel 2
  6. PB5 Green LED
  7. PB6 Red LED
  8. PB7 Lifesignal (to Module stability monitoring unit 2)

D-Sub 9-pin

Pin Color Function
1. Pink 5V
2. Grey 0V
3. Yellow Channel 1
4. Black Channel 2
5. Green Tamper N.C
6. Blue Lifesignal (to Module stability monitoring unit 2)
7. Red Alarm LED from Alarm unit
8. Purple Green LED from Alarm unit
9. Brown Red LED from Alarm unit

Keypad

Keypad-internal-connections-and-dimensions-kq06dq.jpeg
  1. n/a
  2. K3
  3. K2
  4. K1
  5. R1
  6. R2
  7. R3
  8. R4

Images

Schematic drawing

Security-keypad-circuit-149v9g.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 m Control cable, 10-cores, 0.14mm2, 250 V, Ø 5.4mm
1 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, wire, 5x20 / 6.3x32mm
1 Keypad, 12 buttons, 4x3, AK-804
1 LED 5mm clear, Red, 2.0V, 20mA, 140mcd, 6°
3 LED 5mm, Red/Green, 2.0 2.1V, 10mA, 100 63mcd, 30°
3 LED holder 5mm, Black plastic
1 LED holder 5mm, Chrome-plated plastic, reflector
32 cm2 PCB, stripboard, 100x160mm, 160cm2
8 Resistor, carbon film, 0.25W, 330 Ω, 5%
4 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
4 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 Resistor, metal film, 0.6W, 200 Ω, 1%
1 Spacer, round unthreaded, 3mm, Ø6mm, Delrin
16 Straight pin header, female, Single row, 2.54mm
16 Straight pin header, male, Single row, 2.54mm
3 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B

Source code

Template:Basic code

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

Dim Lifesignal As Byte , Number As Byte , Row As Byte , Button As Byte
Dim Code1 As Integer , Code2 As Integer , Code3 As Byte , Code4 As Byte , Nr As Byte
Dim Redled As Byte , Greenled As Byte , Amberled As Byte , Code As Integer
Dim Code_p As Integer , Kanal1 As Byte , Kanal2 As Byte , Timeout As Byte , Feil As Integer
Dim Eeprom As Eram Integer , Program As Byte , Feil_a As Byte

Code_p = Eeprom 'Get stored code
If Code_p < 0 Then Code_p = 1234 'If no code use default
Number = 255

'Boot
Portb = 0

Start Watchdog

Main:
'Read keypad
If Button = 0 And Feil = 0 And Number = 255 Then

If Row = 0 Then 'Keyboard row 1
   Portb.0 = 1
   If Pind.5 = 1 Then Number = 10
   If Pind.4 = 1 Then Number = 7
   If Pind.3 = 1 Then Number = 4
   If Pind.2 = 1 Then Number = 1
   Portb.0 = 0
   End If

If Row = 1 Then 'Keyboard row 2
   Portb.1 = 1
   If Pind.5 = 1 Then Number = 0
   If Pind.4 = 1 Then Number = 8
   If Pind.3 = 1 Then Number = 5
   If Pind.2 = 1 Then Number = 2
   Portb.1 = 0
   End If

If Row = 2 Then 'Keyboard row 3
   Portb.2 = 1
   If Pind.5 = 1 Then Number = 11
   If Pind.4 = 1 Then Number = 9
   If Pind.3 = 1 Then Number = 6
   If Pind.2 = 1 Then Number = 3
   Portb.2 = 0
   End If

Row = Row + 1 'Next row
If Row > 2 Then Row = 0
End If

'Reset button status
Portb.0 = 1
Portb.1 = 1
Portb.2 = 1
If Pind.2 = 0 And Pind.3 = 0 And Pind.4 = 0 And Pind.5 = 0 Then Button = 0
Portb.0 = 0
Portb.1 = 0
Portb.2 = 0

'Get code
If Number <> 255 Then
Button = 1
Select Case Nr
   Case 0                                                   'Digit 1
   Code1 = Number
   Code1 = Code1 * 1000
   Code = Code1 + Code
   Amberled = 4
   Case 1                                                   'Digit 2
   Code2 = Number
   Code2 = Code2 * 100
   Code = Code2 + Code
   Amberled = 4
   Case 2                                                   'Digit 3
   Code3 = Number
   Code3 = Code3 * 10
   Code = Code3 + Code
   Amberled = 4
   Case 3                                                   'Digit 4
   Code4 = Number
   Code = Code4 + Code
   Amberled = 4

   Case 4
   If Program = 1 Then                                      'Program new code
      Select Case Number
         Case 11                                            'Accept
         Code_p = Code
         Eeprom = Code_p
         Greenled = 60
         Case Else                                          'Reject
         Redled = 30
         End Select
      Number = 255
      Program = 0
      Gosub Reset_code_read
      Goto Main
      End If
   If Code = Code_p Then                                    'Code correct
   Feil_a = 0
      Select Case Number
         Case 0                                             'New code
         Program = 1
         Amberled = 40
         Case 10                                            'Channel 1
         Kanal1 = 20
         Greenled = 20
         Case 11                                            'Channel 2
         Kanal2 = 20
         Greenled = 40
         Case Else                                          'Reject
         Redled = 30
         End Select
   Else                                                     'Code failed
      Redled = 30
      Feil_a = Feil_a + 1
   End If
   Timeout = 0
   Number = 255
   Gosub Reset_code_read
   Goto Main
End Select
Nr = Nr + 1
Number = 255
End If

'Timeout when entering code
If Nr > 0 And Timeout = 0 Then Timeout = 201
If Timeout > 0 Then Timeout = Timeout - 1
If Timeout = 1 And Nr <> 0 Then
   Gosub Reset_code_read
   Number = 255
   Redled = 30
   End If

'Error handling, 3 wrong codes
If Feil_a > 3 And Feil = 0 Then
   Feil = 1200
   Feil_a = 0
   End If
If Feil > 0 And Redled = 0 Then Redled = 4
If Feil > 0 Then Feil = Feil - 1

'AmberLED
If Amberled > 0 Then
   Greenled = Amberled
   Redled = Amberled
   Amberled = 0
   End If

'GreenLED
If Greenled > 2 Then Portb.5 = 1
If Greenled = 2 Then Portb.5 = 0
If Greenled > 0 Then Greenled = Greenled - 1

'RedLED
If Redled > 2 Then Portb.6 = 1
If Redled = 2 Then Portb.6 = 0
If Redled > 0 Then Redled = Redled - 1

'Channel1
If Kanal1 = 20 Then Portb.3 = 1
If Kanal1 = 1 Then Portb.3 = 0
If Kanal1 > 0 Then Kanal1 = Kanal1 - 1

'Channel2
If Kanal2 = 20 Then Portb.4 = 1
If Kanal2 = 1 Then Portb.4 = 0
If Kanal2 > 0 Then Kanal2 = Kanal2 - 1

'Lifesignal
If Lifesignal > 0 Then Lifesignal = Lifesignal - 1
If Lifesignal = 12 Then Portb.7 = 1
If Lifesignal = 1 Then Portb.7 = 0
If Lifesignal = 0 Then Lifesignal = 41

Reset Watchdog
Waitms 50
Goto Main 'Loop cycle
End

Reset_code_read: 'Reset code param.
   Nr = 0
   Code = 0
   Code1 = 0
   Code2 = 0
   Code3 = 0
   Code4 = 0
Return
End