What it shows
The Arduino compares the keys typed with a stored code and turns a servo to slide a bolt only when they match. After three wrong tries it locks out for a minute, showing basic access control logic.
The science
A matrix keypad has four row and four column wires; the Keypad library scans them by putting each row low in turn and reading the columns, so 16 keys need only 8 pins. The sketch stores the typed digits in a buffer and compares them to the code with strcmp. Writing 90 degrees to the servo slides the bolt open and 0 degrees closes it. A counter of wrong tries and millis() give the lockout time.
Materials
Cost: under Rs 1,500. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- An Arduino Uno or compatible board
- A 4 x 4 matrix keypad
- An SG90 micro servo
- A red LED, a green LED and two 220 Ω resistors
- A piezo buzzer
- A 16 x 2 I2C LCD (optional)
- A cardboard or wooden door model, breadboard and wires
Safety
For this project: USB power only. This is a classroom model and must not be used to guard anything valuable. Keep the servo wire clear of the moving bolt.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Install the Keypad library, then connect the keypad rows to pins 2, 3, 4, 5 and the columns to pins 6, 7, 8, 9.
Connect the servo signal to pin 10, with power from 5 V and GND (add a 470 µF capacitor across the servo supply).
Connect the green LED to pin 11, the red LED to pin 12, each with 220 Ω, and the buzzer to pin 13.
Make a four-digit code in a char array and a buffer for typed digits.
Add each pressed key to the buffer, print a star on the LCD, and use # to enter and * to clear.
If the buffer matches, turn the servo to 90 degrees, light green and close again after five seconds.
If it does not match, flash red and count the failure; at three failures sound the buzzer and ignore the keypad for 60 seconds.
Test with right, wrong and partial codes, and change the code by editing the array.
What you should see
The bolt opens only for the correct four digits, wrong codes are rejected and three failures trigger a lockout.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1How can a 4 x 4 keypad use only 8 pins?
The keys are arranged in a grid, and the program scans rows and columns.
2What does strcmp do?
It compares two text strings and returns zero when they are identical.
3Why add a capacitor across the servo supply?
It supplies the short current surges so the Arduino does not reset.
4How could the code be stored so it survives power off?
Save it in the EEPROM.
Take it further
Store the code in EEPROM and add a key sequence that lets the owner change it.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Science projects
Mini and Major Project Guide
For diploma and BTech students: choose, plan, build, document and present
