0% found this document useful (0 votes)
49 views

Firebase 1

This document summarizes a lab that demonstrated using Firebase to control an IoT device. An M5StickC was configured to continuously check the Firebase database for an LED_STATUS variable and turn a local LED on or off based on its value. The code included initializing WiFi and Firebase connections in setup() and an infinite loop to retrieve the status from Firebase and control the LED accordingly. This allowed the LED to be controlled remotely by changing the database value.

Uploaded by

api-607160872
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)
49 views

Firebase 1

This document summarizes a lab that demonstrated using Firebase to control an IoT device. An M5StickC was configured to continuously check the Firebase database for an LED_STATUS variable and turn a local LED on or off based on its value. The code included initializing WiFi and Firebase connections in setup() and an infinite loop to retrieve the status from Firebase and control the LED accordingly. This allowed the LED to be controlled remotely by changing the database value.

Uploaded by

api-607160872
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/ 3

Using Google Firebase to develop an IoT application

Jose Solorio
CSC230
Professor Prater
April 25, 2022

Introduction:

This lab was conducted to demonstrate functionality of firebase.


Firebase is a robust cloud based platform much like ThingSpeak. It
allows us to track various statistics from our IoT device but remains
highly customizable. We configured our M5StickC to talk to Firebase
via an API call in which the loop would continuously check for an
LED_STATUS variable. Conditionals were set to turn the local LED on
or off depending on the LED_STATUS string.
Implementation:
➔ Bill of Materials
◆ M5StickC
◆ USB A to C cord
◆ Computer with common OS eg: Windows, Linux, MacOS
➔ Video: https://youtu.be/-PNgteDwKRs

➔ Code

#include <IOXhop_FirebaseESP32.h>
#include <IOXhop_FirebaseStream.h>
#include <ArduinoJson.h>
#include <M5StickCPlus.h>

#include <WiFi.h>
#include "secrets.h"
String fireStatus;
#define LED_BUILTIN 10

void setup(){
M5.begin();
Serial.begin(9600);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
//initiates WiFi connection
WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
//loop to show WiFI conneciton is being attempted or hanging up
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
//initiates Firebase connection
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
//sets initial status to OFF
Firebase.setString("LED_STATUS", "OFF");
}

void loop(){
//infinite loop that send http request to retrieve status of LED
fireStatus = Firebase.getString("LED_STATUS");
if(fireStatus == "OFF"){

//Status is being written to LCD console


Serial.println("LED Turned Off");
//Writes status to pin which lowers or heightens resistance in
this case hightening to turn LED off
digitalWrite(LED_BUILTIN, HIGH);

}else if (fireStatus == "ON"){


//writing console output to LCD
Serial.println("Led Turned On");
//Writes status to pin which lowers or heightens resistance in
this case lowering to allow LED to turn on
digitalWrite(LED_BUILTIN, LOW);
}else {
Serial.println("Wrong Credential! Please send ON/OFF");
}

}
➔ Structure of program:Sample code was provided in class. Program
operates in typical sketch format. Setup which sets up initial
status values. Second part is an infinite loop in which
firebase is checked to see if a DB value has changed..
➔ Calculations: No calculations were used/required in this lab.

You might also like