School Project in Arduino

Hello everyone! For my school project i have to creat an application for control a mp3 module with bluetooth. But i have some trouble, i can connect my phone to my bluetooth modul but the three buttons i made dosen’t work. I don’t know if it is my programm , my blocks or the both :thinking:. Thanks for your help and have a nice day :v: :v:.

[Code]
#include <SoftwareSerial.h>
#include <MP3Player_KT403A.h>

SoftwareSerial mp3(2, 3); // création d’un port série sur les broches 2 et 3
int num_piste = 1; // numéro de la piste courante initialisé à 1
int boutonpin = 4; // Bouton lecture/pause connecté à la broche n°4
int boutonpin_valeur; // Pour lire la valeur du bouton lecture/pause
int mode = 0;
int Next_broche = 6;
int Previous_broche = 8;
int Previous_valeur;
int Next_valeur ;
int infoBluetooth;

void setup()
{
mp3.begin(9600); // initialiser l’objet MP3
delay(100); // attendre 100ms

SelectPlayerDevice(0x02); // Sélectionner la carte SD pour le module MP3
SetVolume(0x1E); // fixer le volume au maxi (1E)

pinMode(boutonpin, INPUT); // configurer la broche n°4 en entrée
}

void loop()
{

boutonpin_valeur = digitalRead(boutonpin); // lire la valeur présente sur le BP lecture et la stocker

if (boutonpin_valeur == 1) // si le BP lecture est appuyé
{
do
boutonpin_valeur = digitalRead(boutonpin);
while (boutonpin_valeur == 1);

if (mode == 0)
{

  mode = 1;
  SpecifyMusicPlay(3);// lire la piste courante
}
else if (mode == 1)
{

  mode = 2;
  PlayPause();
}
else if (mode == 2)
{
  mode = 1;
  PlayResume();
}

}

Next_valeur = digitalRead(Next_broche);
if (Next_valeur == 1)

{
if (num_piste < 3)
{
do
Next_valeur = digitalRead(Next_broche);
while (Next_valeur == 1);
num_piste = num_piste + 1;
PlayNext();
}
}

Previous_valeur = digitalRead(Previous_broche);
if (Previous_valeur == 1)

{
if ( num_piste > 1)
{
do
Previous_valeur = digitalRead(Previous_broche);
while (Previous_valeur == 1);
num_piste = num_piste - 1;
PlayPrevious();

}

}
delay(100);

:
 infoBluetooth = 1 : bouton play/pause pressé
 infoBluetooth = 2 : bouton Next pressé
 infoBluetooth = 3 : bouton Previous pressé

*/
if (mp3.available() > 0) {
infoBluetooth = mp3.read(); // lire la valeur envoyée par le bluetooth et la socker

if (infoBluetooth == 1)
{
  if (mode == 0)
  {
    mode = 1;
    SpecifyMusicPlay(3);// lire la piste courante
  }
  else if (mode == 1)
  {
    mode = 2;
    PlayPause();
  }
  else if (mode == 2)
  {
    mode = 1;
    PlayResume();
  }

}


if (infoBluetooth == 2)
{
  if (num_piste < 3)
  {
    num_piste = num_piste + 1;
    PlayNext();
  }
}


if (infoBluetooth == 3)
{
  if ( num_piste > 1)
  {
    num_piste = num_piste - 1;
    PlayPrevious();

  }
}
delay(100);

}
}

[Code]

It’s good that you supplied source code for both sides.
That makes debugging much easier.

I am suspicious of two things…

What is the purpose of sending a blank or empty string from AI2 before each contr ol code (‘1’, ‘2’, ‘3’) ?

I notice you are sending text ‘1’, text ‘2’, etc from Ai2 but you are receiving into an int variable on the other side.

Are you expecting some kind of automatic conversion to happen in the Arduino from ‘1’ to int 1 ? (I am not sure there is such a thing.)

The ASCII table says ‘1’ = 49 decimal.
So you might check for 49 in the Arduino or use AI2 sendbytes(1) instead of sendtext(‘1’).
Let us know if that works?

Probably all of it. Where did you get your Arduino code from?
This is some Arduino board with a Bluetooth shield. Which one?
Can you find an app to test your Arduino code? Look at one of those Arduino BT controllers, when you can get it to work this way, you can also find out what to send via App Inventor.

p.s. I am curious why you are sending a space or an empty string, followed by a number, as two separate commands?
Cheers, Ghica

I made my code in school and i use base arduino shield with a Arduino Mega 2560. I try to make this, but i dont understand the part with ASCII M.ABG could you tell me more please ? Thanks and have a nice days (again) :metal: :metal:.

Did i need a Logic level converter ?

Maybe i have to do something like this ?

Start by searching for 'Introduction to Serial Communication'.

is a good introduction.

Also search for 'What is ASCII'

is a good introduction.

Does this simple project work for you?

http://thezhut.com/?page_id=670

i think this can work but i dont have the material for the moment.