0% found this document useful (0 votes)
19 views9 pages

Google Firebase-Controlling LED Using Android App: Saaqib Shaikh 9502

Uploaded by

crce.9502.ecs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Google Firebase-Controlling LED Using Android App: Saaqib Shaikh 9502

Uploaded by

crce.9502.ecs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Fr.

CONCEICAO RODRIGUES COLLEGE OF ENGINEERING


( FrCRCE)
Department of Electronics and Computer Science (ECS)

6. Google firebase-Controlling LED using Android app

Marking scheme (Rubrics)


Name- Saaqib Shaikh Roll no- 9502

Timeline (3) Depth of Completeness Total Signature


Understanding (4) (3)

Course, Subject & Experiment Details

Academic year 2024 – 2025 Estimated Time 02 Hours


Course B.E. (ECS) Subject Name Internet of Things
Semester VII Chapter Title Google firebase
Experiment Type Coding Subject Code ECL 702

Aim & Objective of Experiment

To control a LED using Google Firebase & ESP8266

Theory:

Using the IoT hardware & cloud platform, we can control the IoT devices including LEDs

from any part of the world. This program deals with LED Control using Google Firebase

Console & NodeMCU ESP8266 wifi Module. There are various methods of controlling of the

LED such as using Web Server or Webpage, Blynk Application and using other API based

services. But here we will only focus on Google Firebase


Google Firebase is a Google-backed application development software used for creating,

managing,and modifying data generated from any android/IOS application, web services, IoT

sensors & Hardware. FirebaseArduino is a library to simplify connecting to the Firebase database

from Arduino clients. It is a full abstraction of Firebase’s REST API exposed through C++ calls

in a wiring friendly way. All JSON parsing is handled by the library and you may deal in pure

C/Arduino types.The library cannot work standalone. So you need to add the ArduinoJSON

library as well.

To Control the LED using Google Firebase & Nodemcu ESP8266, you need to setup the
Google Firebase first.
Code:
#include <ESP8266WiFi.h>
#include <Firebase_ESP_Client.h>

/* 1. Define the WiFi credentials */


#define WIFI_SSID "Hotspot-Shady"
#define WIFI_PASSWORD "shady1347 "

/* 2. Define the API Key */


#define API_KEY "AIzaSyBU8Uc3_-JDYgVuu1tFQKWTxI-TYQ2MVIU"

/* 3. Define the RTDB URL */


#define DATABASE_URL "https://wardobepal-default-rtdb.firebaseio.com/"

/* 4. Define the user Email and password that already registered or added in your project */
#define USER_EMAIL "[email protected]"
#define USER_PASSWORD "iotexp"

// Define Firebase Data object


FirebaseData fbdo;

FirebaseAuth auth;
FirebaseConfig config;

unsigned long sendDataPrevMillis = 0;

const int ledPin = 18; // Ensure the pin number is valid for ESP8266

void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);

Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

/* Assign the API key (required) */


config.api_key = API_KEY;

/* Assign the user sign-in credentials */


auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;

/* Assign the RTDB URL (required) */


config.database_url = DATABASE_URL;

// Comment or pass false value when WiFi reconnection will control by your code or third-party
library e.g. WiFiManager
Firebase.reconnectWiFi(true);

// Since v4.4.x, BearSSL engine was used, the SSL buffer needs to be set.
// Large data transmission may require larger RX buffer; otherwise, connection issues or data
read timeouts can occur.
fbdo.setBSSLBufferSize(4096 /* Rx buffer size in bytes from 512 - 16384 */, 1024 /* Tx buffer
size in bytes from 512 - 16384 */);

// Limit the size of response payload to be collected in FirebaseData


fbdo.setResponseSize(2048);

Firebase.begin(&config, &auth);

Firebase.setDoubleDigits(5);

config.timeout.serverResponse = 10 * 1000;
}
void loop()
{
// Firebase.ready() should be called repeatedly to handle authentication tasks.
if (Firebase.ready() && (millis() - sendDataPrevMillis > 1000 || sendDataPrevMillis == 0))
{
sendDataPrevMillis = millis();

int ledState;
if (Firebase.RTDB.getInt(&fbdo, "/led/state", &ledState))
{
digitalWrite(ledPin, ledState);
}
else
{
Serial.println(fbdo.errorReason().c_str());
}
}
}

Arduino Screenshot:
Firebase Screenshot:
Post-Lab Questions:

1. Explain the changes required to connect sensor data using Google firebase.
2. Explain the Firebase functions used to connect Nodemcu to Firebase.

You might also like