Grumpy Box Treasure Hunt Clue
by amachinetech in Circuits > Arduino
143 Views, 1 Favorites, 0 Comments
Grumpy Box Treasure Hunt Clue
An Ardiuno powered, MP3 playing, clue box for treasure hunts all contained in a wood box. When shaken, the box turns on and in a grumpy old man voice (mine before coffee) asks for the code. If the code is correct then the clue is delivered. If the code is incorrect the user is mildly verbally abused then the unit shuts off. The creativity is in the MP3 tracks that you record and you can make it as salty as you want. My target audience was high school kids so I didn't get too spicy. This is another in the series of Arduino powered treasure hunt clues from my collection.
Supplies
You will need an Arduino. I used a nano because I got a deal on a handful of them and they are small. Honestly a full sized uno would have fit in this box so use what you got. You shouldn't need mega sized unit and you could use an esp32 if you wanted but its a bit like using a dump truck to go to the grocery store.
MP3 player board. I got a three pack of DY-SV8F. They are somewhat limited as they only have 8Mb of onboard memory. I managed to smush 21 MP3 tracks on it and still have over half of the memory left. If you are looking for a more lengthy project I would suggest getting a DY-SV5W as it has an external SD card that can hold 32GB which is a lot of storytelling.
Pololu power control board - from Pololu - this allows the Arduino to turn off the system
7.4 volt lipo battery - from Amazon -or- 4 AA battery holder and batteries from Amazon
4 ohm speaker - from amazon or something similar
An enclosure - at least 4x6x3 to allow room for the parts to work. You may be able to make smaller with some work. I made a wood one.
red LED and 200ohm resistor for power light
green LED and 200ohm resistor for keyboard flash light
4x4 keypad - from Amazon
spring, and small weight to create the shake sensor.
header pins, wire, 1/16 inch shrink tubing and whatever else you need
Tools:
Arduino support equipment, cords etc
soldering tools
dremel tool or similar
hot glue gun
a snarky sense of humor
Prepare Your Box
For the box you can use pretty much anything that is around 4x8x3 inches. You will need enough room for the shake sensor to move freely without being interfered with by wires, battery etc. I made a wood box but, anything available from a craft store would do. What ever you choose it will need to be of a non-conductive material.
The three things that take up the most space are the battery, the speaker and the space required for the shake sensor. Figure out where you want your speaker to go. You will want it to sit flat up against the front cover so that the sound will be directed at the user. The great outside will suck up a lot of sound so you will want it to be somewhat louder than you think it should be. There is a volume adjustment on the MP3 board so you can program it quietly while the spouse is sleeping and turn it up when you're ready to use it.
You will need to cut slots in the front of the box to allow the sound to come out. You will need to strike a balance between letting as much sound out as possible and still protecting the speaker if it is dropped. I made five slots with a 1/4 inch router bit. After testing this worked well. Previous versions I drilled holes and it muted the sound so that it was hard to understand the voice.
The Shake Sensor
The shake sensor is made using the principle of inertia. A small weight on the tip of a 3 inch long spring acts like a pendulum. When the box is shaken the pendulum moves back and fourth like the little door stop thingy that the cats like to play with. A loop of wire that is a bit larger than the pendulum is situated in a way that when the pendulum is waving back and fourth it will touch the wire loop for just a moment thus turning on the Pololu power control board. You will have to play with the size of the loop around the pendulum to get the effect that you want. The smaller the loop the less force of a shake required to trigger the board. I wanted mine to be able to ride in a car down a medium bumpy road and not be triggered. My weight is steel, 3/8 inch in diameter and 2 inches long. The spring that I have is pretty stiff so a good solid shake is required to create any movement of the pendulum. My loop is about 3/4 inch in diameter and is place about 2/3 of the way in from the tip of the pendulum. Your results will vary. You can move the loop closer or further away from the tip of the pendulum to increase or decrease the sensitivity of the assembly. The closer to the tip is more sensitive. Farther toward the spring is less. The heavier weight and weaker spring will make the pendulum vibrate for longer. You want it to shake for as short a time as you can manage and still be trigger-able without having to physically assault the box. The sensor is mounted to the side of the box by drilling a hole smaller than the threaded rod that is attached to one end of the spring. The rod is then threaded into the wood cutting threads as it goes. Just before seating the spring against the wood, wrap a wire around the threaded rod and then tighten the spring against the wood for a snug fit and a good connection.
Do the Wiring
Connect the Arduino, MP3 board, keypad, power control and shake sensor as shown in the picture.
NOTE: the connection from the Pololu switch to the Arduino is whatever voltage your battery is. You will need to connect it to the Vin terminal of the Arduino to allow the internal power regulator on the Arduino to step it down to the 5 volts that is needed for the Arduino and the MP3 board. If you connect it to the 5 volt terminal on the Arduino you will get magic smoke from both the Arduino and the MP3 board.
You will need to create a way to cram all this stuff inside the box and anchor it with hot glue, velcro, or superglue. Understand this box will be shaken so nothing can be loose and floating around in the box. I used a piece of velcro to attach the battery so I could remove it for charging or for long term storage of the box when it was not being used.
By the way, the Pololu switch uses a very tiny amount of power even when it is off. If you leave a lipo battery plugged in for months it will very slowly drain the battery down. If you over drain a Lipo it will cause permanent damage to the battery. This will take a loong time but if you forget about it on your desk for a month or two it could. When you are not using it just unplug the battery.
Record Your MP3 Tracks
I used Audacity to record my MP3 tracks as it is free, simple to use, turns out a clean track and I already had it from a previous project. You will need to make sure to export the files as MP3s, The board will also play .wav files but they are substantially larger and will use up the memory on the MP3 board before you get more than 2 or 3 tracks loaded. The following list is based on the programming that is included.
Oh one very important thing...actually two. First the MP3 board needs to have all its switches set in the off position which sets it to parallel binary trigger mode. Second when you name the tracks they must have a 5 digit number or the board won't recognize them and won't play them. (IE 00001, 00002, 00255, etc) The max number of tracks that the board can play in this mode is 00255.
I have 22 tracks. You can record whatever you want for the clues but the below tracks need to be structured as follows for the sketch to play them properly:
track 00001: Opening greeting and instructions on how to use the box. This track is only heard one time.
track 00002: "Your code is correct. Prepare to hear the clue"
track 00003: Returning greeting. Will be played every time the box powers up after the first code has been entered. "Welcome back. Enter your code."
track 00004: wrong code entered the first time "that's wrong, you have 2 more chances"
track 00005: wrong code entered the second time "that's also wrong you have one more chance"
track 00006: wrong code entered for the third time. You will now be placed on a 10 minute time out where the box can not be used until the time elapses. "That's wrong, you were warned now your'e on a time out. You have ten minutes remaining in your time out"
---The following tracks are used in the ten minute timeout. They are the individual numbers that are played as the time counts backwards.---
track 00007: "one minute"
track 00008: "two minutes"
track 00009: "three minutes"
track 00010: "four minutes"
track 00011: "five minutes"
track 00012: "six minutes"
track 00013: "seven minutes"
track 00014: "eight minutes"
track 00015: "nine minutes"
track 00016: "thirty seconds"
----tracks used for the shutdown sequence ----
track 00017: "sleeping in 5 seconds" used as a warning before the box auto shuts off
track 00018: "going to sleep" played just before the box auto shuts off
----clue tracks----
track 00019: clue 1 that you wish to be played when code 1 is entered correctly
track 00020: clue 2 that you wish to be played when code 2 is entered correctly
track 00021: clue 3 that you wish to be played when code 3 is entered correctly
track 00022: clue 4 that you wish to be played when code 4 is entered correctly
Testing the Assembly
I have written three sketches to get you to a working version of this project. The first one is the keypad test program. This is used to make sure that all of your wiring for the key pad is correct and outputting the correct numbers for each button press. It can also be used to troubleshoot any problems that you have later. Load "keypadTestGrumpyBox_instructables.ino" and open the serial monitor. When you press each key the button number and button value is displayed on the serial monitor.
The second sketch is to verify that all the connections from the Arduino to the MP3 board are connected correctly. This also uses the serial monitor. Load "serialControlOfMP3_v1.1_instructables.ino" then open the serial monitor. Type the number of the track that you wish to test in the serial monitor then press enter and it will trigger the correct binary output to trigger that track on the MP3 board. Don't type all the preceding 0s of the actual track number in the serial monitor (IE 00002, 00006, 00015. etc). Just type the number then hit enter and the track will play. If you type another number while a track is playing the first track will stop and the new track will start playing. Don't load the final code until this part works well or you will get weird results and it will be very hard to troubleshoot what is going on. This sketch will only trigger 30 tracks. If you wish to be able to trigger more then you will have to expand the sketch to allow it.
The third sketch is the actual operating sketch that makes the Grumpy Box work. If you have good results from the first two sketches then the main sketch will drop right in and run.
How the System Works:
The first time that the box is shaken the first greeting and instructions are played. When you record this track it needs to include the following:
- the box will auto shut off in 30 seconds after the last button press happens.
- if a code is started but not completed after 2 seconds the code is cleared and you will have to start again
- you have 3 chances to correctly enter the code or you will receive a 10 minute timeout where no codes can be entered. The box will stay on and verbally count backwards the time remaining.
- codes cannot be entered while a track is being played.
- the green light will blink slowly when you have 10 seconds left before shutdown.
- the green light will blink fast when you have 5 seconds left before shutdown and a track will be played.
- to restart the box after it shuts down just shake the box.
- each time a button is pressed the red light will flash to let you know that a button has been pressed.
- each time a button is pressed the "go to sleep" timer is reset back to 30 seconds
- to keep the box from starting needlessly keep it upright and shake as little as possible.
- if you need to hear the instructions again press the * key. If you understand these directions then enter your code.
NOTE: if the box goes to sleep with nothing being pressed then the instructions will be played again on startup.
If the * button is pressed the sketch loops back and plays the instructions again. NOTE: if any other button besides the * is pressed the sketch will think that you are entering a code and it will move on and the instructions will not be played again. If you need to reset back to the beginning then enter the code *, #, 3, 6. This will clear the EEPROM, flash the red light three times and shut down the board. This must be done on battery power and not on USB power for the restart to work. Once the board shuts down it is ready to go again from the beginning. The next startup will be the full instructions of track 00001.
If the code that you entered is correct track 00002 will be played saying that the code is correct and prepare to hear the clue. There will be a slight pause then the track that is attached to the code entered will be played. This will be track 00019 for code 1, 00020 for code 2, 00021 for code 3 and 00022 for code 4.
Once the final track has been played a 30 second timer will begin. If no other button is pressed for 20 seconds then a 5 second warning will be played (track 00017). If a button is not pressed in the final 5 seconds the shutdown track will be played (track 00018) then the Pololu power control board will be triggered and the unit will shut down. If the system is plugged in via USB it will not shut down but the sketch will be trapped in a forever loop and nothing will react until the system is restarted.
if the code that you entered is incorrect then the first refusal track is played (track 00004) saying that the code is wrong and that you have 2 more chances before a 10 minute time out.
If the wrong code is entered a second time then the second refusal message is played (track 00005) that says the code is wrong again and that you have one more chance at the correct code before a ten minute time out.
if the code is entered wrong a third time then the third refusal message is played (track 00006) that says that now the user is on a ten minute time out. Codes will not be accepted while the time out is happening. Every thirty seconds a track is played saying the minute. Every other 30 second increment track 00016 is played saying "30 seconds" after the minute is played. When the time runs out then track 00003 will be played. This is the greeting asking for the code. Three more chances are given to get a correct code entered.
A little more on parallel binary trigger mode. The board has 8 inputs, We are only using 5 because we are only triggering a max of 31 tracks. If you look at the graph you will see how the Arduino is triggering each track by turning on a binary sequence then turning it off again. If you were to expand this graph all the way out to 8 inputs you would be able to trigger all 255 tracks.
Adjusting the Code
Inside the final sketch there are 4 variables at the top of the sketch labeled "code1, code2, code3, and code4" These are the four digit codes that need to be entered to allow the clue to be delivered. You may keep them as is or change them. They have to stay a 4 digit number however.
The program decodes the button presses by combining the values of each button press through an algorithm.
Each number 1-9 has its own value. 0 is worth 10, * is worth 11, # is worth 12, A is worth 13, B is worth 14, C is worth 15 and D is worth 16.
When the unit starts the variable that holds the button presses is 0. When the first button is pressed, for instance 6, it is added to the variable. When the second button is pressed the variable is multiplied by 10 then the new button value is added. Third number, multiplied again by 10 then new button is added, Fourth, again multiplied by 10 then button is added. If the button pressed is 0 nothing is added but the variable is still multiplied by 10.
So the variable progression look like this:
start variable = 0
first button =6, variable =6
second button = 7. 6x10=60+7=67 variable =67
button ^
third button = 0, 67x10=670+0. variable = 670
button ^
fourth button =1. 670x10=6700+1=6701
button ^
As long as you use the number keys the four digit number that you alter the codes to will be the same as the numbers that you type. The weird part is when you use all the other keys (*,#,A,B,C,D)
If you look at the sketch below the four codes, there is a reset code. This is used to reset the program back to the beginning so that the instructions are played when the box starts up. This code number is 5 digits. But all entered codes are only 4 digits. The reset code is *, #. 3, 6
The progression looks like this:
start variable =0
first button =11 (*button). variable =11.
second button =12 (# button). 11x10=110+12=122. variable =122
third button =3. 122x10=1220+3=1223. variable=1223.
fourth button =6. 1223x10=12230+6=12236. variable = 12236
This is how we get a 5 digit code from a four button press.
Above I also said that 0 was worth 10. There is one specific line of code that says if the button press = 10 (0 button is pressed) then don't add anything but multiply the variable by 10.
Build something amazing and share
AMachineTech