Press ESC to close

Or check our Popular Categories...

IOT with Firebase : Sensor Alert Push Notification to Android App Using FCM & PUSHER #PART4

3 Min Read

I continue teaching IOT with Firebase through problem solving. In this video I’ll show step by step guide to Setup Sensor Alert for Sending Push Notification to Android App by Using FCM (Firebase Cloud Messaging) & Pusher.In this tutorial we configure our android app and setup pusher notifications for sending manual Push Notifications in later tutorial we’ll create a python script for sending automatic push notifications to android app if sensor detects any fire.

Video :

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

Transcript / Cheat Sheet:

Arduino :

Circuit Diagram :

Above diagram connections:

Sensor A0 -> Node MCU Analog Pin
SENSOR alert LED -> Node MCU D5 Pin
Home Automation LED -> Node MCU D1 Pin

Arduino Code :

#include <FirebaseArduino.h>

#include <ESP8266WiFi.h>

// Set these to run example.
#define FIREBASE_AUTH qULRQbnuzJ3qk———Xic1UQ1FxHvM
#define WIFI_SSID kavin
#define WIFI_PASSWORD 1123581321
float fire;
void setup() {
pinMode(D1, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(A0, INPUT);
// connect to wifi.
while (WiFi.status() != WL_CONNECTED) {
Serial.print(connected: );
Firebase.set(LED_STATUS, 0);
int n = 0;
void loop() {
// get value
fire = analogRead(A0);
n = Firebase.getInt(LED_STATUS);
// handle error
if (n==1) {
Serial.println(LED ON);
else {
Serial.println(LED OFF);
Android App Code : 

    Firstly we need to add FCM to our app for that Navigate to Tools -> Firebase, under Cloud Messaging click Setup Firebase Cloud Messaging. Now follow Step 1 & Step 2 which will help in Connecting your app with Firebase & add FCM dependency to your app.

    Navigate to App/build.gradle, add dependency for pusher-notification API .


    apply plugin:

    android {

    compileSdkVersion 26
    buildToolsVersion 27.0.3
    defaultConfig {
    applicationId com.example.root.ledcontrol
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName 1.0
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile(proguard-android.txt),
    dependencies {
    compile fileTree(dir: libs, include: [*.jar])
    androidTestCompile(, {
    exclude group:, module: support-annotations
    compile com.pusher:push-notifications-android:0.9.12
    testCompile junit:junit:4.12
    apply plugin:
       Now sync your gradle file and Add Pusher Code to Main which we get from pusher quick start guide

      import android.os.Bundle;
      import android.view.View;
      import android.widget.Button;
      import com.pusher.pushnotifications.PushNotifications;
      public class MainActivity extends AppCompatActivity {
      Button on;
      Button off;
      protected void onCreate(Bundle savedInstanceState) {
      PushNotifications.start(getApplicationContext(), 61d2753d-9e78-4bc5-86d4-61e44fedab27);
      on = (Button) findViewById(;
      off = (Button) findViewById(;
      on.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
      FirebaseDatabase database = FirebaseDatabase.getInstance();
      DatabaseReference myRef = database.getReference(LED_STATUS);
      off.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
      FirebaseDatabase database = FirebaseDatabase.getInstance();
      DatabaseReference myRef = database.getReference(LED_STATUS);

        Now build your gradle and Run app device & once compilation done you will get Continue option in pusher quick start guide after which we get code for sending push-notifications manually to our App.

        Code Sample (run in terminal ) :

        curl -H Content-Type: application/json

        -H Authorization: Bearer 01CCFEA41DC49B7BE0782BC9BE6F064

        -X POST
        -d {“interests”:[“hello”],”fcm”:{“notification”:{“title”:”Hello”,”body”:”Hello, world!”}}}
        that’s it for this tutorial in next Tutorial i will show you how to create Python script for sending automated push notification to android app if sensor detects any Fire Alert.

          Categorized in:


          1. Unknown on April 16, 2018

            I have a doubt, you are using only curl or what else you use to apply "curl -H" Content-Type: application / json ""

          2. kavin sharma on April 17, 2018

            we can create a python script which will automatically send push notification when some value changes in database
            Check out :

          3. Burgess on May 7, 2018

            While tablets should be conveyed in packs or in their unique cases, cell phones can without much of a stretch be put inside pockets. fallout 4 endurance bobbleheads locations

          4. judden jout on May 23, 2018

            A portion of the prominent offering stock incorporates. periscope apk download

          5. on December 8, 2018

            Bro can u please send me the app making code.specially the activity_main.xml

          6. kavin sharma on December 8, 2018

            i will suggest you to check previous part of this post which includes all source code

          7. Steven on February 1, 2019

            For additional wellbeing, you can even do your squats on a smith machine. So on the off chance that you are a learner, I propose crouching on a smith machine until you become acclimated to doing them legitimately. interval running

          8. Unknown on May 11, 2019

            Hello! I need help. I did everything as written by you and watched the video. BUT I do not receive notifications on the application. I add changes to FIreBase because there is no arduino. In the end, nothing comes

          9. Anonymous on May 18, 2019

            Sir, i want to know about the sensor used in this project

          10. tike mik on January 27, 2020

            Still it is the story of the human and the divine, not intended to be opposing forces, but certainly if not oddly playing out in the landscape of free will and providence…and eventually, the "Man of La Manga." was born.

            kiss manga

          11. Smith on March 21, 2020

            Transforming a relaxation time movement or enthusiasm into full time calling could be a fantasy occupation and Android Game Development could be named one.

          12. Unknown on May 2, 2020

            why didn't use firebase push notification???

          Comments are closed.