//20260415
//dht22
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#define DHTPIN 19
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;
const int OLED_RESET = -1;
const int SCREEN_ADDRESS = 0x3C;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_BMP085 bmp;
const unsigned char icono_temp [] PROGMEM = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xf0,0x03,0xff,0xff,0xf0,0x03,0xff,
0xff,0xf3,0xcf,0xff,0xff,0xf3,0xcf,0xff,
0xff,0xf3,0xc3,0xff,0xff,0xf2,0x43,0xff,
0xff,0xf2,0x4f,0xff,0xff,0xf2,0x4f,0xff,
0xff,0xf2,0x43,0xff,0xff,0xf2,0x43,0xff,
0xff,0xf2,0x4f,0xff,0xff,0xf2,0x4f,0xff,
0xff,0xe2,0x47,0xff,0xff,0xce,0x73,0xff,
0xff,0xcc,0x33,0xff,0xff,0x98,0x19,0xff,
0xff,0x98,0x19,0xff,0xff,0x98,0x19,0xff,
0xff,0x98,0x19,0xff,0xff,0x8c,0x31,0xff,
0xff,0xcf,0xf3,0xff,0xff,0xe3,0xc7,0xff,
0xff,0xf0,0x0f,0xff,0xff,0xf8,0x1f,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay();
bmp.begin();
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float temperatura = bmp.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Error DHT");
return;
}
Serial.print("Humedad: ");
Serial.print(h);
Serial.print("% Temp DHT: ");
Serial.print(t);
Serial.print("°C Temp BMP: ");
Serial.println(temperatura);
display.clearDisplay();
display.drawBitmap(5, 16, icono_temp, 32, 32, WHITE);
display.setTextSize(1);
display.setCursor(45, 10);
display.print("Temp:");
display.setTextSize(2);
display.setCursor(45, 25);
display.print(temperatura);
display.display();
}