Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega ADK Weather Monitoring Station with SD Data Logging

View and Edit Project In Cirkit DesignerImage of Arduino Mega ADK Weather Monitoring Station with SD Data Logging

Circuit Documentation

Summary

This circuit is designed to monitor environmental parameters such as water level, wind speed, temperature, humidity, and atmospheric pressure. It utilizes an Arduino Mega ADK (Rev3) as the central microcontroller to interface with various sensors including a DHT22 for temperature and humidity, a BMP180 for atmospheric pressure, a water level sensor, and a wind vane for wind speed. The data collected from these sensors is logged onto an SD card using a Micro SD Card Module. The circuit is powered by the Arduino's 5V output, and ground connections are shared across the components.

Component List

Arduino Mega ADK (Rev3)

DHT22

BMP180

Water Level Sensor

Micro SD Card Module

Wind Vane

Wiring Details

Arduino Mega ADK (Rev3)

DHT22

BMP180

Water Level Sensor

Micro SD Card Module

Wind Vane

Documented Code

Arduino Mega ADK (Rev3) Code

#include <SPI.h>
#include <SD.h>
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

// Define the pins
const int waterSensorPin = A0;     // Water level sensor connected to A0
const int windSensorPin = A1;      // Wind speed sensor connected to A1
const int chipSelect = 4;          // Chip select pin for the SD card
const float radius = 2.5;          // Radius of the cup in cm
const float conversionFactor = 17.76; // Example conversion factor from voltage to km/h

// DHT22 setup
#define DHTPIN 2                   // DHT22 data pin connected to pin 2
#define DHTTYPE DHT22              // Define DHT type
DHT dht(DHTPIN, DHTTYPE);          // Create DHT object

// BMP180 setup
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); // Create BMP180 object

void setup() {
  // Start the serial communication
  Serial.begin(9600);

  // Initialize the DHT22 sensor
  dht.begin();

  // Initialize the BMP180 sensor
  if (!bmp.begin()) {
    Serial.print("Could not find a valid BMP180 sensor, check wiring!");
    while (1); // Stop execution if BMP180 is not found
  }

  // Initialize the SD card
  if (!SD.begin(chipSelect)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");

  // Create or open a file on the SD card
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.println("Water Level (mL), Wind Speed (km/h), Temperature (°C), Humidity (%), Pressure (kPa):");
    dataFile.close();
  } else {
    Serial.println("Error opening datalog.txt");
  }
}

void loop() {
  // Read the value from the water sensor
  int waterSensorValue = analogRead(waterSensorPin);

  // Convert the water sensor value to height (assuming a linear relationship)
  float height = map(waterSensorValue, 0, 1023, 0, 4); // Adjust the mapping based on your sensor calibration

  // Calculate the volume in mL
  float volume = 3.14159 * radius * radius * height;

  // Print the water volume to the Serial Monitor
  Serial.print("Water Volume: ");
  Serial.print(volume);
  Serial.println(" mL");

  // Read the voltage from the wind sensor
  int windSensorValue = analogRead(windSensorPin);

  // Convert the wind sensor value to voltage (assuming 5V reference)
  float voltage = windSensorValue * (5.0 / 1023.0);

  // Convert the voltage to wind speed in km/h
  float windSpeed = voltage * conversionFactor;

  // Print the wind speed to the Serial Monitor
  Serial.print("Wind Speed: ");
  Serial.print(windSpeed);
  Serial.println(" km/h");

  // Read temperature and humidity from DHT22
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Read pressure from BMP180
  sensors_event_t event;
  bmp.getEvent(&event);
  float pressure = event.pressure / 10.0; // Convert hPa to kPa

  // Print temperature, humidity, and pressure to the Serial Monitor
  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(" kPa");

  // Save the data to the SD card
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print(volume);
    dataFile.print(" mL, ");
    dataFile.print(windSpeed);
    dataFile.print(" km/h, ");
    dataFile.print(temperature);
    dataFile.print(" °C, ");
    dataFile.print(humidity);
    dataFile.print(" %, ");
    dataFile.print(pressure);
    dataFile.println(" kPa");
    dataFile.close();
  } else {
    Serial.println("Error opening datalog.txt");
  }

  // Wait for a short period before reading again
  delay(500);
}

BMP180 Code (Unused)

void setup() {