Learn to code

Arduino Home

Lessons 1
Arduino - Getting Started
Lessons 2
Arduino - Basics
Lessons 3
Arduino - Serial Communication
Lessons 4
Arduino - Digital / Analog
Lessons 5
Arduino - Visual Output
Lessons 6
Arduino - Motor Control
Lessons 7
Arduino -LCD Displays
Lessons 8
Arduino -LCD Displays

Creating a password protected lock with a keypad, relay, and display for Arduino

in Arduino Project

This premium tutorial will teach you how to combine a keypad, a TM1637 4-digit 7-segment display, a relay, a solenoid lock, and an Arduino Uno.

The display shows the input from the keypad,  a Pincode. If the user enters the correct code, the solenoid lock unlocks.

The tutorial explains the code in detail, so you should have no problems modifying it to suit your needs. The code allows you to add multiple passwords. The passwords are predefined in the code.

Wiring diagrams are included in this tutorial. The tutorial starts with a breadboard layout that shows all the connections. This breadboard layout is explained in 3 sections. Each module connection is explained.

If you are new to Arduino, please visit the below tutorials before continuing.

What you will need to know?

Before continuing with this guide, you may want to check out any topics from the list below that sound unfamiliar.

Parts you will need

Arduino Uno Rev3 Arduino Uno Rev3 × 1
Dupont Wires Dupont Wires × 17
DC Barrel Jack DC Barrel Jack × 1
5v Relay 5v Relay × 1
12v Solenoid Lock 12v Solenoid Lock × 1
TM1637 4-digit 7-segment display TM1637 4-digit 7-segment display × 1
Keypad Keypad × 1

Arduinoplatform is a participant in several affiliate programs. This means that I will earn a commision if you buy a product from the affiliated websites through clicking on the links provided above.

BreadBoard Layout

TM163 Display

Most displays require a lot of connection pins. That is quite complex and does not leave much space for other sensors or modules to connect with the Arduino Board. The TM1637 display module only uses four pins. Two pins are required for the power connections and the other two are used to control display.

A 7-segment display contain individually addressable LEDs. The segments are labeled from A to G. To be able to set the LEDs you should know which segment corresponds to which letter. The image shows how the display segments are labeled.

TM1367 Wire connection

TM1637 4-digit displayArduino Board
VCC3.3v Pin
GNDGND Pin
CLK A0 Pin
DIOA1 Pin

Keypad 3 x 4

The buttons of each keypad are arranged in rows and columns. The keypad that we are using has 4 rows and 3 columns. Beneath each key is a switch. Each switch is connected with the other switches in the row.  Each row and column should be connected to the Arduino Board. In total, we have 7 pins that we are going to connect.

Arduino detects which button is pressed on the keypad by detecting the row and columns pin that is detected to the button.

Keypad wire connections

3x4 Matrix KeypadArduino Board
Pins 1 till 7Pin 7 till 13

Relay Module

The relay module gives you the ability to separate two different circuits with different voltages. In the breadboard layout, the solenoid lock is separate from the Arduino Board with a relay module. The  Arduino Board controls the relay. When the relay is activated, a HIGH signal is sent to the module. The 12 volts circuit is “activated.” This allows us to control the solenoid lock with a different voltage circuit (12V) with the 5V circuit from the Arduino Board. For the wire connection of the relay module with the Arduino Board, it is important to decide whether you want the relay to act as normally closed or as normally open.

  • COM: common pin
  • NC (Normally Closed): the normally closed configuration is used when you want the relay to be closed by default, meaning the current is flowing unless you send a signal from the Arduino to the relay module to open the circuit and stop the current.
  • NO (Normally Open): the normally open configuration works the other way around: the relay is always open, so the circuit is broken unless you send a signal from the Arduino to close the circuit.

Relay wire connections

5v RelayArduino Board
VCC5V Pin
GNDGND Pin
In PinPin3
COM OutputGND DC Jack
NO OutputVCC Solenoid

Solenoid Lock

The Arduino Board controls the solenoid lock. As stated above, the board sends a signal to the relay module that turns the solenoid on and off. The lock works only with electricity, so the lock cannot be opened or closed in case of power failure.

Solenoid Wire connections

12V SolenoidRelay / Power Supply
VCC SolenoidNO Output relay
GND solenoidGND DC Power supply

The Code

The code that in this article is a paid part of the website. For only 10 dollars, you will be able to see and use the code. Most of the articles are free. However, the premium articles enable me to take time off my job and write more articles.

Furthermore, if there are any questions regarding adjustment, feel free to ask them in the comment section.

In summary, this premium code controls a solenoid lock by entering the correct password with a keypad (code is displayed on a TM1367 Display).

Restricted Section

Only subscribed user would be able to view this content.

Activate subscription

To access content from the group Password Protected Lock please activate subscription.

Activate subscription

To view this post please login and activate subscription.

Next Post
Create a Touch Button with copper /aluminum foil

4 Comments. Leave new

  • MKstudio SK
    12 October 2020 15:31

    What I need to do if I have Serial monitor only(not display) , and I want to show the passwords on the Serial monitor.

    Thanks in advance for an answer.

    • Thank you for replying to my post. In de code the command Serial.println is used a couple of times. This enables you to send the entered code to the Serial Monitor. The below code is from the blog article which sends the pressed key to the Serial Monitor.

      if (key){

      // Log it to the serial output
      Serial.println(key);

  • Hello,
    I’m using an Adafruit 7 segment display with backpack (4 digit, with colon and dots).
    I know I need the adafruit_GFX .h, wire.h and adafruitLEDBackpack.h libraries but i can’t seem to figure out how to rename the code to make this work.
    could you help connecting this to this type of led-display?
    Thanks a bunch!

  • Hello Robin, thank you for your post. Well If you are using the Adafruit segment display you should take a look at the following tutorial

    https://learn.adafruit.com/adafruit-led-backpack/1-2-inch-7-segment-backpack-arduino-wiring-and-setup

    The display uses different commands to function than the display that is shown in the tutorial. I hope this helps, if not, please comment again.

You must be logged in to post a comment.
Menu