I am a beginner I ask about the code that I am creating.

I would like to write to get a value from HC-05 and then open RL1, then wait for the value if the command C came to activate RL2 with the condition that RL1 must open if RL1 does not. Open Can not open RL2, but if command B comes out, shut down the 2 blocks. I wrote this correctly.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(3,2);//RX,TX

int RL1 = 4;
int RL2 = 5;

void setup() {
BTserial.begin(9600);
BTserial.println("BTserial");

pinMode(RL1, OUTPUT);
}

void loop() {
if(BTserial.available()){
char ch = BTserial.read();
if(ch == 'A')
digitalWrite(RL1, HIGH);
if(RL1 == HIGH){
char ch = BTserial.read();
if(ch == 'C')
digitalWrite(RL2, HIGH);
delay(1000);
}
else if(ch == 'B')
digitalWrite(RL1, LOW);
}

}

int RL1 = 4;
int RL2 = 5;

Are those pins that control the relays? Don't both need to be OUTPUT?

if(RL1 == HIGH){

That says " if 4 == HIGH " RL1 is the pin number not the state of the pin that digitalRead() returns.

 if(BTserial.available()){
  char ch = BTserial.read();
    if(ch == 'A')
      digitalWrite(RL1, HIGH);
    if(RL1 == HIGH){
      char ch = BTserial.read();

Are there 2 bytes available to read?

Some good techniques for reading Serial input

      digitalWrite(RL1, HIGH);
      if(RL1 == HIGH){

RL1 is a pin number. 4 is NOT HIGH, so that statement will never be true.

if(BTserial.available()){
    char ch = BTserial.read();
    if(ch == 'A')
      digitalWrite(RL1, HIGH);
      if(RL1 == HIGH){
        char ch = BTserial.read();

If there is one byte of serial data to read, it is NOT OK to read two.

If the first character is not 'A', do you want to know if it is 'B', or do you want to know if the next character is 'B', as you are doing now?

Ok i got that. groundFungus
Are those pins that control the relays?

  • yes

Don't both need to be OUTPUT?

  • Yes, I want it to be. pinMode(RL1, OUTPUT); pinMode(RL2, OUTPUT); yes or no?

That says " if 4 == HIGH " RL1 is the pin number not the state of the pin that digitalRead() returns.

  • I need to fix this point. Thank you

Pauls Thank you.I see