Home Automation Using NodeMCU ESP32 and Firebase | MIT App Inventor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends this is a home automation project to control the multiple rooms of your home you can use the manual switches to control the home appliances and the real-time status of the relays will also be updated on the android app you can also use the android app to control the load connected to each relay you can control up to 4 rooms using this app to control the room number 2 you just tap on room 2 button now you can control the home appliances of room number 2 using android app and you can also use the manual switches to control the load connected to the relays also check the real time status update in the android app next if you reset the microcontroller or if there is a power failure and when the microcontroller power up again the latest status of the relays will be updated automatically next i have used esp8266 for room number one and esp32 for room number two and these both devices are connected to the firebase real-time database you can use two more esp devices for room number three and room number four you can connect up to 200 000 devices to the firebase at the same time the interesting thing of this project is you can upload same sketch on esp32 and esp8266 without making any change in the code so you can use any device you have in this project i have used firebase database for this project so you can control your home appliances from anywhere in the world this project consumes very little amount of firebase data so the free quota of firebase data usage will never exceeded so you don't have to worry about hitting the quota limit of firebase database for this project first we need to set up a firebase project so go to firebase and sign in using your google account here click on get started and then add project to create a new project then give a name to your project you can give any name to your project and then click on continue again click the continue button next select the default account for firebase and then click on create project button the project is ready just click on continue here first we will create a real-time database so click on real-time database then click on create database here select the location for your database server you must select a location that is near to your country then click on next then select start in test mode after that click on enable button now the database is ready next we have to set the read and write permissions to do so go to the rules tab here change the permissions to true our project will use these permissions to access the firebase database then click on publish button to publish the rules next you need to set authentication method for your project so from the left panel click on authentication the authentication is required because it allows our project to securely save the data in the firebase cloud database here click on get started here you can see there are several authentication methods like email and password google account facebook account and others for testing purpose you can select the anonymous user this method does not require any username and password for authentication enable this option and then click on save button next you will need to get the project api key so from the left panel click on project settings here you can see the web api key just copy it and save it in some text editor software like notepad this web api key will be used later in the code and also used in the android app next you will need to get the firebase host url so from the left panel click on real time database here you can see the firebase host url just copy it by clicking on this button then again go to the notepad and paste the url here we will use this data later next you can download the code from my github account i have put the download link in the description of the video here is the downloaded folder you can see arduino sketch file wiring diagram and big automation dot aia file this file will be used to make the android app next we will create an android app using mit app inventor you can log in into app inventor using your gmail account now first we will import the aia file that we have already downloaded so click on project and then click on import project from my computer then click on choose file now browse to the code folder that we have downloaded before here open the bigautomation.aia file and then click on ok now the project is imported here you can see the project big automation just open it here i have create four screens screen one is used to control the room number one similarly screen two for room 2 screen 3 for room 3 and so on you can also add more screens as per your requirements each screen is connected to the buttons below you can use these buttons to control the load for each room separately next we will enter the firebase credentials in this project we have already saved them in the notepad here first copy the web api key and then go to the app inventor here select firebase db1 and then paste the api key in the firebase token field next go back to the notepad and copy the firebase host url then go back and paste the url here in the firebase url field make sure you must delete all the data from the project bucket field now the screen 1 is ready you must repeat the same process for the other screens like room 2 room 3 and room 4. make sure you must have entered the firebase host url and web api key in all the screens you must entered the same data in all the screens that we have entered in screen 1. otherwise the app will not work as you can see i have made all the required changes so now the project is ready let's have a look at code blocks here are the code blocks the same code blocks are used in all the screen the code is very simple and straightforward if you feel any issue then tell me in the comments next we will create the android apk file so click on build and then select android app.apk file soon the project building process will start now the apk file is ready click on download button to download the file on your computer now we have android app apk file and we will install it in the phone so just move this file to your android phone and then install it after installing the app it looks something like this now we will test this app so select the room one and press the light one button now observe the firebase database here you can see the data as updated for light one of room number one similarly you can test the other buttons to see if they are working or not next select the room number 2 and then test all the buttons here before going forward make sure all the buttons are must working properly next let's have a look at the wiring diagram here i have connected the four push buttons to d5 d6 sd2 and sd3 pins of node mcu board the relay module is connected to the pin d0 d1 d2 and pin d3 of node mcu microcontroller i have power up the whole project using 5 volts wall watt power supply i have connected the vcc pin of power supply to v in pin of node mcu board and to the vcc pin of relay module next here i have already connected all the components as per wiring diagram now the first device is ready and we will use it for room number one similarly prepare three more node mcus for room two room three and room number 4. next if you want to use esp32 microcontroller then you must follow this wiring diagram here i have connected the 8 channel relay module to esp32 because i don't have another 4 channel relay module you might use 4 channel relay module with esp32 now the hardware setup is complete next let's move to the coding part of the project from the code folder open this file mit multi-room firebase.ino file here first you need to install the board packages for esp32 and esp8266 by using these links in the preferences i have installed the latest version both for esp32 and esp8266 devices for esp8266 i have installed the version 3.0.2 and for esp32 i have installed the version 1.0.6 next you also need to install esp firebase client library this library is required to work with the firebase real-time database you can install it from the library manager here is the library firebase arduino client library i have installed the version 3.1.5 next below you need to enter your wi-fi router's ssid and password next here you need to enter the firebase web api key we have already store it in the notepad so just copy the web api key then go back and paste the web api key here next enter the firebase host url here so just copy it from the notepad then go back and paste the firebase url here make sure just remove the trailing slash from the end also delete the https part from the beginning of the url next below here you need to add the room number for your esp device i am configuring this code for room number one so i will not change this value now the code is ready just select your esp8266 board from the tools menu my board is node mcu 1.0 and here you can see the configurations of my board now just hit upload button to upload the code after uploading the code open serial monitor here first the project will connect to the wi-fi router and then it will sign up for the firebase database as an anonymous user and then project will fetch the latest data from the room 1 bucket of the firebase database and then it updates the relay states according to the incoming data if i press the push button then the relay will turn on and the relay status will be updated in the firebase database similarly you can test other buttons as well next for room number 2 we will upload the same code on esp32 as well so just change room number and set it to room 2. next you will have to define the pins for your esp32 board as per wiring diagram i have already stored the pin definitions in this modifysketch.txt file so just copy the pin definitions for esp32 then go back to sketch file and paste the pin definitions here now the sketch is ready next select your esp32 device from the tools menu i will select the board as esp32 development module next select the com port for uesp32 board now just click on upload button to upload the code this way you can prepare two more devices for room number three and four the final setup of my project is look something like this and you can control anything by using manual switches as well as using the android app that's all this is for today if you have any question then comment me in the comment box below see you in another video bye
Info
Channel: Ahmad Logs
Views: 13,032
Rating: undefined out of 5
Keywords: home automation using nodemcu and firebase, google firebase esp8266 home automation, nodemcu firebase mit app inventor, nodemcu firebase tutorial, iot home automation, esp32, esp8266, iot home automation esp32, iot home automation esp8266
Id: tOKTNex2wwA
Channel Id: undefined
Length: 14min 30sec (870 seconds)
Published: Mon Apr 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.