by Floris Wouterlood – Leiden – the Netherlands – May 5, 2017
This paper describes the construction of an Arduino-based logging device that is connected to a digital kWh meter. This kWh meter records the power produced by my grid-connected solar photovoltaic panels. Every time that 0.5 Wh of solar electricity has passed through the meter a led on the meter flashes and the meter’s SO port shorts for a few milliseconds. This event can be registered by an Arduino microcontroller board and, through a logging shield, with intervals written to a datafile on a SD memory card. In the sketch sampling intervals and writing intervals to the SD card can be programmed. The data file is in comma delimited format that can easily be imported in a spreadsheet.
The production of the solar photovoltaic panels that decorate the roof of my home is registered with two meters. First, an antique meter with a spinning disc and a mechanical counter tallies the solar kilowatt hours. Lined up with this analog meter is a modern digital kWh meter equipped with a led that flashes every time that a half watt-hour of power has passed the meter (2,000 pulses/kWh). Simultaneously with the flashing led an optocoupled device inside the digital meter is activated for approximately 90 milliseconds. This device acts as a switch: two contacts on the meter (the SO port, contacts numbered 20 and 21) are shorted. If a voltage is placed over the SO port it will change every time the led flashes. An Arduino can supply such a voltage, can be programmed to notice rises or drops in voltage, and it can count. In other words: an Arduino microcontroller board is perfectly capable to do the job of logging pulses.The number of pulses per time unit can be used as an indication for power and for production, and with a spreadsheet program graphs can be produced.
Figure 1: Scheme of my solar panels, the grid inverter and the associated AC and DC wiring. Production registered by the digital solar kWh meter is recorded by an Arduino microcontroller – SD shield.
In an earlier project1 I constructed an optocoupled device that mimics a working SO port of a digital kWh meter. This was a necessary predecessor project because working on the current project required an uninterrupted ‘supply’ of pulses in rapid succession, something that with solar panels in the climate in Western Europe is not always available, and certainly not at night.
For a safe workflow and to prevent frying the microcontroller a SO port on any kWh meter should electrically be completely isolated from the main 230V AC power current. The manufacturer of the kWh meter bought by me guarantees this aspect. The SO port of my solar kWh meter is certified to operate with a DC current with voltages between 5 and 27V. As a pin set ‘HIGH’ on an Arduino provides 5V DC I reckoned that my digital kWh meter could probably be Arduino compatible. In addition to the microcontroller platform necessary for counting pulses I needed a timing device because an Arduino does not support multithreading. Accurate timing can be provided by adding a RTC (real time clock). Finally we need to record the numbers of pulses per time unit over a daytime cycle. Among the several ways that exist to accomplish this I choose for the solution to write data to a file on a SD card. On the market are Arduino compatible shields that feature both a RTC and a SD card slot.
Solar panels, inverter and digital kWh meter
Modern solar grid inverters are equipped with web interfaces or with network connectivity. My solar panels are rather old: they were installed more than 15 years ago when web interfaces were uncommon. Most of my solar panels are equipped with their own microinverter whose AC connector plugs directly into a wall outlet. These microinverters were bought from different manufacturers. Together the inverters feed as an ‘inverter bank’ into one AC wall outlet that is directly connected with my home’s main electricity power meter (a designated 230V AC electrical ‘PV wiring group’ – separated from the other electrical wiring groups that supply power to electricity consuming apparatus, as required by regulations in The Netherlands).
The ‘solar’ analog and digital kWh meters connect the bank of microinverters and the ‘PV wiring group’ AC wall outlet.
Figure 1 shows schematically the connections between solar panels, inverter, wall outlet and Arduino. Only one inverter is drawn in the figure, and the analog kWh meter is omitted.
Electronics and supplies needed
(apart from the digital KWh meter): Arduino Uno microcontroller board, SD shield with real time clock, 30×70 mm soldering board, 3x 220Ω resistors, 1x 10k Ω resistor, red led, green led, yellow led, wires, SD card (FAT32 formatted).
If we connect the 5V pin of the Arduino with the SO port of the kWh meter and complete the circuit by connecting the other contact on the SO port with, for instance, pin 2 on the Arduino, then the voltage on the Arduino’s pin 2 will shortly rise from 0V to 5V as soon as the kWh meter pulses. Pin 2 is not a randomly selected pin. Pins 2 and 3 on an Arduino Uno can be programmed as interrupt pins, that is if an event happens at these pins the microprocessor will be informed of the event and do a calculation or perform an action in response to this interrupt. In case of pulse detection the proper action would be to increase the value of a variable called ‘counter’.
In order to detect a proper voltage rise a 10 k Ω pull down resistor is necessary between the detection wire and GND.
As the digital kWh meter is mounted in its own isolated, closed cabinet far away from the Arduino its flashing led is not easily visible. To have a cue that an event (led on kWh meter flashes) is happening it is handy to have a led on board of the logging device that echos the led flashing on the digital kWh meter. Other activity such as sampling, writing to file, and error situations, should be reported by led activity as well. Rather than on the logging shield these ‘activity leds’ are mounted on an interface board that I designed (scheme in figure 2; figure 3 shows the actual board).
Figure 2. Design of the interface between the SO port of the digital kWh meter and the Arduino Uno microcontroller board. 230V AC is indicated in red. Warning! Because solar panel inverters produce 230V AC while the Arduino is a 3.3-5V DC configuration, one needs to be extra careful to be sure that the DC circuit is completely and safely isolated from the AC power circuit. This is achieved via the construction and mounting of the digital kWh meter. One should be aware of working with 230V AC and always be very cautious. In my situation the digital kWh meter is mounted in a separate isolated cabinet next to the solar inverter bank, 10 meters away from the Arduino logging device.
Figure 3: The actual interface between the SO port on the digital kWh meter and the Uno microcontroller board. The soldering board contains connectors, resistors and leds as schematized in the right part of the figure.
For this purpose I soldered the following components on a small (30×70 mm) soldering board (figure 2, left panel of figure 3): red ‘pulse echo’ led, yellow led (‘flush’ and ‘error’) and a green ‘write sample to file’ led. On the board is also a female pin header that connects with the SO port of the digital kWh meter. The wire connecting the SO port on the digital kWh meter and the logging unit has a length of approximately 10 meters.
Figure 4: SO interface and SD logger mounted on the Arduino Uno, ready for action..
The sketch does the following:
• prepares the Arduino;
• calls a time stamp;
• reports every pulse by blinking the red ‘pulse echo’ led on the interface board;
• stores the number of pulses recorded in 5-minute intervals;
• writes data comma delimited to file on the SD memory card every 10 minutes;
• blinks the green led to report a write-to-SD card operation;
• blinks the yellow led to report a flush operation or an error situation.
The SD logger was tested first with the optocoupled pulse generator described in a previous paper1. Here, in the graphical output of the logging files a nice linear relationship was seen between logging time and counts. Next we undertook a series of logging sessions with the real solar PV kWh meter. Logging occurred in in the fourth week of April and the first week of May. Logging initially started at 06:00 AM and stopped at 9:00 PM (21:00). During these 15 hours, 180 sample points were recorded and the corresponding number of pulses written to the logging file on the SD card (CSV format) One day worth of logging data requires 14 kB on the SD card. On the current 4 GB SD memory card there is space enough to save more than 900 years of logging (!) After any logging period the SD memory card was transferred to a card slot in a laptop computer and the CSV file imported in a spreadsheet in Open Office (Excel may do as well). A typical graphical output is shown in Figure 5. That day (April 28, 2017) was a sunny day with partial cloud coverage, outside temperature 10 degrees Celsius and a steady breeze. Solar panels produce under these circumstances sizeable amounts of electricity. Day production of the logged panels on the 28th of April, 2017 was 6.3 kWh for 2.330 Wp (specific production that day of 2.7 Wh/Wp).
Figure 5: Results of the logging session on 28 April, 2017: A typical Dutch spring day: lots of sunshine on an otherwise breezy and partially cloudy sky. Solar electricity was produced between 08:00 and 20:00. The Y-axis represents numbers of pulses counted per 5 minute interval.
The current project exploits the ‘pulse’ feature of the digital kWh meter that registers electricity produced by the grid inverters of my solar panels. Actually this feature is not a pulse of real current. A ‘pulse’ on the S0 port of the kWh meter consists of the brief shorting of contacts 20 and 21 at the very moment that the indicator led flashes. The Arduino supplies 5V to the S0 port and detects on pin 2 that the voltage briefly spikes from 0V to 5V when the S0 port shorts. A pulse therefore could better be described as a ‘voltage event’
One question is: how reliable is pulse counting of a solar PV kWh meter with an Arduino? Is every pulse indeed counted and are there ‘ghost counts’ caused by line noise or jitter? What is the quality of the pulse (how fast goes the voltage on the S0 port from 5V to 0V and back? Does the voltage go all the way to 5V or is it an irregular or parhaps asymmetrical shallow hop?). How stable is the 5V power supply of the Arduino? An oscilloscope would be handy at this point. One problem that occurs with pulse counting is ‘debouncing’, that is that a pulse may be counted twice because the voltage ‘pulse’ has a rising component and a dropping component. The sketch instructs the Arduino to record only voltage rises at pin 2, and a subroutine then checks any voltage event on the interrupt pin with a set of criteria in order to validate that voltage event as one, ‘true’ pulse.
A second item is accuracy and calibration. We are dealing here with cheap consumer electronics and not with carefullly selected, accurate and professional equipment.
To get an insight into this matter I took another logging system: Plugwise www.plugwise.com). Plugwise is an energy consumption logging system that includes small connectors intermediate between the wall outlet and the connecting plug of the electronic apparatus whose energy supply is going to be logged. The connectors send information via a ZigBee wireless mesh network to a receiver that sticks into an usb port of a computer. I use the Plugwise system in my home to monitor electricity consumption during the day, month or year, of a score of electric apparatus (for example electricity consumption of the floor heating circulation pump). Plugwise fortunately registers electrical energy flowing in any direction and for that matter can be used to record electricity generated by solar photovoltaic panels. The software however produces only output in terms of kWh consumed or produced per hour. An advantage is that data can be exported in CSV format. The manufacturer does not reveal what happens inside the plugs, that is how energy that passes the plugs is measured. In this sense the Plugwise is for its user as uncalibrated and hence as reliable as an Arduino.
To do a proper comparison I placed a Plugwise connector during several logging sessions in between the solar kWh meter and the wall outlet. The pulse counts saved in the Arduino logging files (remember: one pulse represents 0.0005 kWh) had to be recalculated with my spreadsheet program into production in kWh per hour to do a proper comparison with the data generated by Plugwise.
Figure 6: Spreadsheet. Columns A through F: data from a logging session on 4 May, 2017: A typical Dutch spring day: lots of sunshine on an otherwise breezy day with some periods that clouds covered the sun. Columns J,K and L (in the outlined box) are copy-pasted from the worksheet wherein I summed the pulses by the Arduino logger for each hour and calculated the produced ‘solar’ kWhs. A graphical comparison of Arduino and Plugwise registrations is presented in figure 6.
In the comparison of the spreadsheet data of Arduino logged pulses and the Plugwise registration (figures 6 and 7) it appears that differences exist between Plugwise data and Arduino SD logging data. The Plugwise registered over 4th May 7,0 kWh generated while the Arduino SD logger counted 14,075 pulses which is the equivalent of 7.036 kWh. The difference between the totals of the Arduino output and Plugwise registration is almost negligible. The biggest hourly difference was seen between 16:00 and 17:00 (time point 17:00) where the Arduino logged 0.2360 kWh where the Plugwise registered 0.2684 kWh (30 Wh, or 12% difference). Relative to each other these values may look big, but at a power output of the system of 750W around 17:00, an amount of 30 Wh is in the order of magnitude of 2 minutes of solar power production. As figure 5 shows the pulses were written by the Arduino to SD card three minutes 36 seconds after the full hour which may largely be responsible for the variation. There is no data available of the accuracy (calibration? ) of the Plugwise system. Exact quantitative comparison is therefore difficult.
Figure 7: Comparison of data generated by the Arduino SD logger and by the Plugwise monitoring system connected in series with the solar kWh meter. Logging session 4 May 2017.
In conclusion: I consider the present project successful because I constructed an interface between the S0 port on my solar production kWh meter and an Arduino Uno / RTC-SD shield. The result is a logging system that is capable of counting pulses of my digital solar kWh meter and to log the production to files on a SD card. The next step is to further improve the sketch and to connect the Arduino via a network shield to the home network. A parallel project is to connect the logging Arduino to a slave Arduino with a LCD display to allow real time display of interesting ‘solar’ data.
1. Arduino ‘pulse’ generator using a photo-transistor optocoupler
Floris Wouterlood – April 10, 2016