• Home
  • IOT
  • Articles
  • IoT Project Google Firebase controlling LED using Android App

IoT Project Google Firebase controlling LED using Android App

Last updated on May 30 2022
Kritika Singh

Table of Contents

IoT Project Google Firebase controlling LED using Android App

In this blog, we’ll control the LED connected with NodeMCU using Firebase database and an Android app . within 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 whenever isn’t 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.

iot 50
iot

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.
Now, write an Android code to interact with Google Firebase database and update the LED status:
Open Android Studio and make an Empty project.
First of all, we’d like to attach our Android app with Firebase project. For doing this click Tools > Firebase >

iot 51
iot

Click Realtime Database > Save and retrieve data.

iot 52
iot

Click on the choice “1 Connect your app to Firebase” and choose your project created over Firebase.

iot 53
iot
iot 54
iot

After selecting project, click “Connect to Firebase”, and add “Realtime Database to your app”
activity_main.xml
In the layout file we take two buttons to send serial data to vary LED status 1(ON), and 0 (OFF)
1. <?xml version=”1.0″ encoding=”utf-8″?>
2.
8.
9.
10. <Button
11. android:id=”@+id/button_on”
12. android:layout_width=”wrap_content”
13. android:layout_height=”wrap_content”
14. android:layout_marginBottom=”8dp”
15. android:layout_marginEnd=”8dp”
16. android:layout_marginStart=”8dp”
17. android:layout_marginTop=”8dp”
18. android:text=”ON”
19. app:layout_constraintBottom_toBottomOf=”parent”
20. app:layout_constraintEnd_toStartOf=”@+id/button_off”
21. app:layout_constraintStart_toStartOf=”parent”
22. app:layout_constraintTop_toTopOf=”parent” />
23.
24. <Button
25. android:id=”@+id/button_off”
26. android:layout_width=”wrap_content”
27. android:layout_height=”wrap_content”
28. android:layout_marginBottom=”8dp”
29. android:layout_marginEnd=”76dp”
30. android:layout_marginRight=”76dp”
31. android:layout_marginTop=”8dp”
32. android:text=”OFF”
33. app:layout_constraintBottom_toBottomOf=”parent”
34. app:layout_constraintEnd_toEndOf=”parent”
35. app:layout_constraintTop_toTopOf=”parent” />
36.
37.
50.
51.
MainActivity.java
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.
1. package example.tecklearn.com.controlledwithnodemcuusingandroidapp;
2.
3. import android.support.v7.app.AppCompatActivity;
4. import android.os.Bundle;
5. import android.view.View;
6. import android.widget.Button;
7. import com.google.firebase.database.DatabaseReference;
8. import com.google.firebase.database.FirebaseDatabase;
9.
10. public class MainActivity extends AppCompatActivity {
11. Button on;
12. Button off;
13. @Override
14. protected void onCreate(Bundle savedInstanceState) {
15. super.onCreate(savedInstanceState);
16. setContentView(R.layout.activity_main);
17. on = findViewById(R.id.button_on);
18. off = findViewById(R.id.button_off);
19. on.set FirebaseDatabase.getInstance();
24. DatabaseReference myRef = database.getReference(“LED_STATUS”);//LED_STATUS is Firebase database LED_STATUS
25. myRef.setValue(1);
26. }
27. });
28. off.set FirebaseDatabase.getInstance();
32. DatabaseReference myRef = database.getReference(“LED_STATUS”);//LED_STATUS is Firebase database LED_STATUS
33. myRef.setValue(0);
34. }
35. });
36. }
37. }
Add the web permission in AndroidManifest.xml file
1.
Update the principles of Firebase database read, write status from false to true.
Note: making rules property true set it to the general public which may be accessed from anyone. So, for security reason doesn’t set to true or learn more about security rules.

iot 55
iot

Run your project and control LED connected with NodeMCU ESP8266.
Output:

iot 56
iot
iot 57
iot

So, this brings us to the end of blog. This Tecklearn ‘IoT Project Google Firebase controlling LED using Android App’ 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:

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 controlling LED using Android App"

Leave a Message

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