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
GNDconnected to common groundD2connected to DHT22 data pinD10connected to SD card module CS pinD11/MOSIconnected to SD card module MOSI pinD12/MISOconnected to SD card module MISO pinD13/SCKconnected to SD card module SCK pinVINconnected to the battery output via the charge controller5Vconnected to BMP280 VCC, DS3231 RTC VCC, SD card module +5V, and DHT22 VCCA4connected to BMP280 SDA and DS3231 RTC SDAA5connected to BMP280 SCL and DS3231 RTC SCL
BMP280
GNDconnected to common groundVCCconnected to 5V from Arduino NanoSDAconnected to A4 on Arduino NanoSCLconnected to A5 on Arduino Nano
DHT22
GNDconnected to common groundVCCconnected to 5V from Arduino NanoDATconnected to D2 on Arduino Nano
DS3231 RTC
GNDconnected to common groundVCCconnected to 5V from Arduino NanoSCLconnected to A5 on Arduino NanoSDAconnected to A4 on Arduino Nano
SD Card Module
GNDconnected to common ground+3.3V(not connected in this configuration)+5Vconnected to 5V from Arduino NanoCSconnected to D10 on Arduino NanoMOSIconnected to D11/MOSI on Arduino NanoSCKconnected to D13/SCK on Arduino NanoMISOconnected to D12/MISO on Arduino Nano
Lithium-ion Battery 10000mAh
11.1Vconnected to BAT on the charge controller and VIN on Arduino NanoGNDconnected to common ground
Charge Controller
GNDconnected to common ground and solar panel negative terminalBATconnected to the lithium-ion battery 11.1V terminalVinconnected 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.
