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

Solar-Powered Arduino Weather Station with Data Logging

View and Edit Project In Cirkit DesignerImage 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

BMP280

DHT22

DS3231 RTC

SD Card Module

OLED 1.3" Display

Lithium-ion Battery 10000mAh

Charge Controller

Solar Panel

Wiring Details

Arduino Nano

BMP280

DHT22

DS3231 RTC

SD Card Module

Lithium-ion Battery 10000mAh

Charge Controller

Solar Panel

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: