Could you start by describing how you envisage the device working? From that we’ll be able to help you with the code. Without a proper understanding, coding is just the art of adding bugs to an empty file.
Well I’m making a cache box for the app game Geocaching.
The panel of the box has 6 buttons, a LED, speaker and a battery port. After plugging in the battery the led should light up blue and play a greeting tune. Pressing any one of the the first Five buttons will play an assigned tune. The last button will act as a Enter to confirm tune combination. If tune combination is incorrect LED should blink Red and play tune. If combination is correct LED should light up Green, play tune and activate Solenoid level to unlock the box.
Wow, aren’t you worried someone will walk off with your components?
That sounds easy enough; you’d have the tunes either in your code, or read them from the SD card. But if the tune is a simple sequence of tones, I’d recommend you just keep them in the code.
If I understand that correctly, each of the first 5 buttons will be a tone/note/frequency and the user has to press the buttons in the correct order to match the tune they heard on startup. If that’s the case, you wouldn’t need an Enter button because the number of notes is given. By that I mean if the startup played a tune of 6 notes, the user should press buttons 6 times.
If I’ve understood things correctly, this is how it would/could work:
On power up, make the LED blue, select a tune at random, and play it.
Wait for n button presses and compare the sequence to the tune selected in step 1.
2a. If the tune matches, make the LED green and open the solenoid.
2b. If the tune doesn’t match, make the LED red and start at 2 again.
In essence, this is very much like the Simon game:
Please let me know if that’s correct, or if I’ve misunderstood the sequence.
Questions:
How does the user lock the box again? You could add a sensor (a microswitch) to automatically lock the box when it closes.
I presume the user has to bring their own battery. Have you considered including protection for overcharge and reverse charge for users who bring the wrong battery or plug it in the wrong way around?
The speaker can produce notes of a given frequency by sending a signal of that frequency on the positive pin of the speaker (in the project from the original post, that’s pin 9). In fact, Skyler might be better off with a Piezo buzzer rather than a speaker for durability and size.
All the components will be sealed away inside a cleverly designed bird house. The are careful measures to place to insure that not just anybody can walk off with it.
The theme of the cache is based off The Legend of Zelda Game. The 5 button tunes will be ocarina notes. The unlock code is one of the songs from the game.
I might just have to get my N64 out of the wardrobe again… Have you seen the code to play music notes?
A wedge sounds ideal to lock again, and a USB power source is ideal because it physically prevents reverse polarity. (A 9v battery connector doesn’t.) I’m just not sure what an UNO does if you connect the battery backwards.
What’s this about an APP? How is the phone connected to the device, or how do they synchronise which tune is required?
If you want to collaborate on the code, please let me know and we can set up a repository on Github and possibly email directly. Maybe we could even get the project featured on Circuito.io - who knows.