Lucky Coin Block

by RalfZeilstra in Circuits > Arduino

127 Views, 0 Favorites, 0 Comments

Lucky Coin Block

CoinBoxFinal.jpg

I made a Lucky Coin Box with an ESP32 controller that makes coin sounds when shaken. It detects fast acceleration and depending of the speed treshold it makes a coin sound! Continuous shaking keeps the sound playing giving you tons of coins!

This project was made for a school project.

Supplies

Things I used for the circuit:

1x ESP 32 Devkit

1x MPU-6500 Accelerometer

2x Speaker

4x Simple Wire

1x Experimental circuit board


Things I used for the build and casing:

Wood for the casing

Tin for soldering

White & Yellow Paint

Screws


Tools I used for making this:

A computer for coding and uploading the code

Saw

Sandpaper

Soldering iron

Woodglue


Software I used:

Audacity

HxD

Arduino IDE

Setup Code and ESP32

EspSetupUnsoldered.jpg
Diagram.png

Setup MPU-6500 and Speaker

First off connect your MPU-6500 and Speakers as shown in the diagram.

Then add ITTTProject.ino and open it in Arduino IDE.

Downloads

Setup Audio

ProjectRate.png
SaveAsWav.png
Encoder.png
OpenHxD.png
CopyAsC.png

For this project I stored the sound's data in another header file. That way this huge line of code is separated in a different place but still easy to use. In the file I attatched is a coin sound implemented but you could replace it with your own sound if you want to. You need to put the sounddata.h file in the same folder as ITTTProject.ino.

How to add own sound:

First off download your audio file as mp3 or wav file.

I used Audacity to change the audio's Project Rate (Hz) to 16000.

Then I saved the project as a wav file. Change the encoder to Unsigned 8-bit PCM.

After exporting the audio to a wav file you need to use HxD to export is to it's hex values.

Open up HxD and open the audio file, select all values and copy as C code.

Ctrl+a to select all and then Edit>Copy As>C.

Now Paste this code in SoundData.h.

Change the name of the array to audioRaw.

Like this:'unsigned char audioRaw[6850] = {'

Downloads

Solder Together

SolderedTop.jpg
SolderedBottom.jpg
SolderedSpeakers.jpg
SolderedFinal.jpg
SolderedFinalBottom.jpg

Solder ESP-32 to the ciruit board.

Solder MPU-6500 to the same board, make sure to keep some distance if possible with the pins to make it easier to solder the connections.

Solder the speakers in series and solder them next to the pins of the ESP-32 so it's easy to solder them directly together.

Then add the connections with the MPU and Speakers. Make sure everything is connect correctly.


Casing (Optional)

Case.jpg
Case2.jpg
Case3.jpg
Case4.jpg

I made a wooden casing for this project. You can make anycasing that works for you so you dont have to follow this step if you want!

I made a case out of wood. Make sure the speakers aren't blocked off completely and everything fits well.

Also have an opening for the power if you're not using a battery pack.

I made sure the wood stays together with wood glue except for one side I screwed shut. That way I can still open it.

Use your sandpaper to make sure the cube is comfortable to hold with both hand.

I painted it yellow and white paint, but you can use anthing to decorate it, though make sure not to block the speaker holes.

Addition (Optional)

Extra thing you could do:

My project has it's flaws and there are many thing that you could improve!

Amplify sound. You could amplify the sound because this project has low powered speakers and are very soft in a room with other sounds. You could look into using a transistor like BC337 to amplify it or an aplify ciruit board that does the work for you.

Add a SD card: Currently I put the sound data directly in the code which takes up a lot of space. For an arduino atleast. If you want more sounds to play or be cleaner with the hardware you could add your own SD card module.

Add a battery pack: You could add a battery pack instead of directly wired to keep it more portable than mine.


Additional sources I used to make this project:

https://randomnerdtutorials.com/esp32-mpu-6050-accelerometer-gyroscope-arduino/

https://www.buildlog.net/blog/2018/02/game-audio-for-the-esp32/

https://www.hackster.io/electronicsworkshop111/esp-32-based-audio-player-6a6bee

https://www.xtronical.com/the-dacaudio-library-download-and-installation/

https://www.myinstants.com/en/instant/jixaw-metal-pipe-falling-sound-28270/

Conclusion

I learned a lot with this project. I also took many shortcuts to make sure I get to finish the project. The learning didn't stop with arduino it also taught me a bit of C++ and how to use the saw and sandpaper effieciently. If I were to create this project again I could make it a thousand times more awesome! I hope this helped you create and learn.