Introduction: $12 Secret Code Box
This is an easy little project for Arduino beginners that only costs about $12 to make. When a person enters the correct code on the keypad, the box will play a secret message. It could be used as part of a scavenger hunt or could be modified to trigger a door to open or trigger a servo with just a few changes.
I used an Arduino Mini Pro for my project, but I think an Arduino Nano is a better choice for most beginners because it has a build in USB port for easy programming, so I wrote this instructable with that in mind even though some of my pictures show a Mini Pro.
Step 1: Parts Needed
- Project Box (Free if you are creative)
- Arduino Nano ($3)
- MP3 Sound Module ($6)
- Speaker ($2)
- Keypad ($1)
- LED of your choice ($0.05)
- USB Cable (Hopefully you have one laying around)
- A few jumper wires (same)
- 1 resistor for the LED ($0.05). You can use this calculator to figure out the resistor value depending on the LED color you choose. I think I used a 1K Ohm resistor to dim the LED somewhat.
Total Cost: ~$12
Step 2: How It Works
When you plug in the USB cable, the Arduino powers up and runs the program which waits for input from the keypad. If the program gets the right keypad presses in the right sequence, it then connects one of the signal pins on the MP3 Sound Module to ground which plays a sound file through the attached speaker.
Step 3: Load Sound Files on Sound Player Module
Connect the MP3 Sound Module to your computer. It should automatically be recognized as a USB drive. Copy the mp3 file you want to play onto the module and rename it "0001.mp3". If you want to elaborate on the program and create multiple combinations with multiple messages you can copy more files to the module. Just name them sequentially (i.e. "0002.mp3"," 0003.mp3", etc). These sound files correspond to the physical pins (K1 - K7) on the sound module. If you connect pin K1 to ground it will play the first sound file. If you connect pin K2 to ground it will play the next one and so on. For advanced users, you can use a serial connection on the module to play any number of sounds. Here is a link to an English translated version of the user guide for the module I used if you are interested in learning more.
Step 4: Prepare Your Power Source and Box
You will need to supply 3.3 - 5 volts of power for this project. You can connect a 3.7v lithium ion battery if you want your box to go anywhere. For my needs, a long USB cable was just fine and I had one lying around that I could use. This might be a good time to drill a hole in your project box slightly bigger than the cable you are using. Be sure to make enough room for the plug end of the cable. You can also do what I did and cut off the plug end to make it easier to get through a smaller hole. You can then strip the jacket off the red(+) and black(-) wires and connect them directly to the VIN and GND pins. If your edges are sharp, consider adding a rubber grommet to prevent the box from cutting into your cable. Then feed your cable through the hole and tie a small overhand knot so that the cable can't be pulled back out through the hole.
You might also want to drill a hole for your LED at this point.
Step 5: Program Arduino
Download and install the keypad library from this site. Load the attached Arduino program. Be sure to choose the correct COM port and Arduino Nano as the board in the Tools menu of the Arduino IDE. I won't be covering the details of how to use the IDE in this instructable. There are plenty of good resources elsewhere for that.
Step 6: Connect Everything Together
Solder your resistor to the positive side of your LED.
Make the following connections.
Keypad ribbon cable <--> Arduino Nano pins D2 - D9
Sound module VCC <--> Arduino Nano pin 5V
Sound module GND <--> Arduino Nano pin GND
Sound module K1 <--> Arduino Nano pin D10
Sound module SPK1,SPK2 <--> Speaker wires
LED Positive w/ resistor <--> 5V on Nano 6 pin header (see image above)
LED Negative <--> GND on Nano 6 pin header
Mount everything in the box. I used double sided foam tape for the PCB boards. I also 3D printed a special mount for the sound module and used E6000 glue to attach that to the side of my box. I wouldn't recommend using hot glue or super glue if you are using a metal case like me since it won't stick for more than a day or so.
Step 7: Mount Your Box
On my project box I made keyhole slots so I could easily mount this to a wall if I wanted to. You can do the same thing by drilling one hole slightly bigger than the diameter of the screw head you want to use. Then drill one or two more slightly smaller holes that are on center but above the original hole. See the picture above if that doesn't make sense.
Step 8: Further Development
Now that you have your secret code box working, why not modify the project to do something else? You could turn on a light by using a relay. You could control a programmable LED strip to run a pattern based on which number you press. You could make a box that only opens when you enter the right code.
I hope you had fun building this project!