This project will guide you through the process of creating a simple weather station using an Arduino. The station will collect temperature, humidity, and pressure data, and display it on a web page.

Components Needed

  • Arduino board (e.g., Arduino Uno)
  • DHT11 or DHT22 temperature and humidity sensor
  • BMP180 or BMP280 pressure sensor
  • Breadboard and jumper wires
  • USB cable
  • Power supply for Arduino
  • Web server (e.g., ESP8266 or ESP32)

Steps

  1. Connect the Sensors to the Arduino: Connect the DHT11 or DHT22 to digital pin 2 and the BMP180 or BMP280 to analog pin A0.
  2. Upload the Code: Write a program to read the sensor data and send it to the web server.
  3. Set Up the Web Server: Connect the web server to your local network and create a web page to display the sensor data.
  4. Access the Web Page: Open the web page on your browser to view the weather data.

Example Code

#include <DHT.h>
#include <Wire.h>
#include <ESP8266WiFi.h>

#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "yourSSID";
const char* password = "yourPassword";

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  float pressure = (float)sensor.readPressure() / 101325.0;

  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");

  String webpage = "<html><body><h1>Weather Station</h1>";
  webpage += "<p>Temperature: ";
  webpage += temperature;
  webpage += " C</p>";
  webpage += "<p>Humidity: ";
  webpage += humidity;
  webpage += " %</p>";
  webpage += "<p>Pressure: ";
  webpage += pressure;
  webpage += " hPa</p></body></html>";

  WiFiClient client;
  client.begin("192.168.1.100", 80);
  client.println("GET / HTTP/1.1");
  client.println("Host: 192.168.1.100");
  client.println("Connection: close");
  client.println();
  client.print(webpage);
  client.stop();

  delay(10000);
}

Further Reading

For more information on Arduino and web servers, please visit our Arduino Web Server Tutorial.