Go Down

Topic: my bluetooth reception is a non stop loop (Read 484 times) previous topic - next topic

Scootify888

Hello,

I have a JDY-09 module, an rgb led banner, a relay and an arduino UNO card. my project is to control the colors of the led + a relay by bluetooth from my smartphone. Here is my 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);
  } 
}


However, my program was working for a while but now at the very moment I send any information to my Bluetooth module, the serial port shows me that it receives these unknown characters very quickly:"βΈ®" + letters that have nothing to do with it and that makes my program completely buggy. Not finding answers on the internet and being a complete beginner on arduino I allow myself to ask you for your help, I have been struggling on this for more than 2 weeks HELP ME PLEASE
thank you in advance,
:)


Go Up