Press ESC to close

14 12

IOT with Firebase : Control Led with Android App #Part3

IOT with Firebase

I continue teaching IOT with Firebase through problem solving. In this video I’ll show step by step guide to create Android App. It will be using Android studio for controlling LED which is connected to Arduino NodeMCU.

I think learning through doing is the best. The problems will keep getting more complex. The code follows the video below to help.

If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials

 
Transcript / Cheat Sheet
Firstly, set the internet permission for our app for which need to add this code after tag.
Manifest.xml



<manifest xmlns:android=http://schemas.android.com/apk/res/android
package=com.example.root.led_control >
<uses-permission android:name=android.permission.INTERNET />
<application
android:allowBackup=true
android:icon=@mipmap/ic_launcher
android:label=@string/app_name
android:roundIcon=@mipmap/ic_launcher_round
android:supportsRtl=true
android:theme=@style/AppTheme >
<activity android:name=.MainActivity >
<intent-filter>
<action android:name=android.intent.action.MAIN />
<category android:name=android.intent.category.LAUNCHER />
</intent-filter>
</activity>
</application>
</manifest>
After setting the permission, we need to create layout for our application. So let’s check out XML code.

activity_main.xml

<RelativeLayout
xmlns:android=http://schemas.android.com/apk/res/android
xmlns:tools=http://schemas.android.com/tools
xmlns:app=http://schemas.android.com/apk/res-auto
android:layout_width=match_parent
android:layout_height=match_parent
tools:context=com.example.root.led_control.MainActivity>
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:layout_alignParentTop=true
android:layout_centerHorizontal=true
android:layout_marginTop=41dp
android:text=IOT CONTROL LED
android:textSize=30sp
app:layout_constraintBottom_toBottomOf=parent
app:layout_constraintLeft_toLeftOf=parent
app:layout_constraintRight_toRightOf=parent
app:layout_constraintTop_toTopOf=parent
android:id=@+id/textView />
<Button
android:id=@+id/on
android:layout_width=wrap_content
android:layout_height=wrap_content
android:layout_alignParentLeft=true
android:layout_alignParentStart=true
android:layout_centerVertical=true
android:layout_marginLeft=36dp
android:layout_marginStart=36dp
android:text=ON />
<Button
android:id=@+id/off
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=OFF
android:layout_alignBaseline=@+id/on
android:layout_alignBottom=@+id/on
android:layout_alignRight=@+id/textView
android:layout_alignEnd=@+id/textView />
</RelativeLayout>

Now, at last here is our java code i.e Main_Activity.

Main Activity.java



package com.example.root.led_control;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
Button on;
Button off;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
on = (Button) findViewById(R.id.on);
off = (Button) findViewById(R.id.off);
on.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference(LED_STATUS);
myRef.setValue(1);
}
});
off.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference(LED_STATUS);
myRef.setValue(0);
}
});
}
}

At last we end up with great tutorial on IOT home automation using Firebase , NodeMCU & Android App.

12 Comments

  1. Satyajeet on May 15, 2018

    where is code of ESP8266?

    Reply
  2. Unknown on May 28, 2018

    I can't able to simulate output in android app

    Reply
  3. suvathi on July 4, 2018

    Its an incredible joy perusing your post. It's brimming with data I am searching for and I want to post a remark that "The substance of your post is marvelous" Great work.
    android app development courses in chennai

    Reply
  4. saberi on August 11, 2018

    Hi Kavin
    Thank you for your amazing tutorial about iot, if i want to use your tutorial for many esp8266 board what should i do ? i want to have one app and every customer by knowing something unic about their board like some serial number or MAC address or anything we can define in the board can access their specific board using firebase, i need your help please help me (my email saberisajjad14@gmail.com)

    Reply
  5. William T.Mack on August 28, 2018

    this was a really nice post. In idea I would like to put in writing like this additionally ? taking time and actual effort to make a very good article? but what can I say? I procrastinate alot and by no means seem to get something done.
    kingroot apk

    Reply
  6. wpc on October 17, 2018

    Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    Digital Marketing Training

    Reply
  7. Sannihitha Technologies on December 25, 2018

    Thanks for sharing the details! thanks for sharing information,nice article.
    i would like to more information from your side!
    please added more then tips!Am working in
    Excel Training In Hyderabad

    Reply
  8. shady on June 14, 2019

    what if we want to create application for controlling more than one led lights

    Reply
  9. Sreenivas Kaushik on July 4, 2019

    Hi Kevin, Nice tutorial. I would like to know how to read the data from firebase when the app is loaded based on the database value? If the LED Status is 0 then need to show the ON button with LED on. OFF incase the database value is 1. How to handle this? Any help would be appreciated. Thanks in advance.

    Reply
  10. Joseph Whitaker on April 25, 2020

    I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. app store

    Reply
  11. yoyo on June 1, 2020

    I admit, I have not been on this web page in a long time… however it was another joy to see It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues. led work lights research by expert

    Reply

Leave a Reply