Go Down

Topic: bluetooth reception probleme (data recu non stop) (Read 458 times) previous topic - next topic

Scootify888

Bonjour,

je dispose d'un modul JDY-09, d'un bandeau led rgb, d'un relai et d'une carte arduino UNO.Mon porjet est de controler les couleurs de led + un relais par bluetooth depuis mon smartphone. Voici mon code:

char color=0; //store the received byte here

//define the RGB pind
int pc=7;
int red = 3;
int green = 5;
int blue = 9;
int pc_state = 0;
int Received=0;
char received;

void setup()  {
 Serial.begin(9600);     //Start the serial comunication for the bluetooth module
 pinMode(red, OUTPUT);   //Red color pwm pin defined as output
 pinMode(green, OUTPUT); //Green color pwm pin defined as output
 pinMode(blue, OUTPUT);  //Blue color pwm pin defined as output
 pinMode(pc,OUTPUT);
 //Give first value of the PWM 0, we start with the RGB LEDs off
 analogWrite(red,255);
 analogWrite(green,255);
 analogWrite(blue,255);

}

void loop()  {
 
 if(Serial.available()>0){
   // read the bluetoot data and store it
   color = Serial.read();
   char Rec = char(color);
   if (Rec != '0')
   {
   Serial.println(Rec); //This is to visualise the received character on the serial monitor
   }  
 }

/////////////RELAY/////////////////
 if (pc_state == 0 && Received == 'a')
 {
   digitalWrite(pc,HIGH);
   pc_state=1;
   Received=0;  
 }
if (pc_state ==1 && Received == 'a')
 {
   digitalWrite(pc,LOW);
   pc_state=0;
   Received=0;
 }
//////////////////////////////

//////////////////////////////

 //LEDs off
 if (color == 'n')
 {
   analogWrite(red,255);
   analogWrite(green,255);
   analogWrite(blue,255);
 }
 //White
 if (color == 'w')
 {
   analogWrite(red,0);
   analogWrite(green,0);
   analogWrite(blue,0);
 }
 //Red
 if (color == 'r')
 {
   analogWrite(red,0);
   analogWrite(green,255);
   analogWrite(blue,255);
 }
 //Green
 if (color == 'g')
 {
   analogWrite(red,255);
   analogWrite(green,0);
   analogWrite(blue,255);
 }
 //Blue
 if (color == 'b')
 {
   analogWrite(red,255);
   analogWrite(green,255);
   analogWrite(blue,0);
 }
 //Orange
 if (color == 'o')
 {
   analogWrite(red,0);
   analogWrite(green,98);
   analogWrite(blue,255);
 }
 //Violet
 if (color == 'v')
 {
   analogWrite(red,148);
   analogWrite(green,255);
   analogWrite(blue,107);
 }
 //Cyan
 if (color == 'c')
 {
   analogWrite(red,255);
   analogWrite(green,0);
   analogWrite(blue,0);
 }
 //Yellow
 if (color == 'y')
 {
   analogWrite(red,0);
   analogWrite(green,51);
   analogWrite(blue,255);
 }  

 if (color == 'p')
 {
   analogWrite(red,0);
   analogWrite(green,255);
   analogWrite(blue,20);
 }  
}


Or, mon programme fonctionnait un certain temps mais maintenant à l'instant meme ou j'envoie une quelconque information a mon module bluetooth, le serial port me montre qu'il recoit à l'infini très rapidement ces caracteres inconnu:"⸮" + des lettres qui n'ont rien a voir et cela fait donc complètement buger mon programme. Ne trouvant pas de réponses sur internet et étant completement débutant sur arduino je me permet de vous demander votre aide, je galère sur ca depuis +de 2 semaines AIDEZ MOI SVP
merci à l'avance,
:)

Go Up