Arduino Secret Pattern Lock

Arduino Secret Pattern Lock

Introduction

In this project, we are making a pattern lock using Arduino and Solenoid lock. The lock will only get opened when the correct pattern is entered. the pattern is a combination of “long” and “short” press of the pattern switch.

Hardware Used

Components
AliExpressali express
Banggoodbanggood
Amazon.comamazon
Amazon.inamazon
Win Source
Micro push-button
cart icon
cart icon
cart icon
cart icon
Arduino Nano
cart icon
cart icon
cart icon
cart icon
TIP120 transistor
cart icon
cart icon
cart icon
cart icon
cart icon
Resistors 2.3k,10k(kit)
cart icon
cart icon
cart icon
cart icon
1N4007 Diode
cart icon
cart icon
cart icon
cart icon
Solenoid Lock
cart icon
cart icon
cart icon
cart icon

Watch the video

Theory

  • The code will constantly monitor the enter switch and patter switch state and store it
  • Whenever I press the pattern button, the time from millis() function will be stored in two variables, one for press time and one for release time.
  • then the time difference between the release and press will be calculated and stored.
  • then using an if condition the program will check whether the time difference is less-than or greater-than the predefined time for “short” and “long” press.
  • then the code will check whether there is any space for the last detected press and if will be stored to the nearly available NULL space in the pattern lock array until all the array is filled
  • now if we press the enter button the program will compare the default pattern and the patter which you just entered.
  • if the pattern is true then the transistor will turn on and all the values stored to the pattern array will be erased.
  • if the pattern is false then the transistor will remain off and all the values stored to the pattern array will be erased.
  • also, I have added some LEDs for indication

Circuit

Connect the Circuit as shown,

  • Digital pin 2 and 3 to enter and the pattern button.
  • Digital pin 5 and 6 for Red and Green LEDs.
  • Digital pin 12 to the transistor base.
  • Transistor emitter to GND.
  • Transistor collector to Solenoid ground.
  • 12v to Solenoid VCC.
  • Don’t forget to connect ground of 12 to ground of Arduino
  • The diode in between VCC and ground of solenoid
  • and don’t forget all the resistors.

Arduino Code

How to change the LOCK CODE?

Enter your code “1” for short press and “2” for long press in the above-mentioned line.

For example, if you want to set your code as “long short short short” then change the line to this 👇🏻

Leave a Reply