COMBINATION LOCK FOR SAFE using PIC16F628

Introduction

This program is a simple combination lock that I designed for an old Sentry® fire safe that was given to me without any lock electronics. I created a front panel with a keyboard and microprocessor with a six-digit combination sequence.

COMBINATION LOCK FOR SAFE

Details

The LED flashes to show it’s alive after power is applied.

The lock solenoid requires 6VDC at approxmately 2 amps. Given that a small 9V battery is used and wouldn’t easily provide that current for very long, I used the PIC’s PWM output to vary the current in two phases:

  1. It starts with a 30mS “pick” phase that delivers full current by providing a 100% duty cycle to the FET driver which puts a solid 9V across the solenoid.
  2. That’s followed by a “hold” phase of 1.4 seconds at a reduced duty cycle that reduces current to significantly less.

The initial combination is “123456”. Regardless of any immediately prior key sequence, when that correct key sequence is entered and completed, the lock solenoid is actuated for 1.5 seconds. If a key isn’t pressed for two or more seconds, the firmware resets to again look for the first digit.

Caveats

Since this circuit is battery powered, some way is required to turn on the battery when needed. I used a toggle switch below the keypad to accomplish this, but more innovative methods would be more elegant. For instance, one could employ some sort of mechanical cover over the keypad whereby lifting the cover would actuate the switch to connect the battery.

COMBINATION LOCK FOR SAFE

Code:

/**************************************************************************** SAFE_COMBO_02.C PIC 16F628 Combination Lock – resets to first expected digit two seconds after last key is pressed – uses PWM to reduce current to coil after initial pulse ——— ———- +5 –14-|VCC B0|-17—–|C1 | | B1|-18—–|C2 | Gnd —5-| B2|-1——|C3 | 6MHz XTAL –16-| B4|-2——|R1 KBD | XTAL –15-| B5|-6——|R2 | | B6|-7——|R3 | | B7|-8——|R4 | | 16F628 | ———- | | | B3|-6— LOCK SOLENOID | A1|-18– LED ——— ========= | 1 2 3 | R0 | 4 5 6 | R1 | 7 8 9 | R2 | * 0 # | R3 ========= C0 C1 C2 Keyboard connector is (backside): C2 C1 C0 R3 R2 R1 R0 Oscillator = 6MHz crystal Jon Fick 03/09/07 ***************************************************************************/ #include <16F628A.h> #include // Set configuration bits in the PIC processor #fuses HS, NOPROTECT, NOWDT, PUT, BROWNOUT, NOMCLR, NOLVP #define COMBO_1 ‘1’ #define COMBO_2 ‘2’ #define COMBO_3 ‘3’ #define COMBO_4 ‘4’ #define COMBO_5 ‘5’ #define COMBO_6 ‘6’ #define KBD_C1 PIN_B0 #define KBD_C2 PIN_B1 #define KBD_C3 PIN_B2 #define KBD_R1 PIN_B4 #define KBD_R2 PIN_B5 #define KBD_R3 PIN_B6 #define KBD_R4 PIN_B7 #define LOCK_OUT PIN_B3 #define LED PIN_A1 #define NOKEY 0xFF #define RESET_KBD_COUNT 46 // at 23 counts/second #define LOCK_HIGH 255 // full PWM duty cycle #define LOCK_HIGH_TIME 30 // mS at full coil current #define LOCK_MED 20 // partial PWM duty cycle #define LOCK_MED_TIME 1450 // mS at partial coil current #define LOCK_OFF 0 // no PWM current #use delay ( clock = 6000000 ) // sets appropriate compiler constants #use standard_io ( A ) #use standard_io ( B ) char GetKey ( void ); // prototypes static char cKbdTimeoutFlag, cLedCount; #int_rtcc void TimerInterrupt ( void ) // 43mS tic, 23/second { if ( cKbdTimeoutFlag != 0 ) { cKbdTimeoutFlag–; // count down to zero } if ( cLedCount++ > 12 ) { cLedCount = 0; } if ( cLedCount > 6 ) { output_high ( LED ); } else { output_low ( LED ); } } void main ( void ) { delay_ms ( 100 ); // power up delay output_low ( LOCK_OUT ); // turn off lock solenoid */ output_low ( LED );

 

For more detail: COMBINATION LOCK FOR SAFE using PIC16F628

About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter