Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to send sensor readings (LDR) onto Firebase Real-Time Database.
// Code to send sensor readings (LDR) onto Firebase Real-Time Database.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define WIFI_SSID "..................................." // WiFi SSID
#define WIFI_PASSWORD "..................................." //WiFi Password
#define FIREBASE_HOST "..................................." // my-realtime-database.firebaseio.com
#define FIREBASE_AUTH "..................................." // Firebase Authentication Token
#define LIGHT_PIN 0
int lum=0;
void setup() {
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting");
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(250);
}
Serial.println();
Serial.print("Connected, ip: ");
Serial.println(WiFi.localIP());
pinMode(LIGHT_PIN, INPUT);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
lum = analogRead(LIGHT_PIN);
Serial.println(lum);
Firebase.pushInt("light", lum);
if(Firebase.failed()){
Serial.println("Failed:");
}
delay(30000);
}
@decoded-cipher

This comment has been minimized.

Copy link
Owner Author

@decoded-cipher decoded-cipher commented Apr 22, 2021

const int LDR = A0; // Defining LDR PIN 
int input_val = 0;  // Varible to store Input values

void setup() {
   Serial.begin(9600); 
}

void loop() {  
   input_val = analogRead(LDR);      // Reading Input
   Serial.print("LDR value is : " );                        
   Serial.println(input_val);        // Writing input on serial monitor.
   delay(1000);       
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment