Introduction: Arduino Magnetic Combination Lock

Picture of Arduino Magnetic Combination Lock

This is my first published instructable and there may be many elements of this build that I may be taking for granted. Please feel free to comment if extra clarification is needed as this is a work in progress. This is also a prototype for something much bigger, please excuse the duct tape, shoddy wiring, and beat-up old box.

This project is for a magnetic combination lock using an Arduino, reed switches, and servo motor. The project can easily be manipulated to accommodate other locking mechanisms or modified to make more complex combinations.

The combination is unlocked using a magnet to trigger reed switches hidden behind an article. The reed switches must be triggered in the correct order for the code to enable the unlock function.

For the demo, LED's will be used to display when a reed switch has been tripped. They will also serve as an indicator for the combination, if it was entered correctly or not.

See the video for two test runs of the program. The first trial is a failure indicated by all the lights flashing 3 times. The second trial is a success, indicated by the lights flashing in sequential order.

Step 1: Parts and Pieces

For this exact build, you will need...

  1. Arduino
  2. 4 reed switches
  3. 4 LEDs and appropriate resistors
  4. 4 additional resistors (I used 100 ohms)
  5. 1 Servo motor
  6. 4 diodes (I used 1N4001, but I'm sure specifics are not necessary)
  7. Sliding door lock
  8. Box of some type
  9. A magnet (I prefer the neodymium but don't put your switches to close)
  10. UPDATE 5/29/16 An external power supply based on your servo size (the 5V supplied by USB may not be enough)

Step 2: Electrical Schematic and Code

Picture of Electrical Schematic and Code

Here's the rough diagram of the schematic you will be using. Please excuse any errors in syntax as I am an amateur hobbyist.

Also the code with plenty of comments for modification. In reality the code believes the combination of the triggered switches to be 1, 2, 3, 4 (like my luggage). However, because you can place the reed switches anywhere you want, the combination really doesn't matter. There does need to be a slight delay for each reed switch that is triggered and before a new switch can be tripped, else the Arduino would read the first tripped switch so fast you would never get to the second one. The delay is noted in the code and can be modified for your specifications.

Step 3: The Build Part 1

Picture of The Build Part 1

Seat your sliding door lock (don't forget a small hole for the pin to slide into) and use hot glue to affix the four reed switches to the inside cover of your box. Do not put the switches to close to each other or your magnet may inadvertently trigger the wrong switch. Also drill four holes for the indicator LEDs (PIC 1).

I used a breadboard to simplify the hookups between many of the pins, ground, and switches but this is not necessary (PIC 2 &3).

Step 4: The Build Part 2

Picture of The Build Part 2

Mount the breadboard to the box and attach the LEDs and reed switches.

Step 5: The Build Part 3

Picture of The Build Part 3

Attach servo motor. The specifics on your servo may vary and need adjustments within the unlock function.

Extra ideas...

A picture could be glued in front of the box with the reed switches located behind key elements within the picture. This will make it easier to remember the loci of the switches.

Remove the LEDs to make your combination truly discreet. Simple trial and error is enough to break the current combination.

Incorporate the lock into a hidden door with access to a secret closet (my next project!)

Enjoy and tweak!

Comments

DeanW43 (author)2016-05-25

Hey, I'm trying to make this. I believe I have this wired up right, but every time I plug it in, the led just go in sequence, then the servo operates and continues on in a loop. Any help as to what I'm doing wrong?

thallmls (author)DeanW432016-05-26

Could you please clarify, you stated the problem occurs the moment you plug it in. Do you even have a chance to close the switches with a magnet?

DeanW43 (author)thallmls2016-05-26

No, the moment the board is powered on the led's light up in sequence, then flash three times. The servo then moves. Continues on in a loop until the led just stay lit and the servo doesn't do anything.

thallmls (author)DeanW432016-05-29

I was able to replicate your problem two various ways. One was a bad ground on the power side (which caused a variety of problems with the servo and lights) and the other was if I didn't have an external power supply hooked to the arduino and tried to power strictly from the USB port. I believe I have taken this step for granted as the 5V from USB may not have enough amperes to drive your servo. I have made amendments to the above instructions. I hope this helps.

DeanW43 (author)thallmls2016-05-31

Thank you so much for the help. It was definitely because I was powering it from the USB.

amberrayh (author)2015-04-07

Congratulations on your first Instructable! I hope we see more from you in the future.

About This Instructable

6,405views

33favorites

License:

Bio: I'm a medical laboratory scientist who found a love in electronic automation through preventative maintenance on a chemistry analyzer.
More by thallmls:Arduino Magnetic Combination Lock
Add instructable to: