1

The L1 is the value i will get from firebase database, but now i wanna send the value that i receive in realtime database to arduino to on LED, how to solve? any suggestion? which mean when arduino receive value 1 from firebase then led will on

ESP8266 code :

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run 
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
#define WIFI_SSID "Home "
#define WIFI_PASSWORD ""

int value1;

void setup() {
  //Initializes the serial connection at 9600 get sensor data from arduino.
  Serial.begin(9600);
   
  delay(1000);
  
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);  
  }

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 
  Firebase.setInt("L1",0);  
}

void loop() 
{
  while(Serial.available())
  { 
        value1 =  Firebase.getString("L1").toInt();  
  }
  
  delay(1000);
}

Arduino code:

#define LED 13;

int value1;

void setup()
{
  pinMode(LED,OUTPUT);
  Serial.begin();
}

void loop()
{
  if (value1 == 1)
  {
     digitalWrite(LED, HIGH);
  }
}
4
  • see the basic examples in IDE examples menu
    – Juraj
    Jul 9 at 12:13
  • Which one should I see?
    – Anohana
    Jul 9 at 14:04
  • all of them .... think about this in your code what will be the state of the LED when value1 is not equal to 1?
    – jsotola
    Jul 9 at 15:09
  • if the value not equal to 1, LED will be off
    – Anohana
    Jul 9 at 15:25
1

ESP8266 code :

   #include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run 
#define FIREBASE_HOST ""
#define FIREBASE_AUTH ""
#define WIFI_SSID "Home "
#define WIFI_PASSWORD ""

int value1;
String string_value;
void setup() {
  //Initializes the serial connection at 9600 get sensor data from arduino.
  Serial.begin(9600);
   
  delay(1000);
  
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);  
  }

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 
  Firebase.setInt("L1",0);  
}

void loop() 
{
 
        value1 =  Firebase.getString("L1").toInt(); 
        string_value = String(value1);
        Serial.print(string_value);
         
  
  
  delay(1000);
}

Arduino code:

    #define LED 13

int value1;
String data;

void setup()
{
  pinMode(LED,OUTPUT);
  Serial.begin(9600);
}

void loop()
{

  bool Sr =false;
 
  while(Serial.available()){
    
        
        data=Serial.readString(); 
        value1 =data.toInt();
        Sr=true;    
        
    }

    delay(500);

    if(Sr){
      
        if (value1 == 1)
        {
           digitalWrite(LED, HIGH);
        }else if(value1 == 0){
          
            digitalWrite(LED, LOW);
          }
   }
}

For More details:

https://www.youtube.com/watch?v=ji71cHaGW8w

1
  • Thank you for your help.
    – Anohana
    Jul 11 at 11:24
0

Your ESP needs to

  • receive data from Firebase over WiFi;
  • send the received data (or the useful part of it) to the Arduino, over its serial port.

Your Arduino needs to:

  • watch its own serial port for data becoming available;
  • read the data;
  • decide whether turn the LED on or off.

Your loop() code on the Esp is watching its serial port, but from your description, it shouldn't expect any data from its serial port - that is connected to the Arduino. You need to watch for data arriving via WiFi instead.

Your Arduino code is testing the variable value but value never gets set to anything. You should set it according to what you receive from the Esp.

Also, since I'm not familiar with Firebase, does the Esp need to tell Firebase each time it wants new data? Or does Firebase send data at intervals without you having to ask for it? If it's the former, your Esp will need code to ask for the data and wait for it to arrive before it can send it on to the Arduino.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.