Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Solar-Powered Arduino Weather Station with Data Logging

Image of Solar-Powered Arduino Weather Station with Data Logging

Circuit Documentation

Summary

The circuit in question is designed to collect environmental data and log it to an SD card. It utilizes an Arduino Nano as the central microcontroller to interface with a BMP280 sensor for atmospheric pressure, a DHT22 sensor for temperature and humidity, a DS3231 Real Time Clock (RTC) for timekeeping, an SD card module for data logging, and a solar panel with a charge controller to power the system. A lithium-ion battery provides energy storage to ensure continuous operation.

Component List

Arduino Nano

  • Microcontroller board based on the ATmega328P
  • Provides digital and analog I/O pins
  • Includes communication interfaces such as I2C and SPI
  • Can be powered via USB or external power source (VIN pin)

BMP280

  • Digital pressure sensor
  • Capable of measuring temperature as well
  • Interfaces with the microcontroller via I2C

DHT22

  • Digital temperature and humidity sensor
  • Provides calibrated digital output
  • Uses a single digital pin for data communication

DS3231 RTC

  • Real Time Clock module
  • Maintains accurate timekeeping with a built-in temperature-compensated crystal oscillator (TCXO)
  • Communicates with the microcontroller via I2C

SD Card Module

  • Allows for reading and writing to SD cards
  • Uses SPI for communication with the microcontroller

OLED 1.3" Display

  • Small display for visual output
  • Typically communicates over I2C

Lithium-ion Battery 10000mAh

  • Provides a 11.1V power source
  • Used for energy storage in the system

Charge Controller

  • Manages charging of the lithium-ion battery from the solar panel
  • Protects the battery from overcharging and deep discharge

Solar Panel

  • Converts sunlight into electrical energy
  • Charges the battery through the charge controller

Wiring Details

Arduino Nano

  • GND connected to common ground
  • D2 connected to DHT22 data pin
  • D10 connected to SD card module CS pin
  • D11/MOSI connected to SD card module MOSI pin
  • D12/MISO connected to SD card module MISO pin
  • D13/SCK connected to SD card module SCK pin
  • VIN connected to the battery output via the charge controller
  • 5V connected to BMP280 VCC, DS3231 RTC VCC, SD card module +5V, and DHT22 VCC
  • A4 connected to BMP280 SDA and DS3231 RTC SDA
  • A5 connected to BMP280 SCL and DS3231 RTC SCL

BMP280

  • GND connected to common ground
  • VCC connected to 5V from Arduino Nano
  • SDA connected to A4 on Arduino Nano
  • SCL connected to A5 on Arduino Nano

DHT22

  • GND connected to common ground
  • VCC connected to 5V from Arduino Nano
  • DAT connected to D2 on Arduino Nano

DS3231 RTC

  • GND connected to common ground
  • VCC connected to 5V from Arduino Nano
  • SCL connected to A5 on Arduino Nano
  • SDA connected to A4 on Arduino Nano

SD Card Module

  • GND connected to common ground
  • +3.3V (not connected in this configuration)
  • +5V connected to 5V from Arduino Nano
  • CS connected to D10 on Arduino Nano
  • MOSI connected to D11/MOSI on Arduino Nano
  • SCK connected to D13/SCK on Arduino Nano
  • MISO connected to D12/MISO on Arduino Nano

Lithium-ion Battery 10000mAh

  • 11.1V connected to BAT on the charge controller and VIN on Arduino Nano
  • GND connected to common ground

Charge Controller

  • GND connected to common ground and solar panel negative terminal
  • BAT connected to the lithium-ion battery 11.1V terminal
  • Vin connected to the solar panel positive terminal

Solar Panel

  • + connected to Vin on the charge controller
  • - connected to GND on the charge controller

Documented Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <Adafruit_BMP280.h>  // If using BMP280, use this library
#include <SD.h>
#include <RTClib.h>

#define DHTPIN 2          // DHT22 data pin
#define DHTTYPE DHT22
#define SD_CS_PIN 10      // SD Card CS pin

DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp;  // Change to BMP280 if using this sensor
RTC_DS3231 rtc;
File dataFile;

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

  // Initialize BMP280 Sensor
  if (!bmp.begin()) {
    Serial.println("BMP280 sensor not detected!");
    while (1);  // Stop execution if sensor is not detected
  }

  // Initialize RTC Module
  if (!rtc.begin()) {
    Serial.println("RTC module not detected!");
    while (1);  // Stop execution if RTC is not detected
  }

  // Initialize SD Card
  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("SD Card initialization failed!");
    return;  // Stop further execution if SD card fails
  }

  // Write header to the SD file
  dataFile = SD.open("weather_log.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.println("Date Time, Temperature (C), Humidity (%), Pressure (hPa)");
    dataFile.close();
  } else {
    Serial.println("Failed to open weather log file.");
  }
}

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

  // Check if any reading fails, skip logging that iteration
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Get current time from RTC
  DateTime now = rtc.now();
  String timestamp = String(now.year()) + "-" + String(now.month()) + "-" + String(now.day()) + " " +
                     String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second());

  // Print to Serial Monitor
  Serial.print(timestamp);
  Serial.print(", ");
  Serial.print(temperature);
  Serial.print(", ");
  Serial.print(humidity);
  Serial.print(", ");
  Serial.println(pressure);

  // Write to SD card
  dataFile = SD.open("weather_log.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print(timestamp);
    dataFile.print(", ");
    dataFile.print(temperature);
    dataFile.print(", ");
    dataFile.print(humidity);
    dataFile.print(", ");
    dataFile.println(pressure);
    dataFile.close();
  } else {
    Serial.println("Failed to open weather log file.");
  }

  delay(60000);  // Log data every minute
}

This code is designed to run on the Arduino Nano and performs the following functions:

  • Initializes the DHT22, BMP280, RTC, and SD card module.
  • Reads temperature, humidity, and pressure data.
  • Logs the data to an SD card with a timestamp from the RTC.
  • Handles sensor initialization failures by halting execution.
  • Handles failed readings by skipping the logging iteration.
  • Logs data every minute.