This guide will help you create an IoT Weather Reporting System using Arduino and Raspberry Pi. The system will monitor real-time weather data such as temperature, humidity, and atmospheric pressure and transmit the data to a cloud platform for remote monitoring and analysis.

Components Required

  • Raspberry Pi (Model 3 or later)
  • Arduino (Uno or similar)
  • DHT11/DHT22 sensor (for temperature and humidity)
  • BMP180/BMP280 sensor (for atmospheric pressure)
  • Connecting wires and breadboard
  • Resistors and capacitors (as needed)
  • Wi-Fi module (ESP8266 or similar, if not using the Raspberry Pi's built-in Wi-Fi)
  • Power supply (for Raspberry Pi and Arduino)
  • Cloud service account (ThingSpeak, AWS IoT, etc.)

Setting Up the Hardware

Follow these steps to set up the hardware:

  1. Connect the Sensors to Arduino

    Connect the DHT11/DHT22 sensor to the Arduino for temperature and humidity measurements. Similarly, connect the BMP180/BMP280 sensor to measure atmospheric pressure. Use the breadboard and jumper wires to make the connections.

  2. Integrate Arduino with Raspberry Pi

    Connect the Arduino to the Raspberry Pi using USB. The Arduino will collect sensor data and send it to the Raspberry Pi for processing and transmission to the cloud.

  3. Power the System

    Ensure that both the Raspberry Pi and Arduino are properly powered using the appropriate power supplies.

Programming the Arduino

Use the Arduino IDE to program the Arduino for reading sensor data and transmitting it to the Raspberry Pi. Here's a basic outline of the code:


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

                #define DHTPIN 2
                #define DHTTYPE DHT11

                DHT dht(DHTPIN, DHTTYPE);
                Adafruit_BMP085 bmp;

                void setup() {
                Serial.begin(9600);
                dht.begin();
                bmp.begin();
                }

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

                Serial.print("Temperature: ");
                Serial.print(temperature);
                Serial.print(" C, Humidity: ");
                Serial.print(humidity);
                Serial.print(" %, Pressure: ");
                Serial.print(pressure);
                Serial.println(" hPa");

                delay(2000); // Wait 2 seconds before next reading
                }
            

This code reads data from the DHT11 and BMP180 sensors and sends it to the Raspberry Pi via the serial connection.

Setting Up the Raspberry Pi

The Raspberry Pi will process the data received from the Arduino and send it to the cloud. Here's how you can set it up:

  1. Install the Required Libraries

    Ensure your Raspberry Pi has Python installed. You'll need to install the following Python libraries:

    
                            sudo apt-get update
                            sudo apt-get install python3-serial
                            sudo pip3 install requests
                    
  2. Write the Python Script

    Create a Python script to read the serial data from the Arduino and send it to the cloud service. Here's an example:

    
                            import serial
                            import requests
    
                            # Replace with your cloud service URL
                            cloud_url = "https://api.thingspeak.com/update?api_key=YOUR_API_KEY"
    
                            ser = serial.Serial('/dev/ttyUSB0', 9600)
    
                            while True:
                                data = ser.readline().decode('utf-8').strip()
                                print(f"Received data: {data}")
    
                                # Parse the data (assuming it follows the format: "Temperature: 25.3 C, Humidity: 60 %, Pressure: 1013.25 hPa")
                                try:
                                    temp, hum, pres = [float(value.split(": ")[1].split(" ")[0]) for value in data.split(", ")]
                                    
                                    # Send data to cloud
                                    response = requests.get(f"{cloud_url}&field1={temp}&field2={hum}&field3={pres}")
                                    print(f"Data sent to cloud: {response.status_code}")
                                    
                                except Exception as e:
                                    print(f"Failed to parse or send data: {e}")
                        

    Ensure to replace the `cloud_url` with your cloud service's API endpoint and key.

  3. Run the Script

    Run the script on your Raspberry Pi to start sending weather data to the cloud:

    python3 weather_reporting.py

Visualizing Data on the Cloud

Once the data is sent to the cloud, you can visualize it using the cloud platform's built-in tools. For example, on ThingSpeak, you can create real-time graphs to monitor temperature, humidity, and pressure data over time.

Conclusion

With this IoT Weather Reporting System, you can monitor weather conditions in real-time from anywhere. By integrating Arduino and Raspberry Pi, this project provides a comprehensive approach to building a connected weather station that can be expanded with additional sensors or features as needed.