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.
GND
connected to common groundD2
connected to DHT22 data pinD10
connected to SD card module CS pinD11/MOSI
connected to SD card module MOSI pinD12/MISO
connected to SD card module MISO pinD13/SCK
connected to SD card module SCK pinVIN
connected to the battery output via the charge controller5V
connected to BMP280 VCC, DS3231 RTC VCC, SD card module +5V, and DHT22 VCCA4
connected to BMP280 SDA and DS3231 RTC SDAA5
connected to BMP280 SCL and DS3231 RTC SCLGND
connected to common groundVCC
connected to 5V from Arduino NanoSDA
connected to A4 on Arduino NanoSCL
connected to A5 on Arduino NanoGND
connected to common groundVCC
connected to 5V from Arduino NanoDAT
connected to D2 on Arduino NanoGND
connected to common groundVCC
connected to 5V from Arduino NanoSCL
connected to A5 on Arduino NanoSDA
connected to A4 on Arduino NanoGND
connected to common ground+3.3V
(not connected in this configuration)+5V
connected to 5V from Arduino NanoCS
connected to D10 on Arduino NanoMOSI
connected to D11/MOSI on Arduino NanoSCK
connected to D13/SCK on Arduino NanoMISO
connected to D12/MISO on Arduino Nano11.1V
connected to BAT on the charge controller and VIN on Arduino NanoGND
connected to common groundGND
connected to common ground and solar panel negative terminalBAT
connected to the lithium-ion battery 11.1V terminalVin
connected to the solar panel positive terminal+
connected to Vin on the charge controller-
connected to GND on the charge controller#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: