Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Creating a weather station using Arduino is an exciting and educational project that allows you to measure and monitor various atmospheric conditions such as temperature, humidity, and pressure. This article will guide you through the process of building your own weather station using an Arduino board and a few sensors.
Connect the DHT22 Sensor:
Connect the BMP180 Sensor:
Optional: Connect the LCD Display:
Before writing the code, you need to install the necessary libraries for the sensors. Open the Arduino IDE and go to Sketch -> Include Library -> Manage Libraries
. Search for and install the following libraries:
DHT sensor library
by AdafruitAdafruit Unified Sensor
by AdafruitAdafruit BMP085 Unified
(for BMP180) or Adafruit BMP280
(for BMP280)Create a new sketch in the Arduino IDE and enter the following code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h> // Use Adafruit_BMP280.h for BMP280
#include <DHT.h>
#include <LiquidCrystal.h> // Include this if using an LCD
#define DHTPIN 2
#define DHTTYPE DHT22 // Change to DHT11 if using DHT11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
void setup() {
Serial.begin(9600);
dht.begin();
if(!bmp.begin()) {
Serial.print("Could not find a valid BMP085 sensor, check wiring!");
while(1);
}
// If using an LCD, initialize it here
// lcd.begin(16, 2);
}
void loop() {
// Reading temperature and humidity from DHT22
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Reading pressure from BMP180
sensors_event_t event;
bmp.getEvent(&event);
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
if (event.pressure) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" *C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Pressure: ");
Serial.print(event.pressure);
Serial.println(" hPa");
// If using an LCD, display the data here
// lcd.setCursor(0, 0);
// lcd.print("Temp: ");
// lcd.print(temperature);
// lcd.print(" C");
// lcd.setCursor(0, 1);
// lcd.print("Hum: ");
// lcd.print(humidity);
// lcd.print(" %");
}
delay(2000);
}
Connect your Arduino to your computer using the USB cable. Select the correct board and port from the Tools
menu in the Arduino IDE. Click the upload button to transfer the code to your Arduino.
Open the Serial Monitor from the Tools
menu to see the temperature, humidity, and pressure readings. If you have connected an LCD, the data will also be displayed there.
By following these steps, you have successfully created a basic weather station using an Arduino. You can expand this project by adding more sensors, logging data to an SD card, or even uploading the data to a cloud service for remote monitoring.