Champaign-Urbana Community Fab Lab
Champaign-Urbana Community Fab Lab

Arduino intro – Andrew Sun

For this week, I was inspired by these dial locks I saw in a store to try to create my own programmable “lock” using an Arduino. The idea was that you could set a password as a series of movements, and to unlock the device, you had to repeat those movements in the correct order. I obviously couldn’t find a sensor that could do all of this, so I used a joystick sensor (similar to the ones found on game controllers) and some software to emulate this behavior.

Since we didn’t have any physical locks that could be controlled by the Arduino, I decided to use some LEDs to display when the device was “unlocked”. I also wanted to give some feedback on the user’s input, so I decided to add some LEDs that would light up when the user moved the joystick (kind of like the dots you see when you type a password).

When creating the circuit, I ran into an issue with the size of the breadboards. I wanted to have a password with at least 6 LEDs, but there was only one ground pin for the Arduino micro I used. I had to connect the ends of all the LEDs to the single ground pin by bridging all of the LEDs using jumper cables, creating a huge mess. I think a good way to improve this design would be to use some wire to avoid the problem of the cables sticking out from the board.

I also tried using various colors for the status LEDs, but for some reason when I added a blue LED into the circuit, all of the other LEDs turned off. Strangely, this problem didn’t happen if I only used blue LEDs or only non-blue LEDs, so I decided to just use a single color for the status LEDs.

The next part was reading the data from the joystick. It turned out to be an analog signal from 0 to 1000, with 500 being the neutral position. However, for some reason, I was sometimes getting multiple inputs at once (as in, moving the joystick up once would create many “up” inputs). After some searching, I found that the input would sometimes quickly alternate between just under the cutoff and just over the cutoff, which caused the problem I was observing. To solve this, I used a technique called debouncing, where I would wait until I saw the same input multiple times (in my case, 100 was a good number) before accepting it. This worked great, and now I was only getting a single input at a time.

And here’s the final product! The green LED blinks at the end if the password is correct, and everything gets reset if the password is incorrect.

In the future, I think it would be cool if users could change their password using the joystick itself, instead of having to reprogram the Arduino. It could be something like a switch that would only be activated when unlocked, and would make any inputs change the password.

 If you are interested, the code I used for this project can be found here: https://ghostbin.com/paste/gpntu