Arduino Wireless Combination Lock With NRF24L01 and 4 Digit 7 Segment Display

by DonX-Developer in Circuits > Arduino

3551 Views, 17 Favorites, 0 Comments

Arduino Wireless Combination Lock With NRF24L01 and 4 Digit 7 Segment Display

03.png

This project started its life as an exercise to do something with a 4 digit 7 segment display.

What I came up with was the ability to enter 4 digit a combination number, but once it was finished, it was quite boring. I built it using an Arduino UNO. It worked, but did nothing else.

I then had the idea that it should have a button to accept the selected number, and maybe another button to change the combination, and maybe an LED to show the state it was in at any time. Whilst it sounded like a plan, it also meant that I would run out of pins on the UNO. There may be a way of multiplexing this unit but I'm not sure where to start, so I reached for the Arduino Mega.

Now that I was using a bigger board and had more pins to play with, I also decided to add wi-fi capabilities to communicate with another Arduino which would actually control some kind of switch.

Requirements and Parts List

01.png

After thinking about all that, I now have a list of requirements:

  • To be able to enter a 4 digit combination.
  • To start with a default hard coded combination.
  • To be able to change the combination and store the new combination in the Arduino's EEPROM.
  • Display the status of the lock with a red LED for locked and green LED for open.
  • Display the status when the combination was being changed with a blue LED.
  • When the state is unlocked, remain for a period of time then revert to the locked state.
  • Transmit the locked/unlocked state to another Arduino.
  • Display the same state with red and green LEDs on the receiving Arduino.
  • For demonstration purposes, use a servo to act as a lock mechanism based on the received state.

From the requirements I can now create a parts list:

The transmitter:

  • Arduino Mega.
  • Breadboard.
  • 4 digit 7 segment display.
  • 2 X momentary switches, with caps.
  • 1 X RGB LED.
  • 9 X 220ohm resistors. 8 for the display and 1 for the RGB LED.
  • 2 X 10kohm resistors. Pull down resistors for the 2 buttons. (I actually used 9.1kohm because that is what I had)
  • 1 X 10k potentiometer.
  • 1 X NRF24L01
  • [optional] 1 X YL-105 breakout board for the NRF24L01. This allows for 5v connection and easier wiring. Jumper wires

The receiver:

  • Arduino UNO.
  • Breadboard.
  • 1 X RGB LED.
  • 1 X 220ohm resistor. For the LED.
  • 1 X servo. I used an SG90 for demonstration purposes only.
  • 1 X NRF24L01
  • optional] 1 X YL-105 breakout board for the NRF24L01. This allows for 5v connection and easier wiring.
  • Jumper wires

The Display

display.png
220px-7_segment_display_labeled.svg.png

I used a 4 digit 7 segment display

Tested with SMA420564 and SM420562K (pins are the same)

Pins 1 and 12 are marked.

Top down pin arrangement 12, 11, 10, 9, 8, 7 1, 2, 3, 4, 5, 6

Pins 12, 9, 8, 6 turn on or off the digit 1 thru 4 from left to right

Wiring Up the Arduino Mega:

03.png

Display to Arduino pin arrangement

  • 1 to pin 6 via 220ohm resistor (E)
  • 2 to pin 5 via 220ohm resistor (D)
  • 3 to pin 9 via 220ohm resistor (DP) not used here
  • 4 to pin 4 via 220ohm resistor (C)
  • 5 to pin 8 via 220ohm resistor (G)
  • 6 to pin 33 (Digit 4)
  • 7 to pin 3 via 220ohm resistor (B)
  • 8 to pin 32 (Digit 3)
  • 9 to pin 31 (Digit 2)
  • 10 to pin 7 via 220ohm resistor (F)
  • 11 to pin 2 via 220ohm resistor (A)
  • 12 to pin 30 (Digit 1)

10kohm potentiometer to change the number on the displayed digit

  • Outer pin to 5v
  • Centre pin to A0
  • Other outer pin to GND

Accept number button.

  • To pin 36.
  • And pin 36 through a 10kohm pull-down resistor to GND

Change combination number button.

  • To pin 37.
  • And pin 37 through a 10kohm pull-down resistor to GND

RGB LED (Common cathode)

  • Cathode to GND through 220ohm resistor
  • Red to pin 40
  • Green to pin 41
  • Blue to pin 42

NRF24L01 with breakout board:

  • MISO to pin 50 (Mandatory through dedicated pin)
  • MOSI to pin 51 (Mandatory through dedicated pin)
  • SCK to pin 52 (Mandatory through dedicated pin)
  • CE to pin 44 (Optional pin number but defined in the sketch)
  • CSN to pin 45 (Optional pin number but defined in the sketch)
  • Vcc to Arduino 5v (or 3.3v if not using the breakout board)
  • GND to Arduino GND

Wiring Up the Arduino UNO:

04.png

RGB LED (Common cathode)

  • Cathode to GND through 220ohm resistor
  • Red to pin 2 Green to pin 3
  • Blue (Not used here)

Servo:

  • Red to Arduino 5v or separate supply if used
  • Brown to Arduino GND and separate supply if used
  • Orange to pin 6

NRF24L01 with breakout board:

MISO to pin 12 (Mandatory through dedicated pin)

MOSI to pin 11 (Mandatory through dedicated pin)

SCK to pin 13 (Mandatory through dedicated pin)

CE to pin 7 (Optional pin number but defined in the sketch)

CSN to pin 8 (Optional pin number but defined in the sketch)

Vcc to Arduino 5v (or 3.3v if not using the breakout board)

GND to Arduino GND

How It Works

07.png
05.png
08.png
4 Digit 7 Segment Wireless Combination Lock
09.png

Once both breadboards are complete and the appropriate sketch is uploaded onto them, we can now test it.

With power on to both boards.

The red LEDs should show on both boards.

The display will display a number in the first digit. This number will depend on where the potentiometer is currently set.

Turn the potentiometer to get the desired number.

Once the number has been found, press the accept button. In my case it is the one to the left of the potentiometer.

Do the same for the other three numbers.

If the combination entered is correct, the word OPEn will be displayed, the green LED will light on both boards and the servo will turn 180 degrees.

The display will go blank and the green LED will stay illuminated for about 5 seconds longer.

Once the unlock time is up, both LEDs will go red and the servo will turn back 180 degrees to its start.

If the combination entered is not correct, the word OOPS will be displayed and the red LEDs will remain on.

There is a hard coded default combination in the sketch of 1 1 1 1.

To change the combination, you must first enter the correct combination.

Once the word OPEn goes away, you have about 5 seconds to press the other button.

Once you enter the change combination sequence, the main board's LED will go blue, whilst the other stays green and therefore open.

Enter a new combination in the same way as before.

Once the new combination has been accepted (on the final button press) it will be stored in the EEPROM.

Both Arduinos will now go into locked mode.

Enter your new combination and it will unlock as expected.

Once a combination has been changed and stored in the EEPROM, the hard coded default of 1 1 1 1 is ignored.

All Done

I built this using the basic NRF24L01 with built in aerial and managed good communication of about 15 feet through one wall.

Because the Arduino Mega breadboard got a bit busy with wires in the way, I used direct jumpers in some places. This, with the fact there is a lot on one breadboard, makes it difficult to follow the pictures.

However, I think that I have explained everything pin for pin and even if you are a beginner, you should be able to build this little project just by taking one wire or pin at a time.

Both sketches are fully commented for ease of reading and are available here for download.

The sketch for the Arduino Mega is quite large, about 400 lines but is broken up into manageable chunks so should be easily followed.