#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define DHTPIN 14 // Pin DHT22
#define DHTTYPE DHT22 // Tipo de sensor DHT
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
// Inicializar la pantalla OLED
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
}
void loop() {
// Leer la temperatura y la humedad del sensor DHT
float temperatura = dht.readTemperature();
float humedad = dht.readHumidity();
// Mostrar la temperatura y la humedad en la pantalla OLED
oled.clearDisplay();
oled.setTextSize(1.8);
oled.setTextColor(WHITE);
oled.setCursor(0, 0);
oled.print("Temperatura: ");
oled.print(temperatura);
oled.print(" C");
oled.setCursor(0, 10);
oled.print("Humedad: ");
oled.print(humedad);
oled.print(" %");
oled.display();
delay(2000);
}