Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsSolar panels rarely give their rated power. The INA219 in the panel lead measures current and power, and the divider reads the 12 V battery. A row every minute shows the morning ramp, the noon peak, cloudy dips and the battery charging through the day. Total it up in a spreadsheet to get the daily watt-hours.
A 12 V battery can deliver hundreds of amps. Fuse every lead at the battery and insulate all joints.
Tick anything you already have and the total updates.
Measures voltage, current and power of a DC circuit up to 26 V and 3.2 A through a tiny shunt resistor, and reports them over I²C.
Two resistors scale the battery voltage down by 11 so an analog pin can measure up to about 50 V safely.
Temperature-compensated real-time clock (±2 minutes a year) with a coin-cell backup, so the time survives power cuts.
Stores readings on a microSD card as a CSV file you can open in Excel or Google Sheets.
Follow the colours: red is power, dark grey is ground, blue is a signal.
Panel + goes to INA219 VIN+, VIN− goes to the charge controller panel input. The divider reads the battery terminals through a 500 mA fuse. Power the Mega from USB or through a buck converter set to 5 V.
mega_solar_energy_logger.inoVerify & upload in Electrolark// Solar energy logger on an Arduino Mega
// Geekobot project library · board: Arduino Mega 2560
// Wiring diagram, parts list and build steps: Geekobot project page "mega-solar-energy-logger"
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <RTClib.h>
#include <SPI.h>
#include <SD.h>
// ---- pins ----
const uint8_t VBAT_PIN = A0;
const uint8_t SD_CS = 53;
const int ADC_MAX = 1023; // 10-bit analog input
const float VREF = 5.0f;
Adafruit_INA219 ina;
RTC_DS3231 rtc;
// ---- latest readings ----
float busV = 0;
float currentMa = 0;
float powerMw = 0;
float batteryV = 0;
const unsigned long LOG_EVERY_MS = 60000UL; // one row per minute
unsigned long lastLog = 0;
bool cardOk = false;
float readBatteryV() { return analogRead(VBAT_PIN) * VREF / ADC_MAX * 11.0f; } // 100 kΩ : 10 kΩ divider = ÷11
void writeRow() {
File f = SD.open("LOG.CSV", FILE_WRITE);
if (!f) { Serial.println(F("Write failed")); return; }
DateTime t = rtc.now();
char stamp[20];
snprintf(stamp, sizeof(stamp), "%04d-%02d-%02d,%02d:%02d:%02d", t.year(), t.month(), t.day(), t.hour(), t.minute(), t.second());
f.print(stamp);
f.print(',');
f.print(busV, 2);
f.print(',');
f.print(currentMa, 0);
f.print(',');
f.print(powerMw, 0);
f.print(',');
f.print(batteryV, 2);
f.println();
f.close();
}
void setup() {
Serial.begin(115200);
if (!ina.begin()) Serial.println(F("INA219 not found"));
if (!rtc.begin()) Serial.println(F("RTC not found"));
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from the upload time
cardOk = SD.begin(SD_CS);
Serial.println(cardOk ? F("SD card ready") : F("SD card not found"));
if (cardOk && !SD.exists("LOG.CSV")) {
File f = SD.open("LOG.CSV", FILE_WRITE);
if (f) { f.println(F("date,time,Voltage(V),Current(mA),Power(mW),Battery(V)")); f.close(); }
}
}
void loop() {
if (millis() - lastLog < LOG_EVERY_MS && lastLog != 0) return;
lastLog = millis();
busV = ina.getBusVoltage_V();
currentMa = ina.getCurrent_mA();
powerMw = ina.getPower_mW();
batteryV = readBatteryV();
Serial.print(F("Voltage="));
Serial.print(busV, 2);
Serial.print(F("V"));
Serial.print(F(", Current="));
Serial.print(currentMa, 0);
Serial.print(F("mA"));
Serial.print(F(", Power="));
Serial.print(powerMw, 0);
Serial.print(F("mW"));
Serial.print(F(", Battery="));
Serial.print(batteryV, 2);
Serial.print(F("V"));
Serial.println();
if (cardOk) writeRow();
}
The sketch above runs here on a simulated Arduino Mega. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
Check SDA and SCL. An I²C scanner should show 0x40.
The + wire must pass through VIN+ to VIN−; measuring on the GND side does not work.
Measure the real resistor values and change 11.0 to (R1 + R2) / R2.
The coin cell is flat or missing. Some modules need the charging resistor removed when using a CR2032.
Check the card is FAT32, fully inserted, and CS is on the pin in the sketch.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Use a 5 V USB phone charger or a power bank into the board's USB port.
8 parts: MEGA 2560 R3 Dev Board with ATmega2560 & CH340G, INA219 Current and Power Monitor Module, Resistor Assortment Kit (30 Values), DS3231 Precision RTC Module with EEPROM, DFRobot Fermion MicroSD Card Module – SPI, microSD Memory Card Class 10 (16GB), Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2–3 hours. The build on this page has 10 steps.
No. This page has the complete, tested code (mega_solar_energy_logger.ino). Install these libraries first: Adafruit INA219, RTClib and SD.
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹2,354 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Real-time clocks and backup batteries; SPI devices and CSV logging; Shunt resistors, current and power; Voltage dividers and ADC scaling.
A 12 V battery can deliver hundreds of amps. Fuse every lead at the battery and insulate all joints.
Ideas that reuse this build: Solar charge logger and Solar panel power meter. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.
Voltage=12.00V, Current=451mA, Power=5374mW, Battery=16.56V Voltage=11.99V, Current=448mA, Power=5389mW, Battery=16.51V Voltage=12.02V, Current=448mA, Power=5396mW, Battery=16.51V
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.