Introduction: Solar Power Diverter

About: Research Chemist with an electronics hobby.

If you live in a country with a big difference between the electricity buy and sell rate, then your solar setup will benefit from either battery storage or a solar diverter. The latter device "diverts" power from the solar panels to a dump load, usually a hot water cylinder (HWC). It works by rapidly switching the HWC element with a microprocessor controlled TRIAC. This works because the smart meter has “play”. A good analogy might be to imagine the steering wheel of your car which also has a bit of "play" in that tiny movements left and right don’t change the direction of the car. In a smart meter, the play is usually 1/1000 of a kWh, or 3600 Joules. Any electricity movement in that 3600 Joule window will not be registered as electricity passing between your house and the grid by your smart meter. 

This project is an adaptation of Robin Emley’s open source project -> https://www.mk2pvrouter.co.uk/ where I’ve added an optional ESP32 (Devkit V4) to handle energy monitoring and internet connectivity. The arduino nano diverter, and esp32 work independently, so the system also works without the ESP32. Everything's plug and play, so you can simply upload the code and get it going. I recommend reading Emley's’ above-mentioned website, and https://openenergymonitor.org/ which both have detailed theory and background regarding the operation, ie. digital filtering, integer math etc.

Whereas Emley’s project uses a naked Atmel 320P chip with an add-on display, I’ve opted to use the inexpensive Arduino Nano which has a lot of components already integrated. I've replaced the display with two LEDs, one lights when the TRIAC's off, and the other when it's on. This very simple setup shows you exactly what's going on with the TRIAC and the flashing frequency is diagnostic for problem-solving. You may be wondering what's the point of the ESP32? Who cares about monitoring? The problem is that having a solar diverter guarantees that the HWC can only switch on if the current clamp detects power leaving your house, and therefore on dark cloudy days your HWC will simply go cold because the TRIAC can't switch on.   You can fix that by adding a manual boost button, but manual intervention is undesirable. What you really want is some additional functionality to sum up the daily HWC on-time and automatically calculate the required boost to be delivered at night. Maybe even boosting at a specific time when electricity is less expensive. You might even want to change the boost duration depending on whether it’s winter or summer. That's exactly what the ESP32 does here. As a bonus, you can even remotely monitor and control the device through the Blynk app (screenshot shown above).

This unit has been tried and tested by me for several years. It's saved me piles of money. It works great and requires almost no maintenance (1 TRIAC replaced in 3 years). I'd like to share it with the community.

Supplies

Obtain the parts listed in list.csv. Difficult to find parts might include the transformer (VTX-120-4206-406) which I got from ebay, and the 3.5 mm stereo plug (used for plugging in the current transformer). I found the stereo plug from Tayda Electronics (see photo). I managed to get 5 inexpensive TRIACS on ebay. I'm not sure if they were fakes, but one TRIAC lasted for about three years, constantly switching a 2kW load about quarter of a million times a day! Download the solar_project.zip file from here and upload to JLCPCB. (If you live in New Zealand, then send me a message and I can post you a board.)

Step 1: Assembly

Solder in all the components. You'll want to check the voltages. Solder a 240 V line to the transformer, making sure to place some electrical tape to the back so you don't electrocute yourself. Measure the voltages at the test points on the board and make sure that you've got 5 V, and 2.5 V. Next check the voltage divider that's used to send signals from the Nano to the ESP32. Write a quick Arduino sketch to switch digital pin 8 HIGH on the Nano. Plug the Nano into the board and make sure that digital pin 32 on the ESP32 is above 2.80 V (threshold for on) and below 3.30 V (max voltage for the ESP32). If all that checks out then your board is ready to go. You may be wondering why the transformer isn't also used to power the ESP32. The reason is because the ESP32 can draw high instantaneous currents which can mess up the mains voltage measurements. Therefore, you'll need to find an old iPhone usb power plug or similar to power the esp32.

Step 2: Test Voltage and Current Sampling

Using the Arduino IDE, install this slightly modified version of Robin Emley's Raw Samples code to the Nano. Leave out the ESP32 out for now. Carefully remove the outer sheath from an old power cord of a heater or toaster, etc. so that you can clamp the YHDC SCT-013 current transformer (CT) to the phase or neutral lines. Ideally, you want a reasonable load 1kW or more so that you can at least see the current waveform move off the baseline. What you're looking for here is to see the voltage and current waveforms - that's all. Notice that depending on which orientation you clamp the current transformer to the wire affects whether the current is in phase, or out of phase with the voltage. That doesn't matter here, but later when you clamp the CT around the main line near your switchboard it needs to be in phase with voltage for the device to work correctly (you just do that later by trial and error).

Step 3: Install Firmware

Using the Arduino IDE, install the firmware for both the Nano ( here), and for the ESP32 ( here). Don't forget to modify the #defines in the esp32 code to add your own WIFI and Blynk credentials. Look carefully at the include directives as you may need to install some libraries to get the code working. You'll of course need to sign up for a free Blynk account and configure each of the virtual pins from the Blynk website. Since making this project, Blynk has halved the number of datastreams per template from 10 to 5, so you'll have to pick and choose which datastreams are important to you. Below is a list of the Virtual Pins and their corresponding names that are incorporated into the above c++ code.


Virtual Pin, Name, data_type, min_value, max_value


V1, Hour Trigger, integer, 0 23

V2, Minute Trigger, integer, 0, 59

V3, Summer Required On Time, Double, 0, 10

V4, Winter Required On Time, Double, 0, 10

V5, Uptime, String,

V6, Boost Active, bool, 0, 1

V8 Last Successful Autocharge, string

V10, Triac Cycles Today, integer, 0, 1e8

V11 Calculated Boost, double, 0, 12


Step 4: Make the TRIAC Controller

Using some good stiff perfboard to mount the TRIAC and MOC3041. Follow the circuit diagram for the MOC3041 and make sure you use thick copper wire to carry the 10 Amp 240 V hotline switched load. You don't really need the snubber, but if you decide to include it, then make sure you use a decent capacitor like a 1600-650V WIMA FKP 1.

Step 5: Assemble the Device Into a Housing

Mount everything to an earthed metal faceplate. Ideally you'll end up with faceplate requiring only five attachments from the other side, ie. the 3.5 mm plug from the CT, phase, neutral and earth lines, and lastly the neutral line side of the HWC (see above photo). The TRIAC gets quite hot, so make sure you have a good heat sink attached directly to the TRIAC. An old CPU cooling block without the fan works well. I used a tiny bit of thermal paste too. Add a 3-position double pole double throw (DPDT) 15A switch. Make sure it's got 6 legs so that you can bypass the TRIAC to the HWC, and switch off the diverter at the same time. The whole device needs to be mounted right next to your switchboard because the CT needs to be clamped around a main line feeding your house. Make sure that you have either or both a dedicated HWC switch on the fusebox, or the HWC fuse in series with, and placed before your live phase line that feeds into your diverter box. If you're not 100% sure what you're doing, then don't do it. Even if you're 100% sure, then be careful, and definitely get an electrician to verify that everything is installed safely, and it's in accordance with local regulations. After you install everything and switch it on and fingers crossed, you'll see rapid alternating flashing of the LEDs (assuming 1; it's a sunny day, 2; the HWC thermostat hasn't switched off the element already, and 3; the CT is oriented correctly). That's it. Super simple! Enjoy paying less to the electricity company.