Last active
April 22, 2021 12:23
-
-
Save decoded-cipher/7d3defd997925dddac564be89784f16e to your computer and use it in GitHub Desktop.
Code to send sensor readings (LDR) onto Firebase Real-Time Database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Author
decoded-cipher
commented
Apr 22, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment