HC-05 receiving data but not excecuting code

Hello! i bought HC05 BT module for one of my projects, i used it before and I had no problem working with it but this module is reciving data (TX led on arduino nano lights up when i send something) and printing it on serial monitor. But led doesnt turn on, i am using this simple code

#define ledPin 6

void setup() {
  
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600); // Default communication rate of the Bluetooth module
}
void loop() {
  
  if(Serial.read() == '1'){
      digitalWrite(9, HIGH);
      }
    else if(Serial.read() == '0'){
      digitalWrite(9,LOW);}
   
}

and this schematic:

This is Serial monitor:

I tried changing code and schematics, but it doesnt even read data now

hc05-bluetooth-module-cuircuit--600x375_AAxGiNhlFP

(i also tried to upload code from project that worked with anoher bluetooth module)

#include <SoftwareSerial.h>


#define rxPin 2
#define txPin 3

SoftwareSerial mySerial(rxPin, txPin); // RX, TX

char myChar ;

int motor1pin1 = 5;
int motor1pin2 = 6;


int motor2pin1 = 7;
int motor2pin2 = 8;

void setup() {
  // put your setup code here, to run once:

  

  Serial.begin(9600);   
  Serial.println("Goodnight moon!");

  

  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);

  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);


  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);

  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("Hello");
  while(mySerial.available()){
    myChar = mySerial.read();
    Serial.print(myChar);

    if(myChar == '1'){
      digitalWrite(9, HIGH);
      }
    else if(myChar == '0'){
      digitalWrite(9,LOW);}
  }

  while(Serial.available()){
   myChar = Serial.read();}

   
  if(myChar == 'F'){            //move forward(all motors rotate in forward direction)

  forward();
  
}
 
else if(myChar == 'B'){      //move reverse (all motors rotate in reverse direction)

  Backwards();
  
}
 
else if(myChar == 'L'){      //turn right (left side motors rotate in forward direction, right side motors rotate in reverse direction for 100ms & stop)
  
  Right();
}
 
else if(myChar == 'R'){      //turn left (right side motors rotate in forward direction, left side motors rotate in reverse direction for 100ms & stop)
  
  Left();
}
 
else if(myChar == 'S'){      //STOP (all motors stop)
  stop_engine();
}
delay(100);

}

void forward(){

  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);


  digitalWrite(motor2pin1, HIGH);
  digitalWrite(motor2pin2, LOW);
  delay(1000);
  
  }

void stop_engine(){
  
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, LOW);


  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, LOW);

  delay(200);
  
  }

void Backwards(){
  
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, HIGH);

  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, HIGH);
  delay(200);
  
  }

void Left(){
  
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, LOW);

  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, HIGH );
  delay(200);
  }

void Right(){

  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);

  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, LOW);
  delay(200);
  
  }

What if the first character was a '0'?

Thank you for your reply but it doesn't change anything

Does

Have anything to do with it? Also, the white wire in the fritzing doesn't seem to have much to do with your code.

No i connected led to pin 9 and I used that second schematic just to see if it reads data on serial monitor, not to turn on anything. Thank you for your reply

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