Introduction: Arduino Combi-button Lock W/ Optional IOS/Android Support
Recently, I decided I would like to attempt to make a passcode lock with my newly acquired Arduino Uno, but all the tutorials I could find made use of a modified keypad, something that not every Tom, Dick and Harry has lying about. I therefore decided to set out and make a version using only things every Arduino user should have in their component box - buttons.
Ladies and Gentlemen, I bring to you - the Arduino Combi-button Lock!!
This example will cause only an LED to come on when the passcode is entered, but other features can easily be added, such as a servo, motor etc.
If you do not wish to use buttons, there is an alternative TouchOSC version for Android or iPad/iPhone/iPod touch. Just skip step 4.
This is an entry for the Microcontroller contest. If you think it's awesome, be sure to vote!
So let's get started!
Step 1: Components - What You Will Need
To make this lock, you will need:
-> An Arduino board - in my case an Arduino UNO I purchased from oomlout.co.uk. I bought the starter kit, and I would highly recommend it - go check them out!
-> A USB type-A to USB type-B cable
-> The Arduino IDE - download from arduino.cc
-> A breadboard
-> 4 x push buttons/switches
-> 4 x 10k ohm resistors
iPhone/iPod Touch OSC Controlled version:
-> TouchOSC app ($4.99 on AppStore, and I believe it is free on Android)
-> TouchOSC layout editor
-> The Processing IDE - download from processing.org
Step 2: Preparation - Setting Up the Breadboard
Plug one of the bus rails along the side into the 5v pin on the Arduino
Plug another bus rail into a ground (GND) pin on the Arduino
Step 3: Let There Be Light! - Setting Up the LEDs
Plug both the LEDs into the breadboard, longer leg on the left ( to make following this tutorial easier).
Next, plug a 560ohm resistor into the rail connected to the longer leg (+ve) of each LED, and take the red LED's resistor to Arduino digital pin 4. Then take the other end of the green LED's resistor to pin 12 on the Arduino.
Finally, take a jumper wire, and join the other leg of the red LED to the GND bus rail, and do the same for the green LED.
Step 4: Physical Version - Buttons
OK, I will walk you through one button, and the same process must be repeated for the other three.
Please Note: It is important that none the buttons are connected to the same rows occupied by the LEDs (two for each or three for each, depending on which setup you chose in the previous step).
Plug a button over the gap in the middle of the breadboard - make sure this goes the right way round. You might have to bend pins.
Next, plug a 10k ohm resistor from one leg of the button to the GND bus rail, and use a jumper wire to connect the other leg on the same side of the gap to the 5V rail.
The next step is a little harder to explain - connect digital pin 8 on the Arduino to the rail which contains a leg of a 10K ohm resistor and a leg of a button. Look on ladyada's website for a more detailed explanation.
Set up the other buttons the same, with the second going to pin 9, the third going to pin 10, and the fourth going to pin 11.
You can now skip to the code section.
Step 5: CAN Touch This - TouchOSC Version - Creating the Layout
First, we must create the layout for TouchOSC. Open up the editor that you should have downloaded in step 1.
Next, create 5 toggle buttons by right-clicking. 4 will be the buttons to enter the code, and one will be the set/reset button. You can position these as you like, just be sure they are named as follows (from left to right):
-> The first is named toggle1
-> The second is called toggle2
-> The third is toggle3
-> The fourth is toggle4
-> And the reset button is called toggleReset.
See a screenshot of my layout above. I also added a label saying RESET, but this is optional. Labels numbering the buttons could also be added.
Save this layout as Passcode Buttons, or anything really, so long as it describes what the layout is.
Step 6: TouchOSC Version - Syncing the Layout
Open the TouchOSC app on your Android/iDevice, and make sure your PC and your device are on the same WiFi network.
On the TouchOSC editor, hit "Sync".
Back on the app, tap "Layout", then add, and select your PC from the list.
Your new layout will now be added onto the list.
Step 7: TouchOSC Setup
On the main menu of the app, tap the OSC entry under the "Connections" heading.
Make sure the options are as follows:
-> Enabled - On
-> Host - enter your computers local IP address here. You can find this by going to your PC and opening a command line
- If you are on Windows, type "ipconfig". I don't use Windows, so I can't tell you exactly what to look for. A quick Google search will provide more info
- For Mac or Linux, use this command: ifconfig | grep "inet " | grep -v 127.0.0.1, and take the first entry (four numbers separated by periods)
-> Port (outgoing) - 8000
-> Port (incoming) - 9000
Step 8: The Code
For the physical version:
Open the Arduino IDE and upload the Passcode.pde file to your board. By default, the passcode is 1,2,3,4. You can change this by modifying the numbers in the code array at the top of the code.
Once the password has been correctly entered, the reset button on the arduino must be pressed to reset the lock. This is intentional.
For the TouchOSC version:
Before you can upload this code, you must download the Arduino library for Processing (the version for the Arduino Mega can be found here ), and also the OscP5 Library . Install these by extracting them, and dropping the folders created into the "libraries" folder in your processing sketchbook (if it is not there, create it).
Next, upload the "Standard Firmata" sketch, found in Examples>Firmata, to your Arduino board.
Finally, run the PasscodeOSC.pde processing sketch.
Now, when using the TouchOSC app and the layout we created, you should be able to type your passcode. Bear in mind that the processing sketch MUST be running on your PC in order to function.
Again, the passcode can be change in the code array at the top of the Processing sketch.
If there are any questions, let me know in the comments.
Remember to vote if you like this Instructable!!
Thankyou and goodnight!!