hi, there could you please tell me how to make changes to this code so when I try to turn on for example the light manually, the Bluetooth data would override the sensor data? I'm new to Arduino btw
int light_detect = A5;
int lightval;
int night_whitelight=12;
int temp_thermistor=A2;
int tempval;
int blue_cooler=4;
int red_heater= 7;
int buzzer_firealarm=8;
char BluetoothData;
void setup() {
// put your setup code here, to run once:
pinMode (light_detect, INPUT);
pinMode(night_whitelight, OUTPUT);
pinMode(temp_thermistor, INPUT);
pinMode (blue_cooler, OUTPUT);
pinMode(red_heater, OUTPUT);
pinMode(buzzer_firealarm, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()) {
BluetoothData = Serial.read(); //Get next character from bluetooth
if (BluetoothData == 'D') digitalWrite (red_heater, HIGH);
if (BluetoothData == 'd') digitalWrite (red_heater, LOW);
if (BluetoothData == 'E') digitalWrite (blue_cooler, HIGH);
if (BluetoothData == 'e') digitalWrite (blue_cooler, LOW);
if (BluetoothData == 'L') digitalWrite (night_whitelight, HIGH);
if (BluetoothData == 'l') digitalWrite (night_whitelight, LOW);
if (BluetoothData == 'F') digitalWrite (buzzer_firealarm, HIGH);
if (BluetoothData == 'f') digitalWrite (buzzer_firealarm, LOW);
}
tempval = analogRead(temp_thermistor);
int newTempVal = map(tempval, 0, 1023, 0, 100);
Serial.print("T"+String(newTempVal)+"");
Serial.print( "reading from thermistor is " );
Serial.println(tempval);
delay(100);
if (tempval<400) {
digitalWrite (red_heater, HIGH);
}
if (tempval>450) {
digitalWrite(red_heater, LOW);
}
if (tempval>560) {
digitalWrite(blue_cooler, HIGH);
}
if (tempval<530) {
digitalWrite(blue_cooler, LOW);
}
if (tempval>600) {
digitalWrite(buzzer_firealarm, HIGH);
}
if (tempval<570) {
digitalWrite(buzzer_firealarm, LOW);
}
lightval= analogRead(light_detect);
int newLightVal = map(lightval, 0, 1023, 0, 100);
Serial.print("B"+String(newLightVal)+"");
Serial.print("reading from photoresistor is ");
Serial.println(lightval);
delay(100);
if (lightval<=200) {
digitalWrite(night_whitelight, HIGH);
}
if (lightval>=201) {
digitalWrite(night_whitelight, LOW);
}
delay(1000);
}