Introduction: Arduino Activated Safe Lock System

Do you want to protect your belongings? Would like to place them somewhere 'safe' where no one would be able to touch them or take them? Well, I have the perfect solution for you! In this instructable, I will be showing you how to create an Arduino controlled and activated safe lock mechanism.

The system functions the same way a normal safe mechanism would, you enter a 4 digit code onto the keypad attached to the Arduino, if you enter the correct code, the Arduino will then send a signal to the servo motor to start turning, thus opening the safe. However, if the incorrect code is entered, not only will the safe not open, but rather the Arduino would order the speaker and neopixel lights attached to it to start making an alarm sounds and start flashing red lights. This would signal everyone in the area that someone is tampering with your safe, and allow you to react accordingly.

Like my previous project, I will be creating this circuit within TinkerCAD, a free-to-use online modelling program that allows you to create circuits electronically. However, since this instructable is still based off a circuit constructed on TinkerCAD, if you wish, it can still be physically constructed using real-life components as TinkerCAD follows the same logic as a physical circuit.

Supplies

I have attached a link to where you can purchase these components if you would like to physically build this circuit. However, if you are building this circuit on TinkerCAD like me, then you do not need to purchase anything, as all of these components are available on the program for free.

Step 1: Installing Keypad

The keypad has a total of 8 pin sockets which can be used to attach the keypad to the Arduino. Each of the pins on the keypad represents either a row or column on the keypad. Going from left to right, the first four pins represent the 4 rows on the keypad while the last four pin sockets represent the 4 columns on the keypad. Before you start connecting the Keypad to the Arduino itself, you must first place the keypad on the breadboard, it does not matter where you place it as long each of the Keypad Pins is in a different row or column on the breadboard. Once that is done, you can start connecting the keypad to the Arduino. The way to connect the keypad to the Arduino is that you would want to take a hookup wire of any colour other than black or red as those wires have their predetermined colour representations, and connect one end of the hookup wire to the keypad pin while the other to the pin sockets in the Arduino labelled with a number. Do not use the 0 and 1 pin sockets on the Arduino as they have their own designated role and are not compatible with the keypad, use pin sockets 2 through 13. It is recommended that you attach the keypad pins to the Arduino pin sockets in order, such as attaching the row 1 pin on the keypad to the pin labelled with a 9 on the Arduino, row 2 pin on the keypad would be attached to pin 8 on the Arduino, row 3 to pin 7, and so forth. Once all the pins on the keypad are attached to the Arduino, your keypad is fully operational and ready for the code!

Step 2: Setting Up Micro Servo

Now that the input device being the keypad is installed, we can start setting up the servo that would be responsible for actually unlocking the safe and allowing it to be opened. The servo consists of three pin sockets, each responsible for a specific thing. Going from left to right, the first pin is responsible for supplying the signal to the servo, telling it when to open and how much to turn, the second is for supplying power to the servo, while the third and last one is for GND (ground). To attach the servo to the Arduino, you will first want to use a red coloured hook up wire and connect the power pin which is the second pin on the servo, to the pin socket on the left side of the Arduino labelled, '5V'. You would then want to use a black coloured hook up wire and attach the GND pin of the servo, which is the third pin, to the pin socket on the left side of the Arduino labelled, 'GND'. Lastly, you would want to connect the signal pin on the servo, which is the first pin on the servo, to any of the remaining pin sockets on the Arduino labelled with a number, excluding pins 0 and 1, using a hookup wire of any colour. Once all the servo pins are attached to the Arduino, your servo is now completely wired and ready for code!

Step 3: Connecting Piezo Speaker

Now that all the components that are needed for the door opening are all wired, we can start wiring the alarm countermeasures that will alert you if someone is trying to break into your safe. We will start wiring the alarm system with the piezo speaker that will create the alarm sound. The piezo speaker has two legs attached to it, looking at the speaker head-on and going from left to right, the left leg is referred to as 'Terminal 2', while the second leg is referred to as 'Negative'. The Negative leg is used to ground the speaker while the Terminal 2 leg is used for power. Before we start wiring the speaker itself, I recommend using a black hook up wire and connecting the ground rail on the breadboard that is marked with a black '-' symbol to the pin socket on the Arduino labelled 'GND'. Really what you are doing here is activating that entire column of pin sockets on the breadboard so it is easier to ground your speaker. Once you have the ground rail on the breadboard activated, use a black hook up wire to connect the Negative leg of the speaker to any pin socket on the ground rail located on the breadboard. Activating the ground rail on the breadboard using the help of the Arduino and then connecting the Negative leg to the ground rail on the breadboard is more of a trick to make your circuit look more clean and tidy. If you would like to connect the Negative leg of the speaker, straight to the GND pin socket on the Arduino using a black hook up wire, feel free to do so. After the Negative leg of the speaker is connected to ground, you can now move onto connecting the Terminal 2 leg of the speaker to the Arduino. To do so, you first want to connect one leg of 100 Ohm resistor to the piezo speaker, and the other to a pin socket on the breadboard. Once that is complete, use a wire of any colour and connect one end of it in the breadboard rail in which the 100 Ohm resistor is connected to, and the other end to any of the numbered pins on the Arduino. Once that is complete, your piezo speaker is fully wired and connected!

Step 4: Installing NeoPixel Light Strips

With the speaker wired and ready to go, we will now install the NeoPixel light strips. I will be installing a Neopixel light strip that consists of 4 LEDs, however, you could use a light strip with more LEDs, just edit the code accordingly. I will be placing two separate LED strips in the circuit, however, you could add as many as you wish. The NeoPixel light strips have two ends and each end houses three pins, each with its own ideal role and purpose. If you look closely on to the strips, you will notice that there are arrows that point in a certain direction, the arrows help the user orient the NeoPixel strips. The side of the strip that we will be using is the side on which the arrows on the strip are pointing opposite in relation to the side. Just in case you get confused, the side that we are using houses the pins labelled as: 'In', 'Power', and 'Ground', in that specific order. Now to start wiring, we will first take a red coloured hook up wire and connect one end of it to the 'Power' pin, which is the centre pin on the light strip, and the other end to the 5V pin socket on the Arduino. Then, using a black coloured hook up wire, connect the 'Ground' pin on the light strip, which is the pin on the far right of the strip, to the GND labelled pin socket on the Arduino. Lastly, connect one end of a hook up wire of any colour to the 'In' pin on the light strip, to any of the remaining numbered pins on the Arduino. Repeat these steps for the other NeoPixel Light Strip(s).

Step 5: Coding the Components

This safe lock would never be able to function or perform its duty without the set of instructions we are going to give it in the form of code. Allow me to give you a brief rundown of how the code functions. It first sets up a variable labelled as 'a' that equals zero in the start. Then, the code sets up the keypad, servo, speaker, and NeoPixel light strips, establishing them as either an input or output device. After it has established all the components as either input or output device, it starts to read the keypad and waits for a button on it to be pressed. When a key that is apart of the security code we have preset is pressed, it adds a value of 1 to the 'a' variable. However, during that time if an incorrect key is pressed on the keypad that does not fit the security code we have set, it subtracts a value of 1 from the 'a' variable. Then once you have entered all the values you wish, you press the 'A' key to enter that set of inputs into the machine. Once entered, the code would read the value of the 'a' variable, and if it matches the size of the security code we have entered which is 4 digits, so if the 'a' variable is equal to 4, it orders the servo to turn, thus opening the safe. However, if the 'a' variable does not equal 4, it tells the NeoPixel lights to start blinking and the speaker to start functioning, thus sounding the alarm. The file to the code can be found above. Here is a link to a google doc with the code if the file fails.

If you are coding in TinkerCAD then you will just need to click on the "Code" button in the top left corner and write the code there. However, if you are creating this circuit physically, then you will need to open a C++ coding software onto the computer which your Arduino is connected to. You will have to set the output source of the code to the Arduino and then send the instructions to the Arduino once you have completed the code.

Step 6: Locking Up Your Valuables!

Congratulations! You have just completed the Arduino Activated Safe Lock System! You can show this off to your friends and family or build it in real life and use it to create a real safe to protect your valuables, or even use this as a door lock to protect your home from intruders or keep your older brother out of your room! Feel free to further modify this circuit and add your own little elements to it to make it even better and more useful. Thank you for following this instructable!

References:

Below you can find all the references and resources I used in order to construct this circuit!

Keypad/Servo:


https://github.com/ammadkarar786/E-Innovators-code...

NeoPixel Light Strips:

http://theelectronics.co.in/neopixel-ring-interfac...

https://create.arduino.cc/projecthub/zanycadenced...

https://learn.adafruit.com/neopixel-painter/test-...

Piezo Speaker:

The speaker I mainly learned how to use through a predesigned circuit of the piezo speaker that could be found in the TinkerCAD pre-designed circuits library.
https://www.tinkercad.com/things/7kwDMPmSp5r-speak...