Android app to control music using Arduino via Bluetooth - Page 1
Forum section: electronics / beginners

author: Nexo
author_rank: Regular Contributor
timestamp: March 05, 2017, 05:35:30 pm
content: Hello everyone!This is what I've done:1) I've created a small app that connects my Android phone to the Arduino using a BT module. This is the code:Code:char data = 0; //Variable for storing received datavoid setup(){Serial.begin(9600); //Sets the baud for serial data transmissionpinMode(13, OUTPUT); //Sets digital pin 13 as output pin}void loop(){if(Serial.available() > 0) // Send data only when you receive data:{data = Serial.read(); //Read the incoming data & store into dataSerial.print(data); //Print Value inside data in Serial monitorSerial.print("\n");if(data == '1') // Checks whether value of data is equal to 1digitalWrite(13, HIGH); //If value is 1 then LED turns ONelse if(data == '0') // Checks whether value of data is equal to 0digitalWrite(13, LOW); //If value is 0 then LED turns OFF}}2) I've looked for on internet and found this site:https://diyhacking.com/arduino-audio-player/in which the author uses a SD adapter module and plays the music from a SD card using the following code:Code:#include "SD.h"#define SD_ChipSelectPin 4#include "TMRpcm.h"#include "SPI.h"TMRpcm tmrpcm;void setup(){tmrpcm.speakerPin = 9;Serial.begin(9600);if (!SD.begin(SD_ChipSelectPin)) {Serial.println("SD fail");return;}tmrpcm.setVolume(6);tmrpcm.play("rain.wav");}void loop(){ }So my questions are these:1) How can I merge this two programs on Arduino and App Inventor in order to, instead of turning on/off an LED, I could be able to control the music?2) Using TMRpcm.h is the only way to play music form the SD card?3) in the last code, there is this line: "tmrpcm.play("rain.wav");" Which means that when I turn on the Arduino it will play the song named "rain" everytime, what if I wanted to load more songs and I'd like to choose them from the App, how can I accomplish this?Thanks in advance!PS: I'm new to Arduino and App inventor, sorry if I made a mistake.

author: Nexo
author_rank: Regular Contributor
timestamp: March 06, 2017, 05:27:11 am
content: Someone please

author: Nexo
author_rank: Regular Contributor
timestamp: March 06, 2017, 02:56:12 pm
content: This is my attemp of merging, could anyone please tell me if there is something wrong?Thanks in advance.Code://Audio code#include "SD.h"#define SD_ChipSelectPin 4#include "TMRpcm.h"#include "SPI.h"TMRpcm tmrpcm;//BT codechar data = 0; //Variable for storing received data//BTvoid setup(){Serial.begin(9600); //Sets the baud for serial data transmissionpinMode(9, OUTPUT); //Sets digital pin 9 as output pintmrpcm.speakerPin = 9;Serial.begin(9600);if (!SD.begin(SD_ChipSelectPin)) {Serial.println("SD fail");return;}tmrpcm.setVolume(6);tmrpcm.play("r");}void loop(){if(Serial.available() > 0) // Send data only when you receive data:{data = Serial.read(); //Read the incoming data & store into dataSerial.print(data); //Print Value inside data in Serial monitorSerial.print("\n");if(data == '1') // Checks whether value of data is equal to 1digitalWrite(9, HIGH); //If value is 1 then LED turns ONelse if(data == '0') // Checks whether value of data is equal to 0digitalWrite(9, LOW); //If value is 0 then LED turns OFF}}