I have started migrating content to my Hugo blog at https://blog.cavelab.dev, already migrated pages will redirect there.

Security keypad with programmable PIN

From CaveLab
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

Keypad with programmable PIN code, two outputs (modes) and protection against repeated incorrect PINs. Uses an AVR ATtiny2313 microcontroller.


This module uses an AVR microcontroller to interface a cheap numeric keypad. The PIN code is set by the user and stored in EEPROM. If entered correctly; a one second pulse is sent on either output 1 or 2, depending on the selected mode. A tamper pin will be shorted to 0V when the module is connected. This keypad module is not itself meant to control anything, but it provides trigger signals for other control modules to act upon (like the Intruder alarm system controller). It has three LEDs (green, red and alarm) which can be used to convey messages from that other control module. Powered by: 5V.




Mode 1

To activate mode 1 enter PIN + * (star), a one second green light indicates correct PIN and confirms command.

Mode 2

To activate mode 2 enter PIN + # (number sign), a two seconds green light indicates correct PIN and confirms command.

PIN code

Change PIN

To change PIN enter current PIN + 0 (zero), a yellow light indicates that a new PIN can be entered. The new PIN is entered and confirmed with #, a green light indicates a successful change. Any button other than # will reject the new code and keep the old one, a red light indicates this.

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.



  1. PD2 Keypad R1
  2. PD3 Keypad R2
  3. PD4 Keypad R3
  4. PD5 Keypad R4


  1. PB0 Keypad K1
  2. PB1 Keypad K2
  3. PB2 Keypad K3
  4. PB3 Mode 1 signal
  5. PB4 Mode 2 signal
  6. PB5 Green LED indicator
  7. PB6 Red LED indicator
  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 internal connection and dimensions
  1. n/a
  2. K3
  3. K2
  4. K1
  5. R1
  6. R2
  7. R3
  8. R4

Source code

Bascom-AVR source is available in a git repository:


Schematic drawing


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