Hello Good Day to Everyone. I have a project where I need to send DHT11 sensor data to a Firebase database using both Arduino UNO and Esp8266 esp-01 wifi module. Both of them must work together to send the data.
Arduino Code:
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
My arduino code is working fine. Now comes the part where I need to program the ESP8266 which I am really confused how to pass the data to the wifi module and send it to firebase. I tried to code some and this is my
ESP8266 Code:
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.h>
#define FIREBASE_HOST "test.firebaseio.com"
#define FIREBASE_AUTH "authcode"
#define WIFI_SSID "mywifi"
#define WIFI_PASSWORD "12345"
#define DHTTYPE DHT11
#define DHTPIN 7
DHT dht(DHTPIN, DHTTYPE);
float temp_f;
unsigned long previousMillis = 0;
const long interval = 2300;
void setup() {
Serial.begin(9600);
dht.begin();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
delay(50);
Firebase.setFloat("temp",t);
Firebase.setFloat("hum",h);
delay(1000);
}
I don't want my esp8266 to go stand alone. I wanted the data to come from the arduino but somehow I don't know how to receive the data from the arduino in the esp8266.
I hope someone can enlighten me.. thank you