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

Battery-Powered Weather Station with Arduino Nano and SD Card Logging

View and Edit Project In Cirkit DesignerImage of Battery-Powered Weather Station with Arduino Nano and SD Card Logging

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions such as temperature, humidity, and atmospheric pressure. It utilizes various sensors and modules, including a DHT22 for temperature and humidity readings, a BMP280 for pressure measurements, and an SD card module for data logging. The Arduino Nano serves as the central microcontroller, coordinating the data collection and storage processes. The circuit is powered by a lithium-ion battery, which is charged via a solar panel and managed by a charge controller.


Component List

1. Arduino Nano

2. BMP280

3. Solar Panel

4. Charge Controller

5. SD Card Module

6. Lithium-ion Battery 10000mAh

7. DHT22

8. DS3231 RTC


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 documentation provides a comprehensive overview of the circuit, detailing each component, its purpose, wiring connections, and the code used for operation.