forked from YUVRAJ06singh08deora/E-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino_code_payO2.ino
More file actions
66 lines (42 loc) · 2.08 KB
/
Arduino_code_payO2.ino
File metadata and controls
66 lines (42 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>
#define FIREBASE_HOST "pay02-59367-default-rtdb.firebaseio.com" //Your Firebase Project URL goes here without "http:" , "\" and "/"
#define FIREBASE_AUTH "zdYDzo7kcnIeqaq6uMRzXfv3VKGpeNquluHoS5Kj" //Your Firebase Database Secret goes here
#define WIFI_SSID "yuvraj" //WiFi SSID to which you want NodeMCU to connect
#define WIFI_PASSWORD "12345678" //Password of your wifi network
int smokeA0 = A0;
// Declare the Firebase Data object in the global scope
FirebaseData firebaseData;
void setup() {
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
pinMode(smokeA0, INPUT);
Serial.println("Serial communication started\n\n");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); //print local IP address
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Firebase.reconnectWiFi(true);
delay(1000);
}
void loop() {
int analogSensor = analogRead(smokeA0);
// Firebase Error Handling And Writing Data At Specifed Path************************************************
if (Firebase.setInt(firebaseData, "/carbonEmission", analogSensor)) { // On successful Write operation, function returns 1
Serial.println("Value Uploaded Successfully to smart Contract");
Serial.print("Carbon Emission = ");
Serial.println(analogSensor);
Serial.println("\n");
}
else {
Serial.println(firebaseData.errorReason());
}
}