
Materials Needed:
- ESP32 WROOM 32D / ESP32 Devlopment Board
- DHT11 or DHT22 temperature and humidity sensor
- BMP280 pressure sensor
- Breadboard
- Jumper wires
- Micro USB cable
- Computer with Arduino IDE installed
Step 1: Set Up Arduino IDE
- Open the Arduino IDE and go to File.
- File -> Preferences
- In the “Additional Board Manager URLs” field, add the following URL:
https://dl.espressif.com/dl/package_esp32_index.json
. - Click OK to save the preferences.
Step 2: Install ESP32 Board Package
- Go to Tools -> Board -> Boards Manager.
- Search for “ESP32” and install the “esp32” board package by Espressif Systems.
- Once installation is complete, select your ESP32 board from Tools -> Board menu. Choose the appropriate variant (e.g., ESP32 Dev Module).
Step 3: Connect Sensors
- Connect the DHT11 or DHT22 sensor to the ESP32 WROOM 32D:
- DHT11/DHT22 VCC pin to ESP32 3.3V pin
- DHT11/DHT22 GND pin to ESP32 GND pin
- DHT11/DHT22 data pin to any GPIO pin on the ESP32 (e.g., GPIO 4)
- Connect the BMP280 pressure sensor to the ESP32 WROOM 32D:
- BMP280 VCC pin to ESP32 3.3V pin
- BMP280 GND pin to ESP32 GND pin
- BMP280 SDA pin to ESP32 GPIO pin (e.g., GPIO 21)
- BMP280 SCL pin to ESP32 GPIO pin (e.g., GPIO 22)
Step 4: Write the Code
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
const char* ssid = "your_network_name";
const char* password = "your_network_password";
#define DHTPIN 4 // DHT sensor pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
if (!bmp.begin()) {
Serial.println("Could not find BMP280 sensor");
while (1);
}
Serial.println("BMP280 sensor found");
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
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");
delay(5000); // Delay 5 seconds before taking the next reading
}
Step 5: Upload the Code
- Connect the ESP32 WROOM 32D to your computer using a micro USB cable.
- Select the particular board and port.
- Upload the code to the ESP32.
Step 6: Monitor Sensor Readings
- Open the Serial Monitor.
- You should see the temperature, humidity, and pressure readings displayed in the Serial Monitor window.
Step 7: Display Data on Web Server (Optional) If you want to display the weather data on a web server hosted by the ESP32, you can use the ESPAsyncWebServer library to set up a simple web server. Let me know if you’d like assistance with this step.
With these steps, you should have a basic home weather station up and running using the ESP32 WROOM 32D.
Here’s how you can modify the code to display the weather data on a simple web server hosted by the ESP32 WROOM 32D:
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "your_network_name";
const char* password = "your_network_password";
#define DHTPIN 4 // DHT sensor pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
if (!bmp.begin()) {
Serial.println("Could not find BMP280 sensor");
while (1);
}
Serial.println("BMP280 sensor found");
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float pressure = bmp.readPressure() / 100.0F; // Convert Pa to hPa
String data = "Temperature: " + String(temperature) + " °C<br>";
data += "Humidity: " + String(humidity) + " %<br>";
data += "Pressure: " + String(pressure) + " hPa<br>";
request->send(200, "text/html", data);
});
server.begin();
}
void loop() {}
In this modified code:
- We include the
ESPAsyncWebServer.h
library to set up an asynchronous web server. - Inside the
setup()
function, we initialize the web server on port 80. - We define route (“/”) which handles HTTP GET requests. When a GET request is received, the server reads the sensor data and constructs an HTML response with the data.
- The HTML response includes the temperature, humidity, and pressure data in a simple format.
- Finally, the server sends the HTML response back to the client.
With this code, when you navigate to the IP address of your ESP32 WROOM 32D in a web browser, you should see a page displaying the weather data. Make sure to replace “your_network_name” and “your_network_password” with your actual Wi-Fi network credentials.
Upload this code to your ESP32 WROOM 32D, and you should be able to access the weather data from any device connected to the same network by typing the ESP32’s IP address into a web browser.