Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Resistor 10k ohm
Breadboard (generic)
DHT11 Temperature & Humidity Sensor (4 pins)
NodeMCU ESP8266 Breakout Board
Software & Tools
Firebase
Project description
Code
Uploading data to firebase
c_cpp
*to be uploaded on the nodeMCU* This code uploads the data received by the nodeMCU on to firebase.
1#include <ESP8266WiFi.h> 2#include <FirebaseArduino.h> 3#include <SoftwareSerial.h> 4 5// 6 Set these to run example. 7#define FIREBASE_HOST "***********************************" 8#define 9 FIREBASE_AUTH "***********************************" 10#define WIFI_SSID "WiFi 11 ssid" 12#define WIFI_PASSWORD "PASSWORD" 13SoftwareSerial esp(D2,D3); 14 15void 16 setup() { 17 Serial.begin(9600); 18 esp.begin(4800); 19 20 // connect to 21 wifi. 22 WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 23 Serial.print("connecting"); 24 25 while (WiFi.status() != WL_CONNECTED) { 26 Serial.print("."); 27 delay(500); 28 29 } 30 Serial.println(); 31 Serial.print("connected: "); 32 Serial.println(WiFi.localIP()); 33 34 35 Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 36} 37 38int n = 0; 39float 40 val; 41 42void loop() { 43 44 while(esp.available()>0) 45 { 46 float 47 val = esp.parseFloat(); 48 if(esp.read()=='\ 49') 50 { 51 Serial.println(val); 52 53 54 } 55 56 // set value 57 Firebase.setFloat("number", val); 58 59 // handle error 60 if (Firebase.failed()) { 61 Serial.print("setting 62 /number failed:"); 63 Serial.println(Firebase.error()); 64 return; 65 66 } 67 delay(100); 68 69 70 71 // get value 72 Serial.print("number: 73 "); 74 Serial.println(Firebase.getFloat("number")); 75 delay(100); 76 77 78 79 // append a new value to /logs 80 String name = Firebase.pushInt("logs", n++); 81 82 // handle error 83 if (Firebase.failed()) { 84 Serial.print("pushing 85 /logs failed:"); 86 Serial.println(Firebase.error()); 87 return; 88 89 } 90 Serial.print("pushed: /logs/"); 91 Serial.println(name); 92 delay(100); 93 94 } 95} 96
Uploading data to firebase
c_cpp
*to be uploaded on the nodeMCU* This code uploads the data received by the nodeMCU on to firebase.
1#include <ESP8266WiFi.h> 2#include <FirebaseArduino.h> 3#include <SoftwareSerial.h> 4 5// Set these to run example. 6#define FIREBASE_HOST "***********************************" 7#define FIREBASE_AUTH "***********************************" 8#define WIFI_SSID "WiFi ssid" 9#define WIFI_PASSWORD "PASSWORD" 10SoftwareSerial esp(D2,D3); 11 12void setup() { 13 Serial.begin(9600); 14 esp.begin(4800); 15 16 // connect to wifi. 17 WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 18 Serial.print("connecting"); 19 while (WiFi.status() != WL_CONNECTED) { 20 Serial.print("."); 21 delay(500); 22 } 23 Serial.println(); 24 Serial.print("connected: "); 25 Serial.println(WiFi.localIP()); 26 27 Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 28} 29 30int n = 0; 31float val; 32 33void loop() { 34 35 while(esp.available()>0) 36 { 37 float val = esp.parseFloat(); 38 if(esp.read()=='\n') 39 { 40 Serial.println(val); 41 42 } 43 44 // set value 45 Firebase.setFloat("number", val); 46 // handle error 47 if (Firebase.failed()) { 48 Serial.print("setting /number failed:"); 49 Serial.println(Firebase.error()); 50 return; 51 } 52 delay(100); 53 54 55 56 // get value 57 Serial.print("number: "); 58 Serial.println(Firebase.getFloat("number")); 59 delay(100); 60 61 62 // append a new value to /logs 63 String name = Firebase.pushInt("logs", n++); 64 // handle error 65 if (Firebase.failed()) { 66 Serial.print("pushing /logs failed:"); 67 Serial.println(Firebase.error()); 68 return; 69 } 70 Serial.print("pushed: /logs/"); 71 Serial.println(name); 72 delay(100); 73 } 74} 75
serial communication
c_cpp
*To be uploaded on the arduino uno* This is the code for serial communication between arduino uno and nodeMCU (esp8266).
1#include <SoftwareSerial.h> 2SoftwareSerial ArduinoUno(3,2); 3int n; 4void setup() { 5 // put your setup code here, to run once: 6 Serial.begin(9600); 7 ArduinoUno.begin(4800); 8 9pinMode (3,INPUT); 10pinMode (2,OUTPUT); 11 12} 13 14void loop() { 15 // put your main code here, to run repeatedly: 16 n=analogRead(A2); 17 ArduinoUno.print(n); 18 ArduinoUno.println("\ 19"); 20 Serial.println(n); 21 delay(300); 22} 23
Downloadable files
circuit
This one is just for reference. It will be updated soon.
circuit

circuit
This one is just for reference. It will be updated soon.
circuit

Comments
Only logged in users can leave comments