You Are Here: Home » AVR ATmega Projects » ATmega8 Based Smart Code Lock

ATmega8 Based Smart Code Lock

Here is a project for beginners using Atmel AVR ATmega8. The project uses some techniques that are very useful for designers to learn and utilize.


Don’t waste time finding each part running from shop to shop. Get all the parts with exact specification in a ready to use kit! Purchase ATmega8 based smart code lock KIT.

Code Lock

Functions of the Project.

This device can be used to code protect any electrical device (like an electronic door, lock or safe). The user must enter a correct password to gain access. The password is entered using the built in 4×4 keypad matrix. The main LCD Module is used to display messages to the user. As soon as correct password is entered the relay is activated. This is indicated by a LED which is placed near the relay. The relay remains on as long as the user wishes. You just need to press a key to deactivate the relay.

After typing four digit password you must press the “OK” button (S8). At anytime you may press the “Cancel” key (S12 )to clear the input (e.g. when you enter any incorrect digit)

The smart code lock has the feature to change the password too. For this enter a special password which is ‘0000’, as soon as the system receives this special password it switches to change password mode. Here you need to enter the old password to gain permission, then enter the new password.

The smart code lock also support power saving feature. The backlight of LCD turns off automatically when the system is idle for few seconds. The cool thing about this is that it uses PWM to control the brightness of LCD Backlight. So the dimming is very smooth and it is like those used in many mobile phones.

Making it yourself!

You can fabricate the circuit on any general purpose PCB or breadboard. The schematic and the BOM (Bill of Material is given below). To save you from lots of trouble we have made a quality PCB of the same! If you purchase the PCB, you just need to solder different components at their proper place on the PCB and you are ready to go.

Burn the HEX file (given at the end of article) to the ATmega8 MCU using any suitable programmer and plug it into the 28 PIN IC Socket.

After assembling the circuit power it on using a 12V 500ma Center Positive DC Wall adaptor (you can use one that is used for mini TVs or Game Consols or Your DSL Modem). Adjust the variable resistor RV1 (just below the LCD module, on the left side, yes the blue thing!) until the LCD Shows some text.

Schematic for ATmega8 based Smart Code Lock

codelock schematic thumb

Bill of Materials (BOM)

Part List
01330 ohm resistor (2 Nos)R3, R5
024k7 Resistor (3 Nos)R2, R4, R6
03200 Ohm ResistorR1
040.1uF Ceramic Disk Capacitor (4 Nos)C1, C3, C4, C5
051N4007 Diode (2 Nos)D1, D3
06LED 5mm Any ColourD4
07ATmega8L-8PU General purpose 8 bit MCUU1
087805 Voltage RegulatorU2
09Power Connector 2 WayCON1
10PCB Mountable RelayRL1
11On/Off SwitchSW1
12DC Socket X1
1316×2 LCD ModuleLCD1
1410K Preset (Blue Plastic POT)RV1
1528 PIN Narrow IC Socket
16BC548 Transistor(2 Units)Q1, Q2
17Push Buttons (16 Units)
18ATmega8 Based Smart Code Lock PCB

Firmware Source Code

The firmware source code is written in a professional was that may seems confusing to a n00b programmer. The thing is that every piece of related functions are stored in a separate source files. That means the the project is composed of several ‘C’ source file. Each C file has set of related functions (like LCD Interfacing Routines or EEPROM Access). You must use AVR Studio as a project manager and WinAVR as compiler. Both the software must be installed in your PC. In the project folder their is a file with name “code_lock.aps”, this is the main AVR Studio Project file. Load it in AVR Studio. You can see the various files that are part of the project in the left hand pane as shown below. Double click any file to load in the editor. After a file has been loaded in editor you can view and change it.

For more detail: ATmega8 Based Smart Code Lock

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Avr Risc Microcontroller Handbook – AVR E-Book

The AVR RISC Microcontroller Handbook is a comprehensive guide to designing with Atmel's new controller family, which is designed to...

Scroll to top