IoT Project Google Firebase controlling LED using Android App
In this section, we will control the LED connected with NodeMCU using Firebase database and an Android app . In the previous section Google Firebase controlling LED connected with NodeMCU ESP8266 of this project we are controlling LED by manually editing the status of LED in Firebase data. Changing the LED status every time is not possible, time taking and not logical.
To overcome with the above problem, we build an Android app that interacts with Firebase database and updates the LED status which turns ON/OFF the LED.
Working principle of the project (Android app, Google Firebase, and Node MCU)
In this project, there are three main components are used an Android app, Firebase database and, 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 basis of data received from Firebase Database. If NodeMCU receives serial data 1, it turns ON the LED, and if NodeMCU receives serial input 0 then it turns OFF the LED.
Now, write an Android code to interact with Google Firebase database and update the LED status:
Open Android Studio and create an Empty project.
First of all, we need to connect our Android app with Firebase project. For doing this click Tools > Firebase >
Click Realtime Database > Save and retrieve data.
Click on the option "1 Connect your app to Firebase" and select your project created over Firebase.
After selecting project, click "Connect to Firebase", and add "Realtime Database to your app"
In the layout file we take two buttons to send serial data to change LED status 1(ON), and 0 (OFF)
In MainActivity.java file, we created two buttons one for "on" another for "off". Clicking the "on" button, it updates the Firebase database LED_STATUS to "1", and clicking the "off" button it update the Firebase database LED_STATUS to "0".
Add the fourth option code "Write to your database" in button click listener.
Add the Internet permission in AndroidManifest.xml file
Update the Rules of Firebase database read, write status from false to true.
Note: making rules property true set it to the public which can be accessed from anyone. So, for security reason doesn't set to true or learn more about security rules.
Run your project and control LED connected with NodeMCU ESP8266.