Minimal Arduino Sound Effect Box
by udubinsky in Circuits > Arduino
2874 Views, 10 Favorites, 0 Comments
Minimal Arduino Sound Effect Box
This is a quick project of a sound effect box.
The device reads a prerecorded wav file from a microSD assigned to a specific button and plays it when pressed.
You Will Need :
Arduino pro mini (or other)
microSD module
A speaker with TRS (mic / aux) connection
Female TRS connector
4 Push Buttons
4 220ohm Resistors
Battery holder and batteries - I used the 2 CR2032 coin batteries but you can use other
Double sided male TRS (headphone) cable
Connections
Each buttons connected to VCC and through a 220ohm resistor to GND (for pulling down false current on the cable) ahead of the resistor each button connected to the Arduino's digital pins 5,6,7,8.
The TRS connector is connected to GND and to the Arduino's 9th digital pin.
The microSD module is connected to the Arduino as follow :
GND => GND
Vcc => Vcc
MISO => 12
MOSI => 11
CS => 4
SCK => 13
The battery + is connected to RAW and - to GND
Setting the Wave Files
The wav files should be at 16000khz 8bit mono.
Name them by the button number you are going to assign them (1,2,3,4)
You can use this site to convert your files
https://audio.online-convert.com/convert-to-wav
The Code
The code uses 2 libraries you should make sure you have (if you don't download them through the lib manager) :
SD.h
TMRpcm.h
#include //include SD module library
#include //include speaker control library #define SD_ChipSelectPin 4 //define CS pin #define B1 5 //4 buttons pins connections #define B2 6 #define B3 7 #define B4 8 TMRpcm tmrpcm; //crete an object for speaker library void setup() { Serial.begin (9600); pinMode (5, INPUT); //4 bottons initialise as INPUTS pinMode (6, INPUT); pinMode (7, INPUT); pinMode (8, INPUT); tmrpcm.speakerPin = 9; //define speaker pin. //you must use pin 9 of the Arduino Uno and Nano //the library is using this pin if (!SD.begin(SD_ChipSelectPin)) { //see if the card is present and can be initialized return; //don't do anything more if not } tmrpcm.setVolume(6); //0 to 7. Set volume level tmrpcm.play("start.wav"); //the sound file "1" will play each time the arduino powers up, or is reset } void loop() { // Serial.println (digitalRead (8)); if (digitalRead (B1)) { Serial.println ("B1"); tmrpcm.play("1.wav"); delay (100); } if (digitalRead (B2)) { Serial.println ("B2"); tmrpcm.play("2.wav"); delay (100); } if (digitalRead (B3)) { Serial.println ("B3"); tmrpcm.play("3.wav"); delay (100); } if (digitalRead (B4)) { Serial.println ("B4"); tmrpcm.play("4.wav"); delay (100); } }
Final Connections...
Connect the device through the TRS connector with the TRS cable to the speaker.
Connect the device to power and turn it ON
...HAVE FUN...