Bluetooth led won't light on

I have my bluetooth working (can send messages and they appear in the Arduino monitor..)
baud rate is 115200

But the Led won't light on when sending value"1" ... ?
led is correctly plugged in.
Any Ideas
Thanks a lot

#include <SoftwareSerial.h>
SoftwareSerial HMSoft(6,7);
const char LED = 9 ;
String messageRecu;

void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
void loop()
      char c =;
      messageRecu += c;
    if (messageRecu.length() >0)
      if (messageRecu == "1")     
        {digitalWrite(LED, HIGH);}
      if (messageRecu == "0")
        {digitalWrite(LED, LOW);}

Does the sender append a line feed (/n) and/or a carriage return to the sent message?

are you sure that the length of 'messageRecu' is exact and ONLY one character long? When transmitting, a 0 byte or a CR can also be added. When receiving, you simply convey everything that comes in in your 'while' loop into the char variable 'messageRecu'. but there are usually also 'end of transmission' characters. And so the comparison 'messageRecu == "1"' does not work because 'messageRecu' always consists of several characters. So you have to make sure when receiving that ONLY the actual command ends up in messageRecu.

Since you are using the String class the trim() function may be of interest. The trim() function can remove any white space characters (\n \r) from the serial input.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.