Arduino Mega ADK Weather Monitoring Station with SD Data Logging
View and Edit Project In Cirkit Designer
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)
- Microcontroller board based on the ATmega2560
- It has 54 digital input/output pins, 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.
DHT22
- A basic, low-cost digital temperature and humidity sensor.
- It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin.
BMP180
- A high-precision, ultra-low power digital barometer.
- It provides a measurement range from 300 to 1100 hPa with an accuracy down to 0.02 hPa in advanced resolution mode.
Water Level Sensor
- A simple and cost-effective sensor for measuring water level.
- It can be used to detect the level of liquid in a tank or container.
Micro SD Card Module
- An SD card module that allows reading and writing to an SD card using the SPI communication protocol.
- It is compatible with the Arduino and can be used for data logging applications.
Wind Vane
- A sensor for detecting wind direction.
- It can also be used to measure wind speed by counting rotations or changes in voltage.
Wiring Details
Arduino Mega ADK (Rev3)
A0connected to Water Level Sensor (SIG)A1connected to Wind Vane (A0)A4(SDA) connected to BMP180 (SDA)A5(SCL) connected to BMP180 (SCL)5Vconnected to DHT22 (VCC), Micro SD Card Module (vcc), BMP180 (VCC), Water Level Sensor (VCC), and Wind Vane (VCC)GNDconnected to DHT22 (GND), Micro SD Card Module (gnd), BMP180 (GND), Water Level Sensor (GND), and Wind Vane (GND)D2 PWMconnected to DHT22 (DAT)D4 PWMconnected to Micro SD Card Module (cs)D50/MISOconnected to Micro SD Card Module (miso)D51/MOSIconnected to Micro SD Card Module (mosi)D52/SCKconnected to Micro SD Card Module (sck)
DHT22
GNDconnected to Arduino Mega ADK (GND)VCCconnected to Arduino Mega ADK (5V)DATconnected to Arduino Mega ADK (D2 PWM)
BMP180
3.3(Not connected)SDAconnected to Arduino Mega ADK (A4)SCLconnected to Arduino Mega ADK (A5)GNDconnected to Arduino Mega ADK (GND)VCCconnected to Arduino Mega ADK (5V)
Water Level Sensor
SIGconnected to Arduino Mega ADK (A0)VCCconnected to Arduino Mega ADK (5V)GNDconnected to Arduino Mega ADK (GND)
Micro SD Card Module
csconnected to Arduino Mega ADK (D4 PWM)sckconnected to Arduino Mega ADK (D52/SCK)mosiconnected to Arduino Mega ADK (D51/MOSI)misoconnected to Arduino Mega ADK (D50/MISO)vccconnected to Arduino Mega ADK (5V)gndconnected to Arduino Mega ADK (GND)
Wind Vane
A0connected to Arduino Mega ADK (A1)VCCconnected to Arduino Mega ADK (5V)GNDconnected to Arduino Mega ADK (GND)
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() {