Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decoded-cipher/7d3defd997925dddac564be89784f16e to your computer and use it in GitHub Desktop.
Save decoded-cipher/7d3defd997925dddac564be89784f16e to your computer and use it in GitHub Desktop.
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
Copy link
Author

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