Alvin IlhamNivan Pratama Ihsan Yuwanto
Published

Prototype Smoke detector ESP32 connection Firebase

MQ-2 is a gas and smoke sensor that is often used in various electronics and IoT projects.

BeginnerFull instructions provided921
Prototype Smoke detector ESP32 connection Firebase

Things used in this project

Story

Read more

Schematics

scematic_diagram_lEhVOTfvDG.jpg

Code

ESP32 connection Firebase dengan sensor asap

Arduino
#include <FirebaseESP32.h>
#include <WiFi.h>

#define FIREBASE_HOST "htt.............................com/" // Salin kunci URL database Firebase Anda
#define FIREBASE_AUTH "p................................A"   // Salin kunci API Firebase Anda.

#define WIFI_SSID "Alv....a" // Wifi ssid Anda
#define WIFI_PASSWORD "alvn.......g" // Wifi Password Anda

FirebaseData fbdo; //fbdo adalah variabel. 

#define PinDigital 25 // mendefinisikan pin yang digunakan adalah pin Digital
int NilaiDigital;

void setup() {
  Serial.begin(9600);
  pinMode(PinDigital, INPUT); //mode pada pin D25 dijadikan sebagai input
  
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Menghubungkan Wi-Fi");
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  Serial.print("terhubung dengan WiFi IP: ");
  Serial.println(WiFi.localIP());
  Serial.println();

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop() {
  NilaiDigital = digitalRead(PinDigital); // membaca nilai digital

  Serial.print("Nilai Output Digital = ");
  Serial.println(NilaiDigital);
  //Aktif LOW = Jika Ada Asap Maka Nilai nya 0 jika tidak ada Asap maka nilai Nya 1

  //Proses Kirim Data
  Firebase.setFloat(fbdo, "/Nilai_Asap", NilaiDigital);
  
  if(NilaiDigital==0){
    Firebase.setString(fbdo, "/Kondisi", "Ada Asap");
  } else {
    Firebase.setString(fbdo, "/Kondisi", "Aman");
  }
  
  delay(1000);
}

Credits

Alvin Ilham

Alvin Ilham

1 project • 0 followers
Nivan Pratama Ihsan Yuwanto

Nivan Pratama Ihsan Yuwanto

1 project • 0 followers

Comments