#include <Arduino.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA>
#include <DHT.h>
#include <Adafruit_BMP280.h>
#define DHTPIN 2 // Define the pin to which the DHT11 sensor is connected
#define DHTTYPE DHT11 // DHT 11
#define LED_PIN 13 // Define the pin to which the LED is connected
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;
const char* ssid = "YourSSID";
const char* password = "YourPassword";
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(LED_PIN, OUTPUT); // Set the LED pin as an output
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
ArduinoOTA.begin();
ArduinoOTA.setHostname("ESP32-OTA");
ArduinoOTA.setPassword("YourOTAPassword");
dht.begin();
if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}
void loop() {
ArduinoOTA.handle();
digitalWrite(LED_PIN, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second
digitalWrite(LED_PIN, LOW); // Turn off the LED
delay(1000); // Wait for 1 second
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float pressure = bmp.readPressure() / 100.0F;
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
}
}