Projects   /   Home Automation & Security   /   PIC16F84A

Electronic combination lock based on PIC16f84

description This is my electronic combination lock to use with an outdoor gate. The functionality is implemented in software.

Published

At a glance

CategoryHome Automation & Security
PIC modelPIC16F84A
IncludesCode · Circuit diagram
Reading time~3 min
Jump to a section
  1. description
  2. operation
  3. software
  4. hardware
  5. Quick Solutions to Questions related to Electronic Combination Lock:
  6. Related projects

Summary of Electronic combination lock based on PIC16f84

This article describes a PIC16F84-based electronic combination lock for outdoor gates. It operates by entering a valid code to toggle or trigger a relay for AC locks, with low power consumption achieved via sleep modes. Users can change the default code (1234) using an asterisk key sequence. The software allows customization of parameters like clock speed, pulse width, and code length.

Parts used in the Electronic Combination Lock:

  • PIC16F84 microcontroller
  • Keypad matrix (push-buttons)
  • Relay
  • Code change indicator LED
  • Crystal oscillator (optional)
  • RC oscillator (internal to PIC16F628 or external for 16F84)
  • Power-to-open electric strike or power-to-hold electromagnetic lock

description

This is my electronic combination lock to use with an outdoor gate. The functionality is implemented in software. It turns on a relay (usually to open a door) for a few seconds if someone enters the valid code. Alternatively, it works as an ON/OFF switch, which toggles the relay each time the code is entered. This relay can operate a power-to-open type electric strike with a shorting contact or a power-to-hold type electromagnetic lock with a breaking contact (we need the relay because these locks usually work with AC, not DC). The code can be changed any time after entering the current code.

Electronic combination lock

Current consumption of the circuit is low, because the PIC sleeps most of the time, and wakes up only for processing key presses. If you don't have a crystal, you can use the RC oscillator of the PIC16F84 as well, just check the PIC datasheets for details on oscillator configurations. The 16F628 already contains an internal RC oscillator, so no crystal is needed.

operation

type in the correct code and use # as 'enter'. The initial code is 1234 after programming the un-modified HEX file. You could activate the output with typing in:

Code listing
1 2 3 4 #

* is used to change the code. Type in the actual code then press *. If you didn't miss the actual code, the code change indicator LED will light up. Then type in the new code twice. Eg:

Code listing (2)
1 2 3 4 * 1 9 9 8 # 1 9 9 8 #

will change the code to 1998. The code changes immediately and permanently after typing the new code twice. If you miss entering the new code twice, the original code is kept.

Electronic combination lock Schematic

software

Essentially, all software versions work the same. You can download and customize the source code for the version you choose. The first few lines of the code contain definitions of changeable parameters. If you are lazy, you can simply download the HEX files already compiled with default values. The definitions:

Code listing (3)
mhz EQU D'4'
this value is used for delay calibration. Of course, the code will run with different speed hardware as well, but faster or slower than intended.
Code listing (4)
pulsewidth EQU 'D'150'
this value is used to set the delay of the output pulse. To calculate the delay in seconds, use pulsewidth * 20 ms
Code listing (5)
clen EQU 4
this value sets the length of the code. The length is always fixed, and you can set it much higher, until you have available RAM on the chip

More details on the source code can be found here.

hardware

The keypad is actually a collection of push-buttons, organized into a matrix. It looks like this:

 

For more detail: Electronic combination lock based on PIC16f84

  • How do I enter the correct code?
    Type the correct digits followed by the hash symbol as enter.
  • What is the initial default code?
    The initial code is 1234 after programming the un-modified HEX file.
  • Can I change the code after setup?
    Yes, you can change the code any time after entering the current code.
  • How do I activate the output switch mode?
    Type the correct code and use the hash symbol to toggle the relay.
  • Does this circuit work with AC locks?
    Yes, the relay is required because these locks usually work with AC not DC.
  • Can I use a crystal oscillator for the PIC16F628?
    No, the 16F628 already contains an internal RC oscillator so no crystal is needed.
  • How is the output pulse delay calculated?
    Calculate the delay in seconds by multiplying the pulsewidth value by 20 ms.
  • What happens if I miss entering the new code twice?
    If you miss entering the new code twice, the original code is kept.
Beginner Tutorials · PIC16F84A

PIC Stepper Motor Controller using PIC16F84A with Proteus Simulation

Introduction Stepper motors are widely used in embedded systems and DIY electronics projects where precise position control is required. This PIC Stepper...

Programmers & ICSP · PIC16F84A

PIC Musical Doorbell using PIC16F84A with Proteus Simulation

IntroductionThis microcontroller project demonstrates a musical doorbell built around a PIC16F84A and a simple piezo sounder.Using two push buttons, the system allows...

Beginner Tutorials · PIC16C84

Exploring the World of PIC Microcontrollers: An Architectural Overview

A Peripheral Interface Microcontroller (PIC), developed by General Instruments Microcontrollers in 1993, operates under software control and is programmed to execute various...

Home Automation & Security

Voice Activated Power Sockets (Home Automation)

Yet another voice controlled home automation system! As shown in the picture, the system can control any electrical appliance, by turning ON...

Home Automation & Security

Home Security System with GSM Using 8051 Microcontroller

Security is a big challenge everywhere because thefts are increasing day by day owing to the unsafe and insecure security systems in...

Home Automation & Security

Home Automation and Security System using Microcontroller ATMEGA8 with Arduino Programming

Home automation and security systems have become very popular these days, today industrial automation techniques are widely adopted by luxurious homes and...

Ibrar Ayyub

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...