IoT Project: Google Firebase using NodeMCU ESP8266

Last updated on May 30 2022
Sankalp Agarwal

Table of Contents

IoT Project: Google Firebase using NodeMCU ESP8266

In this IoT (Internet of Things) project, we’ll connect Arduino NodeMCU device with Google Firebase database and by using Android application, we shall send data to Firebase to regulate LED.

Google Firebase database may be a real-time, high speed and free database provided by Google.

Hardware Requirements

  1. Wi-Fi Node MCU ESP8266
  2. Standard USB cable to attach Node MCU
  3. Jumper wires female to female
  4. LED
  5. Bulb holder
  6. Wire
  7. AC 220v/120v home appliances or 9v Hi-Walt Battery

Software requirements

  1. Arduino software
  2. Android Studio

Working principle of the project (Android app, Google Firebase, and Node MCU)

In this project, there are three main components which use an Android app, Firebase database, and Wi-Fi Node MCU.

image001 6
Wi-Fi Node MCU

The Android app sends the serial data 1 or 0 to the Firebase database. The Firebase database interacts with Wi-Fi NodeMCU and this NodeMCU acts on the idea of knowledge received from Firebase Database. If NodeMCU receives serial data 1, it activates the LED, and if NodeMCU receives serial input 0 then it turns OFF the LED.

This project is assessed into three different steps:

  1. Connecting Arduino Node-MCU with Google Firebase
  2. Control Led Using Firebase Console
  3. Control Led with Android App using Firebase database

Connecting Arduino Node-MCU with Google Firebase

Download the Firebase Arduino library from https://github.com/FirebaseExtended/firebase-arduino

image003 5
Download

Add the Firebase Arduino library to Arduino IDE, click Sketch -> Include Library -> Add .ZIP Library…. and choose downloaded library.

image005 3
Add

If Firebase Arduino library is successfully added, it shows in Include Library.

Now, Login the Google Firebase using your Google account. Create a Firebase project by clicking Add project.

image006 3
Login

Provide a project name and make project.

image007 1
project name

Click, Project Overview setting where you’ll find your project’s detail. Now, click on Service accounts choice to view database secrets.

A program on Arduino IDE to attach NodeMCU and Google Firebase

Click, File > Examples > FirebaseArduino > FirebaseDemo_ESP8266

Click on Project Overview > Project Settings > Service Account > Database secrets to look at firebase auth secrets, add this secret to your Arduino program’s FIREBASE_AUTH.

Go to database section at left-menu and look for Realtime Database, where you discover the Firebase host URL. Copy this URL without “https://” and “/” the at end and paste it at FIREBASE_HOST within the program.

Add Realtime database in your project, click Project Overview setting > Realtime Database.

image008 2
Add Realtime database

Add your WIFI name and password in WIFI_SSID and WIFI_PASSWORD respectively.

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. //
  8. // Copyright 2015 Google Inc.
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the “License”);
  11. // you’ll not use this file except in compliance with the License.
  12. // you’ll obtain a replica of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an “AS IS” BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the precise language governing permissions and
  20. // limitations under the License.
  21. //
  22. // FirebaseDemo_ESP8266 may be a sample that demo the various functions
  23. // of the FirebaseArduino API.
  24. #include
  25. #include
  26. // Set these to run example.
  27. #define FIREBASE_HOST “nodemcu-demo-697d8.firebaseio.com”
  28. #define FIREBASE_AUTH “YOUR_FIREBASE_AUTH”
  29. #define WIFI_SSID “NETGEAR64”
  30. #define WIFI_PASSWORD “*TECKLEARN#”
  31. void setup() {
  32. Serial.begin(9600);
  33. // hook up with wifi.
  34. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  35. Serial.print(“connecting”);
  36. while (WiFi.status() != WL_CONNECTED) {
  37. Serial.print(“.”);
  38. delay(500);
  39. }
  40. Serial.println();
  41. Serial.print(“connected: “);
  42. Serial.println(WiFi.localIP());
  43. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  44. }
  45. int n = 0;
  46. void loop() {
  47. // set value
  48. Firebase.setFloat(“number”, 42.0);
  49. // handle error
  50. if (Firebase.failed()) {
  51. Serial.print(“setting /number failed:”);
  52. Serial.println(Firebase.error());
  53. return;
  54. }
  55. delay(1000);
  56. // update value
  57. Firebase.setFloat(“number”, 43.0);
  58. // handle error
  59. if (Firebase.failed()) {
  60. Serial.print(“setting /number failed:”);
  61. Serial.println(Firebase.error());
  62. return;
  63. }
  64. delay(1000);
  65. // get value
  66. Serial.print(“number: “);
  67. Serial.println(Firebase.getFloat(“number”));
  68. delay(1000);
  69. // remove value
  70. Firebase.remove(“number”);
  71. delay(1000);
  72. // set string value
  73. Firebase.setString(“message”, “hello world”);
  74. // handle error
  75. if (Firebase.failed()) {
  76. Serial.print(“setting /message failed:”);
  77. Serial.println(Firebase.error());
  78. return;
  79. }
  80. delay(1000);
  81. // set bool value
  82. Firebase.setBool(“truth”, false);
  83. // handle error
  84. if (Firebase.failed()) {
  85. Serial.print(“setting /truth failed:”);
  86. Serial.println(Firebase.error());
  87. return;
  88. }
  89. delay(1000);
  90. // append a replacement value to /logs
  91. String name = Firebase.pushInt(“logs”, n++);
  92. // handle error
  93. if (Firebase.failed()) {
  94. Serial.print(“pushing /logs failed:”);
  95. Serial.println(Firebase.error());
  96. return;
  97. }
  98. Serial.print(“pushed: /logs/”);
  99. Serial.println(name);
  100. delay(1000);
  101. }

Connect your NodeMCU ESP8266 together with your pc via standard USB cable and upload code in it. While uploading the code into NodeMCU, the device continuously blinks.

Now open the serial monitor form Tools, you’ll find data are uploaded to Firebase database.

Note: If you bought setting /number failed: message in serial monitor then updates the fingerprint: attend C:/Users/{username}/My Documents/Arduino/libraries/firebase-arduino-master/src open FirebaseHttpClient.h file, and update the fingerprint with => 6F D0 9A 52 C0 E9 E4 CD A0 D3 02 A4 B7 A1 92 38 2D CA 2F 26

Output:

image010 1
Output
image011 2
Outputd

Google Firebase database is one among the fastest, real-time and free databases for IoT.

So, this brings us to the end of blog. This Tecklearn ‘IoT project – Google Firebase using NodeMCU ESP8266’ blog helps you with commonly asked questions if you are looking out for a job in Internet of Things (IoT). If you wish to learn IoT and build a career in Internet of Things (IoT) domain, then check out our interactive, Internet of Things (IoT) Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/iot-internet-of-things-training/

Internet of Things (IoT) Training

About the Course

Internet of Things or IoT, as it is widely known, simply put, is a network of devices which can communicate with each other with regards to sending, receiving and analyzing data. Tecklearn’s IoT Training as an online training platform delivers you the best in the industry IoT knowledge by certified and experienced trainers to master IoT. Interactive sessions include two real-time projects to provide in-depth understanding of advanced IoT concepts that covers IoT methods and technologies, application deployment, network and communication protocols and integrations, security measures and real-time data management on the internet. You will learn IoT introduction, significance, building your own IoT devices, sensors, IoT communication and security. This training will help you be a part of the IoT revolution underway around the globe.

Why Should you take IoT (Internet of Things) Training?

  • The average salary for an IoT Engineer is $163,514 per year in the United States. (Indeed.com)
  • Many industries such as Eddie Stobart Transport and Logistics Company, the Amazon, Dell, Aviva, German Auto Manufacturer Daimler, the John Deere Company and Walt Disney Land are all utilizing the Internet of Things technology to monitor various activities and advance their existing systems.
  • Gartner Says 5.8 Billion Enterprise and Automotive IoT Endpoints Will Be in Use in 2020

What you will Learn in this Course?

Introduction to Internet of Things

  • What is IoT, how does it work
  • IoT vs IIoT
  • Business Cases of IIoT
  • Industry 4.0
  • Properties of IoT device
  • IoT Ecosystem
  • IoT Decision Framework
  • IoT Solution Architecture Models
  • How IoT is Transforming Businesses
  • Major IoT Boards in Market

IoT Communication Protocols

  • Types of wireless communication
  • Major wireless Short-range communication devices and properties
  • Comparison of these devices (Bluetooth, WIFI, ZigBee, 6LoWPAN)
  • Major wireless Long-range communication devices and properties, Comparison of these devices (Cellular IoT, LPWAN)

IoT Architecture

  • The IoT Stack Architecture and the various components and layers
  • The app, the data processing and platform
  • IoT OS like Contiki, FreeRTOS and mbe
  • The edge and the connected thing or device

IoT Sensors and Device Platforms

  • Introduction to IoT Sensors and the role they play in getting the IoT systems work efficiently
  • Micro-electromechanical systems revolutionizing IoT sensors
  • Use Case of Water Quality Monitoring
  • Use Case: Sericulture
  • Difference between microcontroller and microprocessor
  • IoT Device Platforms – Arduino, Raspberry Pi etc
  • Smartphone Centric Architecture
  • IoT Application Layer protocols
  • Hands On

Arduino Platform and Arduino Interfacing

  • Arduino physical board, libraries and the Integrated Development Environment
  • Arduino Shields various operations such as heat and light sensing, GPS, UI display
  • Programming Arduino using C language
  • Controlling external devices using pins on the Arduino board
  • The Arduino Interface
  • Reading inputs from various sources and providing an output
  • Working with sensors for sensing and controlling the physical world
  • Deploying various types of sensors and connecting it to the Arduino
  • Constant conversion between analog and digital signals for information exchange between the physical and digital domains
  • Hands On

Raspberry Pi Platform and Raspberry Pi Interfacing

  • Introduction to Raspberry Pi
  • Set up of Raspberry Pi environment
  • Coding for the Raspberry Pi using Python
  • Deploying Python-based Integrated Development Environment
  • Interfacing the Raspberry Pi with the physical world
  • Introducing the various input and output devices
  • Raspberry Pi expansion boards for building complex hardware setup
  • Real-time demo of Raspberry Pi interfacing
  • Hands On

Arduino Uno Wifi and IoTivity

  • Iotivity
  • Iotivity Architecture
  • Hands On

Netduino Platform and Netduino Interfacing

  • Introduction to Netduino Platform
  • Setting up the Netduino environment
  • Coding for the Netduino
  • Interfacing the Netduino with the physical world
  • Introducing the various input and output devices
  • Real-time demo of Netduino interfacing
  • Hands On

IoT for Arduino, NodeMCU and Netduino

  • Control LED light using Netduino board
  • NodeMCU
  • Blynk

Project: Building WSN with MQTT, Raspberry Pi & Arduino

Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "IoT Project: Google Firebase using NodeMCU ESP8266"

Leave a Message

Your email address will not be published. Required fields are marked *