Hi there! I recently built the following setup: A massive, 20kg bronze head ist connected to a metal touch sensor (KY-036) and as being touched one of 30 audio files is played via my Arduino/Adafruit compound. At the beginning playback works just fine. But after a while the files are being played without me touching the sensor. Since there is a LED on the sensor which lights up as soon as there is an input signal I think I can rule out any interferences on the sensor side …
I am pretty new to the Arduino world and copied the code from different tutorials to the best of my understanding. I would appreciate it very much if you could have a look at my code and tell me what's wrong. Thanks in advance!
// include SPI, MP3, Servo and SD libraries
#include <SPI.h> // We will use the hardware SPI pins: CLK (13), MISO (12), MOSI (11)
#include "Adafruit_VS1053.h"
#include <SD.h>
char trackName;
int Digital_Eingang = 2; // Metal Touch Sensor
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
void setup() {
pinMode (Digital_Eingang, INPUT); // Metal Touch Sensor
uint32_t seed = 0;
for ( uint8_t i=10 ; i ; i-- ) {
seed = ( seed << 5 ) + ( analogRead( 0 ) * 3 );
}
randomSeed( seed );
Serial.begin(9600);
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
SD.begin(CARDCS); // initialise the SD card
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(20,20);
}
void loop() {
int Digital;
Digital = digitalRead (Digital_Eingang);
if(Digital==1)
{
char trackName[ 13 ];
int group = 4; // can be 1 to 10 for your code
sprintf( trackName, "trk%02d_%02d.mp3", group, random( 30 ) );
// output will have the form "trk09_07.mp3", assuming the random number was 7
musicPlayer.playFullFile( trackName );
}
}