JANAK13
Published © GPL3+

Real-Time Data Access Using Arduino and Firebase

A good project for leaning and implementing serial communication, real-time data access, and using Firebase.

IntermediateShowcase (no instructions)14,009
Real-Time Data Access Using Arduino and Firebase

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Firebase
Google Firebase

Story

Read more

Schematics

circuit

This one is just for reference. It will be updated soon.

Code

serial communication

C/C++
*To be uploaded on the arduino uno*
This is the code for serial communication between arduino uno and nodeMCU (esp8266).
#include <SoftwareSerial.h>
SoftwareSerial ArduinoUno(3,2);
int n;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  ArduinoUno.begin(4800);
  
pinMode (3,INPUT);
pinMode (2,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  n=analogRead(A2);
   ArduinoUno.print(n);
  ArduinoUno.println("\n");
  Serial.println(n);
  delay(300);
}

Uploading data to firebase

C/C++
*to be uploaded on the nodeMCU*
This code uploads the data received by the nodeMCU on to firebase.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <SoftwareSerial.h>

// Set these to run example.
#define FIREBASE_HOST "***********************************"
#define FIREBASE_AUTH "***********************************"
#define WIFI_SSID "WiFi ssid"
#define WIFI_PASSWORD "PASSWORD"
SoftwareSerial esp(D2,D3);

void setup() {
  Serial.begin(9600);
  esp.begin(4800);

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;
float val;

void loop() {

   while(esp.available()>0)
  {
     float val = esp.parseFloat();
     if(esp.read()=='\n')
     {
       Serial.println(val);
       
     }

  // set value
  Firebase.setFloat("number", val);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(100);
  


  // get value 
  Serial.print("number: ");
  Serial.println(Firebase.getFloat("number"));
  delay(100);


  // append a new value to /logs
  String name = Firebase.pushInt("logs", n++);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /logs/");
  Serial.println(name);
  delay(100);
  }
}

Credits

JANAK13

JANAK13

6 projects • 44 followers

Comments