How Much Do You Pay for Your Cache ?
by feiticeir0 in Circuits > Arduino
5298 Views, 48 Favorites, 0 Comments
How Much Do You Pay for Your Cache ?
This one is what's called a "Smart Cache" or "Gadget Cache".
I've always wanted to do this type of caches and to finally start using the bunch of Arduinos and other electronics stuff that I have at home. So, nothing like create a fun cache with a "puzzle" .
In this type of caches it's necessary to "solve a puzzle" to get to the logbook.
This puzzle is just pay the asked quantity for the lock code of the padlock that locks the logbook.
Some considerations:
- Use small change (no one goes out Geocaching with a lot of changes in the pocket - if any change at all)
- Use, at max, 6 to 7 coins
Thus, this cache was born.
When inserting the quantity (more than the quantity - more on that later) shown on the display, the lock code is displayed, giving access to the logbook.
Supplies
To create this cache, we're going to need for the electronics:
- 1x Arduino UNO (any other should do - in the schematics is a NANO)
- 1x 4 digit 7-segment display
- 1x Coin Acceptor (CH-926)
- 1x LM2587 step up (for 12v)
- 1x 4xAA batteries support
For the container, some wood scraps to create a rectangular box big enough for everything.
Some paint to decorate the cache
A 4 digit code padlock
A couple of screw eye for the padlock
Geocaching
"Join the world's largest treasure hunt."
I've been doing Geocaching for a long time now.
I just love discovering new places, the Nature and solving crazy puzzles. The essence of Geocaching is, by solving puzzles, reading clues or by just going straight to the place, to discover a geocache.
A geocache is something (most of the times, a Tupperware) that another geocacher hid (sometimes in plain sight) that coins a logbook, some times some swagg, and, on the rare occasions, a geocoin or a trackable.
The logbook, a piece of paper, is for you to sign, as a testimony that you've been there (you must also log your visit on the geocache page at Geocaching.com) .
The intencion of the Geocacher with that geocache is for you to have fun, solve a crazy puzzle, take your family to walk a rail on a sunny day or just for you to discover a wonderful place.
There are some crazy geocaches out there - some you must solve at night, others require a UV light, some water, for you to use a bycicle pump and others just for you to crack your head thinking of a solution... Or just to spend hours searching for a geocache and never to be found. There's even one Geocache on the International Space Station. Someday, it could be the moon or mars. Imagine when traveling amonst the stars is just like taking a bus to another town (a spaceship to another planet) - Geocaching would be crazy hard ! :)
But, there's another side to it: instead solving other one's caches, create your own, give them a theme, a twist and watch (read) the Geocachers reactions.
Since I was little, I love treasure hunts. I'm from the 80s, and movies like The Goonies just filled one's imagination. Who didn't want to find a pirate's treasure ? Or just like Indiana Jones. Not for the whip, but for the clues, the puzzles, the stories.
Electronics
My biggest problem with this cache was the voltage and energy. The coin selector works at 12v. I didn't want to make the Geocacher to have to buy a crazy 12v battery (like the 23A 12v) just for this cache - keep things simple and cheap. This way, a step up for 12v was needed.
Why not using a 9v battery and still use the step up ?
A simple answer - Energy.
A 9v battery has about 600mAh, while the AA 1.5v has about 3000mAh with a discharge about 25mA. The coin selector uses a lot of energy. 4x AA (6v) are better than 1x 9V . Still, they need to be new or almost full for it to work.
You can read more about energy density in the 9v batteries here.
The wiring is straightforward, but there's a small detail that, if not done, the coin acceptor will not read any coins:
- Both the coin selector and the Arduino must share the same GND.
For the signal wiring, it's necessary a 10k resistor connected to 5v and to D2.
You now need a multimeter to regulate the voltage from the LM2587 step-up. Wire the battery holder to the step-up input.
Place your multimeter in the output of the LM2587 and with a screwdriver rotate the small screw on the potentiometer until you see 12v.
Now, connect the output will go to the Arduino and the Coin Acceptor. Just follow the schematics.
7-segment Display
The 7-Segments display can be of two types - common Anode or common Cathode.
Mine are common Anode, meaning all the anodes are connected to VCC and the individual segments are turned on and off by switching power to the cathodes. If it's low, then the segment is turn off and vice-versa.
Here's an excellent, excellent learning tutorial on the wiring and the types of 7-segment displays. You just need to know yours.
https://www.circuitbasics.com/arduino-7-segment-display-tutorial/
Basically, each segment of the 7-segments display (single ones. This may change for double or quadruple digits) has a pin that needs to be connected to the Arduino. You need to know yours and see the datasheet to know what letter the pins are.
As you can see from the schematics, my 7-segment display has 12 PINs - A to F, DP and D1 to D4.
A to F refer to the segments (see the picture). D1 to D4 refer to which digit is referring to. D1 from the leftmost one (one thousands) to D4, the rightmost one (ones).
The tutorial above explains very well all this and we're going to use the same library, so , you can read the tutorial and learn how to use the library.
Coin Acceptor
The coin acceptor, I've bough it on Aliexpress - CH-926 model. This ones work very well with an Arduino - I'm guessing other models may work too.
The programming of it is fairly easy (although at first time won't seem so) - Mine can be programmed to recognize up to 6 different coins - but I've only programmed 3 :
- 0.05 (5 euro cents)
- 0.10 (10 euro cents)
- 0.20 (20 euro cents)
Using this small coin values, will make the quantities smaller.
When programming the coin acceptor, it's necessary to set the number of pulses it will send to arduino, when detecting a coin. For each programmed coin, a number of pulses is set.
so, to be easy on the programming, I've decided to go for multiples of 5. When a 5 cents coin is detected, it will send 1 pulse, 2 pulses for 10 cents and 4 pulses for 20 cents. Just this easy.
You can read your coin acceptor instructions to know how to program it, but It's always easy with a video.
This instructable explains it very well and detailed.
and this Youtube video by Mario or the Arduino Project Hub page.
Container
For the cache container I needed a wooden box big enough for the coin acceptor, the 4 digit 7-segment display and to have a small door for the logbook.
On the back I've secured the Arduino with 4 screws.
On the front, I've created some holes for the 7-segment display and the coin selector. You can unscrew the front of the coin selector and secure it firmly with screws to the front of the container.
You can see image 3.
Code
For the 7-segments display, we're going to use the SevSeg library, by Dean Reading. To install it, you can use the Arduino IDE library manager.
Let's go through it and explain the key sections.
First, a brief explanation how the coin acceptor works (the same already above):
I've programmed my coin acceptor to recognize 3 coins (it can be programmed to recognize up to 6 different coins):
- 0.05 (5 euro cents)
- 0.10 (10 euro cents)
- 0.20 (20 euro cents)
Using this small coin values, will make the quantities smaller.
When programming the coin acceptor, it's necessary to set the number of pulses it will send to arduino, when detecting a coin. For each programmed coin, a number of pulses is set.
so, to be easy on the programming, I've decided to go for multiples of 5. When a 5 cents coin is detected, it will send 1 pulse, 2 pulses for 10 cents and 4 pulses for 20 cents. Just this easy.
Let's dive into the code
The following line defines what coin values we're going to accept
static float valuesCoins[] = {0.05, 0.10, 0.20};
Next, let's define an interrupt.
attachInterrupt (coinPin, impulseDetected, RISING);
An interrupt will signal the Arduino, as soon it detects a signal on the defined Pin, to stop everything it's doing and take care of that function.
randomSeed(analogRead(0)); int numCoins = random (2, 8); //7 coins is the max, always at least 2 for (int i = 0; i < numCoins; i++) { float valueArray = valuesCoins[random(0,3)]; valueToOpen = valueToOpen + valueArray; }
numCoins it's the number (random) of coins we're going to use to calculate the money value that's going to be need to reveal the padlock code.
The loop code will execute the number of times as the numCoins is. Inside, we're going to add to the valueToOpen (this is the money's sum to reveal the code for the padlock) a random value from the accepted coins.
IE: numCoins = 3 (The geocacher will have to insert 3 coins to reveal the padlock code).
The next loop will run 3 times, each time will select a random coin value from the accepted coins.
0: valueCoins[2] - 0.20 cents
1: valueCoins[0] - 0.05 cents
2: valueCoins[0] - 0.05 cents
The value shown on the 7-segments display to be paied to reveal the padlock code is 0.30 cents. I know the Geocacher could just insert 6 0.05 cents coins, but you get the thought.
This way I can keep the quantities small .
Loop function
void loop() { //show the value that we need to insert valueToDisplay = valueToOpen * 100; sevseg.setNumber (valueToDisplay, 3); sevseg.refreshDisplay(); //if they already insert the full (and more) amount if (valueToOpen <= 0) { //cache open sevseg.blank(); delay (1000); animation1(); while (1) { //stay here forever //show the padlock code sevseg.setNumber (lockCode); sevseg.refreshDisplay(); } } }
The 7-segment display requires that the value to display be always displayed and do a refresh, or it won't show anyhting. This is in the documentation.
When valuetoOpen (where we're removing the amount inserted) reaches to, or be less than 0, it means the Geocacher already inserted all the coins (or the amount requested) and we can show the padlock code to reach the logbook.
We just display the padlock code in a infinite loop - we don't need anything more until they remove the batteries.
Floating point values
For the display to show the decimal places and because of the way the library works, to the value to be inserted, we just multiply by 100 and place a dot on the 3rd digit.
IE:
Value to insert: 0,60 cents
For the display (4 digits), multiply by 100:
0,60 * 100 = 60
The line:
sevseg.setNumber (valueToDisplay, 3);
will place the value, 60. Because we have the leading zeros option ON, it will display 0060.
The number 3 tells the library to place the dot on the 3rd digit, staying 00,60.
Function impulseDetected
This functions is executed everytime a pulse is dected on the configured Pin. Remember the Interrupt ?
In this example, it's the PIN 0, but physically on the Arduino is 2. This is because Arduino UNO has 2 PINs that can be configured for interrupts - physically PINs 2 and 3, beeing internally 0 and 1.
You can read more about this here.
void impulseDetected() { cli(); //For every impulse, we remove 0.05 from the value to open valueToOpen = valueToOpen - 0.05; //totalAmount = totalAmount + 0.05; sei(); }
What this function does is, for every pulse detected, we remove 0,05 cents from the total value. Remember, I've configured my Coin Acceptor with pulses being multiples of 5 - to get easy on the math.
I've attached the code in this step.
Downloads
Code - Animations
To make this 7-segment display a bit more dynamic, I've configured some animations to be displayed when starting and before showing the padlock code.
I could do this because the library allows to turn on just the segments that we want. The library documentation explains everything.
In this case, a binary value is sent where 1 is on and 0 is off.
The binary value is the following: 0b0xxxxxxxx
Each X matches one of the segments: 0b0GFEDCBA
This way, we can just turn on individual segments.
An example of the startup animation is on this section.
The functions are animation1() and animation2() .
The library function is:
sevseg.setSegmentsDigit(0, 0b00110000);
Where the 0 is the digit (of the 4 digits in the display) - being 0 the leftmost one and 3 the rightmost one.
Next, is the binary code where we identify what segment we want to turn on.
In this case, this is show the first bar on the animation - turning on segments F and E and everyone else off.
Conclusion
Well, I'm hoping everyone has fun doing this Geocache.
It already has a place to stay, but I'm waiting on Spring time to place it.
You can visit the cache page here - code is: GC9K8JH .
Here's a video from the cache working