#include <DHT.h>
#include <WiFi.h>
#include "ThingSpeak.h"
#define DHTPIN 21
#define DHTTYPE DHT22
const char* ssid = "Wokwi-GUEST"; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "";
DHT dht22 (DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200); //1bit=10µs
pinMode(15, INPUT);
pinMode(14, OUTPUT);
Serial.println("\ntest capteur DTH22");
dht22.begin();
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
}
float h;
float t;
void loop() {
float nh = dht22.readHumidity();
float nt = dht22.readTemperature();
if(nh == h && t == nt){
delay(2000);
return;
}
h = nh;
t = nt;
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature: ");
Serial.println(t);
if(t > 50) digitalWrite(14, HIGH);
else digitalWrite(14, LOW);
delay(15000); //Collecting period should be : >1.7 second
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4