Facebook
From rennyson100a, 5 Months ago, written in C++.
Embed
Download Paste or View Raw
Hits: 129
  1. #include <DHT.h>
  2. #include <ESP8266WiFi.h>
  3. #include <ESP8266WebServer.h>
  4.  
  5. const int dhtPin = 4;  // GPIO4 para DHT11
  6. const int higroPin = A0;
  7. int higroValue = 0; // valor inicial
  8.  
  9. DHT dht(dhtPin, DHT11);
  10.  
  11. void setup() {
  12.   Serial.begin(115200);
  13.   dht.begin();
  14. }
  15.  
  16. void loop() {
  17.   // Read the temperature and humidity data from the sensor
  18.   float temperature = dht.readTemperature();
  19.   float humidity = dht.readHumidity();
  20.   higroValue = analogRead(higroPin);
  21.  
  22.   // Print the data to the serial monitor
  23.   Serial.print("Temperature: ");
  24.   Serial.print(temperature);
  25.   Serial.println(" C");
  26.   Serial.print("Humidity: ");
  27.   Serial.print(humidity);
  28.   Serial.println(" %");
  29.   Serial.print("sensor = ");
  30.   Serial.print(higroValue);
  31.  
  32.  
  33.   // Wait for 2 seconds before taking the next reading
  34.   delay(2000);
  35. }