Controlling RGB LED from Android Application and ESP8266 WiFi Module in real-time
A step-by-step guide to creating your first IoT project for beginners
A little back story
When I first saw IoT based Android Application that can control all the home appliances with a simple touch from the app, I was awestruck. So I researched about it and found it’s much simpler than it looks. You can follow this article and create this app without prior knowledge of android programming or ESP8266 WiFi Module. To proceed any further let’s keep all hardware & software handy.
Hardware Requirements:
- Android mobile
- ESP8266 WiFi Module
- Breadboard
- Jumper wire (M/M)
- USB 2.0 cable
- Common Cathode LED
Software Requirements:
How this will work
First I will show you how to set up the Firebase Realtime Database and connect with our ESP8266 WiFi Module code. Then we develop a simple Android application and will connect with Firebase Realtime Database.
Selecting any color from ColorPickerView in the application will change the value in the database and trigger the color change in RGB LED.
Let’s set up the Firebase Realtime Database.
Firebase Realtime Database
- Why Firebase Realtime Database?
Firebase allows us to easily set up listeners that can trigger client code when any data is modified and giving end-users real-time updates.
2. Setting up Firebase Realtime Database
It’s a very simple process to set up Firebase Realtime Database. You can follow this youtube video.
Configuring the Hardware
The most difficult part when working with IoT projects is wiring & setup. In order to work as a complete product, hardware(ESP8266 WiFi Module) & software(Android app) need to work as a single unit. In order to achieve that, let’s install the Arduino IDE first.
- Arduino IDE installation
Arduino IDE is available for all 3 major OSs. You can download from here and install.
2. Add Firebase Arduino library to your project
In order to communicate your Arduino code to the Firebase Realtime Database, you need to install one library.
Open Arduino IDE, go to menu Sketch -> Include Library -> Manage Libraries…
In the Library Manager Window, search for “Firebase” and then select “Firebase ESP8266 Client” and click the “Install” button.
3. Setting up Firebase Realtime Database
4. Circuit Design
Developing Android Application
Open your Android Studio and Click on Create New Project, In the Project Template Window, Select Empty Activity and click on Next. Enter Application Name and click Finish.
- Adding internet permission
Open AndroidManifest.xml and internet permission
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
...>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
2. Adding the dependency
Add the below library in your project build.gradle file
dependencies {
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation "com.github.skydoves:colorpickerview:2.1.5"
}
Add the below library in your module build.gradle file
dependencies {
classpath 'com.google.gms:google-services:4.0.1'
}
3. Android Layout file
Here I used a library to pick a color. I have used the ColorPickerView library, it’s much simpler to implement and extract the RGB color code with very little effort.
4. Activity File
Here we initialize the Firebase Realtime Database, pick the color code from the ColorPickerView library, and send it to Realtime Database.
Screenshots & Images
Android Application Screenshots
Complete application in action