Programming LED output - Controlled by PIR & bluetooth HC-05

Hi, i'm new to programming, I want to use a PIR sensor to switch an LED output with the function of an override using bluetooth module (from android app). The bluetooth controller will manually bypass the PIR if I want to switch it on. Appreciate any help with this :slight_smile: -

int a = 12;
int b = 11;
int c = 10;
int d = 9;
int pirPin = 13;
int pirState = LOW;
int val = 0;

String readString;

void setup() {
  Serial.begin(9600);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(pirPin, INPUT);
}

void loop() {
val = digitalRead(pirPin);
if (val == HIGH){
digitalWrite(a, HIGH);
if (pirState == LOW){
  Serial.println("Motion detected!");
  pirState = HIGH;
}
}else {
  digitalWrite(a, LOW);
  if(pirState == HIGH){
    Serial.println("Motion ended!");
    pirState = LOW;
  }
}

while (Serial.available()) {
delay(3); 
char c = Serial.read();
readString += c; 
}
if (readString.length() >0) {
Serial.println(readString);
if (readString == "on1") 
{
digitalWrite(a, HIGH);
}
if (readString == "off1")
{
digitalWrite(a, LOW);
}
if (readString == "on2") 
{
digitalWrite(b, HIGH);
}
if (readString == "off2")
{
digitalWrite(b, LOW);
}
if (readString == "on3") 
{
digitalWrite(c, HIGH);
}
if (readString == "off3")
{
digitalWrite(c, LOW);
}
if (readString == "on4") 
{
digitalWrite(d, HIGH);
}
if (readString == "off4")
{
digitalWrite(d, LOW);
}
if (readString == "af")
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
}

readString="";
} 


}

Hi sorry, yes the code isnt quite right. It currently only looks at PIR sensor output so I cant override it with bluetooth app.

Many Thanks

Where is the Bluetooth code?

Which Arduino do you have? Have you connected the Bluetooth module to the Arduino and paired it with your Android device?

Its an Arduino Uno and yes the bluetooth module is connected. I can switch output LED B, C & D from the blutooth module but not the PIR LED A. When I delete the PIR code, I can switch LED A via bluetooth fine.