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 holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.