Hope you are well. I have a problem with my Arduino code. I have LED_Function() which is working in Loop () fine, what I want, when I send “ON” from the firebase (the Arduino has got the message) the LED_Function()
is stop working and execute the (DeviceStatus.stringData() == "ON")
conditions (continuous condition till I send OFF). When I send “OFF”, LED_Function() is stop working and the code execute (DeviceStatus.stringData() == "OFF") conditions. If I didn’t send anything, the LED_Function()
is working continuously. Please, I appreciate if you could help me in this matter.
void loop() {
LED_Function();
Firebase.getString(DeviceStatus, "LED_STATUS/LED");
Serial.print("The signal is: ");
Serial.println(DeviceStatus.stringData());
if (DeviceStatus.stringData() == "ON") {
Firebase.setFloat(DeviceStatus, "LED_STATUS/LED", 55);
digitalWrite(led2, HIGH);
digitalWrite(led, LOW);
Serial.println("Led Turned ON");
}
if (DeviceStatus.stringData() == "OFF") {
Firebase.setFloat(DeviceStatus, "LED_STATUS/LED", 55);
digitalWrite(led2, LOW);
digitalWrite(led, HIGH);
Serial.println("Led Turned OFF");
}
}
void LED_Function() {
int Detect = analogRead(SensorRec);
if (isnan(Detect)) {
Serial.println(F("Failed to read from Laser sensor!"));
return;
}
if (Detect < 300) {
Serial.println("Laser Cut. Data is disptched to the Firebase!");
digitalWrite(led5, LOW);
digitalWrite(led7, LOW);
float val = 1.0;
Serial.println(val);
}
else {
float val = 2.0;
digitalWrite(led, HIGH);
digitalWrite(led7, HIGH);
Serial.println(val);
}
}