Firebase Arduino
Firebase Arduino
String data1;
int temp;
void setup() {
Serial.begin(115200);
}
Code
void loop() {
int reading = analogRead(AsensorPin);
NodeMCU to Arduino
NODEMCU ARDUINO
• RX ------------------------- 11 (TX)
• TX ------------------------- 10 (RX)
• GND -------------------------- GND
SETTING UP NODEMCU
GO TO FILE > PREFERENCES > ADDITIONAL BOARD MANAGER URL
and paste
https://github.com/esp8266/Arduino/releases/download/2.7.4/
package_esp8266com_index.json
TOOLS > BOARD MANAGER
//Initialization of variables
// Define the analog pin, the LM35's Vout pin is connected to
#define AsensorPin A0
Sending Data From Arduino To NodeMCU
String data1;
int temp;
void setup() {
Serial.begin(115200);
nodemcu.begin(115200);
//Serial.println("Program started");
}
Sending Data From Arduino To NodeMCU
void loop() {
StaticJsonDocument<1000> doc;
int reading = analogRead(AsensorPin);
delay(1000);
}
Errors You may face
StaticJsonBuffer is a class from ArduinoJson 5. Please see
https://arduinojson.org/upgrade to learn how to upgrade your program
to ArduinoJson version 6
/* 4. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "[email protected]"
#define USER_PASSWORD "arduino123"
Code Explanation
NodeMCU code
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
Serial.begin(115200); // Select the same baud rate if you want to see the datas on
Serial Monitor
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
NodeMCU code
void setup()
{
………………………….
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
if (error)
{
return;
}
NodeMCU code
else{
Serial.println("JSON Object Recieved");
Serial.print ("Recieved Temperature: ");
float data1 = data["temperature"];
String temp = String(data1);
Serial.println(temp);
NodeMCU code
//SENDING THE RECEIVED DATA TO FIREBASE
if (Firebase.ready())
{
sendDataPrevMillis = millis();
int iVal = 0;
Serial.printf("Set float... %s\n", Firebase.setFloat(fbdo, F("/test/float"),
count + 10.2) ? "ok" : fbdo.errorReason().c_str());
FirebaseJson json;
if (count == 0)
{
json.set("value/round/" + String(count), F("cool!"));
json.set(F("vaue/ts/.sv"), F("timestamp"));
Serial.printf("Set json... %s\n", Firebase.set(fbdo, F("/test/json"), json) ?
"ok" : fbdo.errorReason().c_str());
}
NodeMCU code
else
{
json.add(String(count), "smart!");
Serial.printf("Update node... %s\n", Firebase.updateNode(fbdo,
F("/test/json/value/round"), json) ? "ok" : fbdo.errorReason().c_str());
}
Serial.println();
count++;
}
else {
Serial.println("Error in writing data to firebase"); } } }
Code Uploading on NodeMCU
Plug in NodeMCU Cable
• Tools > Boards > Generic ESP8266 Module
• Select Port
• Upload the code, make sure Arduino is not connected to any port
while uploading your code to nodeMCU
Final Look of the Real time Database