Arduino Servo Motor Keypad Safe

by IBuildCircuts in Circuits > Arduino

1846 Views, 25 Favorites, 0 Comments

Arduino Servo Motor Keypad Safe

IMG_0613.JPG
Arduino Servo Motor Keypad Safe

I made a safe that can be locked and unlocked using an Arduino keypad and servo motor.

Supplies

The supplies that you need are

3D Printer/ Laser Cutter

Arduino - Amazon Link

Servo Motor - Amazon Link (you only need one)

4x4 Keypad - Amazon Link (you only need one

Arduino Software

Wires

3d Printing

3D print all the parts and assemble them. Files and print instructions here: https://www.printables.com/model/751743-arduino-keypad-servo-motor-safe/files

Wiring

Project Arduino Safe
Arduino Keypad Safe Wiring Demo
Keypad Unlock Demo

Wire the Arduino, keypad and servo motor.


To wire the 4x4 keypad and servo motor to an Arduino Uno, follow these steps:

1. Connect the black/brown wire of the servo motor to GND pin on the Arduino Uno.

2. Connect the red wire of the servo motor to the 5V pin on the Arduino Uno.

3. Connect the yellow/orange wire of the servo motor to digital pin 10 on the Arduino Uno.

4. Connect the rows of the 4x4 keypad to the following pins on the Arduino Uno:

    * Row 1 to digital pin 9

    * Row 2 to digital pin 8

    * Row 3 to digital pin 7

    * Row 4 to digital pin 6

5. Connect the columns of the 4x4 keypad to the following pins on the Arduino Uno:

    * Column 1 to digital pin 5

    * Column 2 to digital pin 4

    * Column 3 to digital pin 3

    * Column 4 to digital pin 2



Coding

You will upload the code to the Arduino.

Here's how the code works:

1. The code first includes the necessary libraries for the keypad and servo motor.

2. The 4x4 keypad pins are defined, along with the keymap for the keypad and the servo motor pin.

3. The keypad object is created with the defined pins and keymap.

4. The password is defined as "1234", along with an array to store the entered password and an index to keep track of the entered password.

5. In the setup function, the servo motor is attached to the defined pin and the serial communication is initialized for debugging.

6. In the loop function, the code waits for a key to be pressed on the keypad.

7. If a key is pressed, it is added to the entered password array and the password index is incremented.

8. If the entered password is complete (4 digits), the code checks if it matches the defined password.

9. If the entered password is correct, the servo motor is turned 90 degrees.

10. If the entered password is incorrect, an error message is printed to the serial monitor.

11. The entered password and password index are reset to prepare for the next password entry

12. This code uses a boolean variable passwordEntered to keep track of whether the correct password is being entered. If the password is entered correctly, the motorPosition variable is set to 90 degrees and the servo motor is turned to that position. If the correct password is entered again, the motorPosition variable is set to 0 degrees and the servo motor is turned back to the initial position.

13. In the code, we use a unsigned long variable lastKeyTime to record the time of the last key press. We then added a conditional statement that checks if 90 seconds (90000 milliseconds) have passed since the last key


Finished Safe

IMG_0613.JPG
Arduino Servo Motor Keypad Safe

All done!