Logging solar photovoltaic output with Arduino

Using a kilowatt meter with S0 contacts to log Voltage pulses via MQTT.

I want to build a power plug that only works when the solar panels on the roof are generating electricity, useful for charging a phone or my e-bike. I can leave the bike plugged in and it would only charge when there is a surplus of electricity. When it’s cloudy the power should shut off until the PV installation is back, producing clean electricity again. The first step for this long-term goal is to know if the PV panels are generating electricity. My 10+-year-old solar installation and the inverter, a Diehl AKO PLATINUM 2100 S, did not come with nice graphs to monitor the solar output. The inverter does have an EIA485 network port that can be used to attach a monitor device, but it’s so old even the website is no longer available.

Luckily I do have a single-phase digital kW meter in the fuse box, as is often the case in Belgium for our “groenestroomcertificaten” (link in Dutch). The kilowatt meter flashes every time a watt-hour of power passes the meter. This sums up to 1.000 pulses per kWh. The meter also has two S0 pins which act as a switch every time the LED flashes. The Arduino can detect these voltage changes and count the pulses, and thus learn the generated power from the solar installation. I used an old Arduino Ethernet, a 10kΩ resistor, some wires—all found in my “big ol’ pile of electronics”—and loaded the sketch on the Arduino. The sketch waits for an interrupt (= Voltage change) on pin 2 and fires an MQTT message to the broker when it when it does.

Wires connected to the DIN wattmeter Wiring diagram for the Arduino and S0 pins on the meter

WARNING! The Arduino and S0 pins are low voltage but a fuse box also contains high voltage wires. These can cause injury or even death. Be careful when handling high voltages!

I can now subscribe, using MQTT Explorer for example, to the MQTT topic configured in the sketch and count the pulses. A recently received MQTT message means the solar panels are working hard and doing their job.

What’s next?

The Arduino Ethernet needs a power and ethernet cable and my proof-of-concept is a bit messy. I am thinking to port the sketch to an ESP8266 using Wi-Fi and a battery to see if I can clean up the wiring a bit. I also need a local MQTT broker and some database to store the logs. Maybe a Grafana dashboard would be nice as well?

Resources

This post is open source. Did you spot a mistake? Ideas for improvements? Contribute to this post via Github. Thank you!