SolarPV WiFi (4) 20 amp Fused Disconnect with 8 channel volt/temp monitor


I sure need help with programming!
-just the MCP3008 part :wink:
Get a MCP3008 (SPI-bus A/D converter)
talking with an Esp12-e (Esp8266),
-and get the 8 A/D channel data reported to Cayenne.

This PC board is an integral part of a Solar Array Collector, called a
DC Fused Disconnect.
I’m adding Wifi control and 8 channel voltage & temperature monitoring

It is intended to be mounted inside an 8" length of 3" PVC pipe,
and properly mounted on a
QO rated 120/240v 100amp Outdoor Load Center

This PC board provides the voltage regulator and Esp12-e,
(4) Panasonic 277vac/16amp contactor relays/drivers,
MCP3008 A/D Converter and 6 voltage dividers.

Analog inputs 0 and 1 applications do not require a voltage divider.
Analog inputs 2 thru 7 are /50, V(max)= +165v
165vdc/50= 3v3, or 1024 on the 10-bit ADC
Nominal PV circuit voltage is +90v (on my system).

Each of the 4 relays has it’s own voltage monitoring channel.
GPIO 4 (out) controls K1, reports to analog ch.7(/50)
GPIO 5 (out) controls K2, reports to analog ch.6 (/50)
GPIO 12 (out) controls K3, reports to analog ch.5 (/50)
GPIO 13 (out) controls K4, reports to analog ch.4 (/50)
Vin +12 monitoring, reports to analog ch.3 (/50)
DC Mains monitoring reports to analog ch.2 (/50)
+3v3 monitoring, reports to analog ch.1 (direct)
TMP36 temperature, reports to analog ch.0 (direct)

GPIO4 drives the base of Q1 through 5k6 R1, then drives K1,
GPIO5 drives the base of Q2 through 5k6 R2, then drives K2,
GPIO12 drives the base of Q3 through 5k6 R3, then drives K3,
GPIO13 drives the base of Q4 through 5k6 R4, then drives K4.

(4) 1N4001 diodes (left of relays) protect each 2N2222 from relay coil inductive flyback. Pay attention to polarity!

The voltage divider consists of (6) pairs of resistors. One end of the 4k3 resistor goes to ground. One end of the 220k resistor goes to the high voltage signal. The ADC input results from tying the 220k resistor to the 4k3 resistor.

I set my divider impedance at 224.3K,
to limit power dissipation < 1/8th watt @ 165Vdc
4k3 to ground,
220k to high volt input.
This is a divide by 52.16279.
Multiply volt reading by 52.16279 for correct voltage.

Mounting the WiFi radio inside the metal SquareD box would kill the WiFi.
Just…drop everything into a 3" PVC pipe…
Use PVC 3" to 1" reducer at 1 end of the 3", cap other end.
and use a 1" PVC threaded adapter on the bottom of the SquareD box,
using an existing 1" knockout hole on the SquareD.
Raintinght! Meets NEC and UBC code specs.:slight_smile:
No silicone sealant required.
Total of 10 wires-
(8) #10 wires (I like gauging up when V(drop) is critical)
(1) from each of 4 PV strings coming in,
(1) from each of 4 PV strings going out.
…plus, of course, our +12Vdc power in, (2) #16 red/black pair.
1" sch.120 PVC works according to NEC conduit fill limits. :wink:

Voltage Divider Calculations
Let’s design +165Vdc to be our V(max).
165Vdc input should generate <3.3Vdc after the divider.
165Vdc / 3.3Vdc = 50
That is “divide by 50”.

Power through divider
I’ve decided our maximum power through the divider is .125 watt.
We need to find our divider resistance.
V²/P= (the resistance we need)

.125 watt P(max)

217800 ohms.
A non-standard value.
Let’s go up to the next standard value, 220k ohms.

The other resistor is 1/50th the value.
220k ohms / 50 = 4.4k ohms.
A non-standard value.
Let’s drop to the next standard value- 4.3k ohms.

Using 4k3 + 220k 1/8 watt resistors:
V²/R = power (Watts)

224300 ohms (220k + 4.3k)

0.12137761925991975033437360677664 Watt

Current through divider, 165Vdc IN
V/R = current (Amps)
224300 ohms

.00073562193490860454748105216228266 amp

Voltage drop, 165Vdc IN (4k3 grounded resistor)
V= I * R
I= .00073562193490860454748105216228266 amp
4300 ohms

3.163174320106999554168524297804 volts

Divisor / Multiplier
Volts In / Volts Out = multiplier
165 Vdc
3.163174320106999554168524297804 Vdc

( x 52.162790697674418604651162790886)

Digi-Key Parts List < click $29

Esp12-e < click $4.00

##PC Board $9 (includes US shipping)

Monitoring DC voltage on off grid solar power supply

Try this:

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <SPI.h>
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "your token";
// Your network name and password.
char ssid[] = "your ssid";
char password[] = "your password";

#define CS_PIN 15 // Use 10 when compiling for Arduino

void setup() {
  pinMode(CS_PIN, OUTPUT);
  Cayenne.begin(token, ssid, password);

  SPI.setFrequency(100000); // 1 MHz -- remove line when running on Arduino UNO
  digitalWrite(CS_PIN, HIGH);

void loop()

 void adcRead(int channel) {
  if ((channel > 7) || (channel < 0)) {
       return -1;

  digitalWrite(CS_PIN, LOW);
  uint8_t r1 = SPI.transfer((channel + 8) << 4);
  uint8_t r2 = SPI.transfer(0);
  digitalWrite(CS_PIN, HIGH);

  return ((r1 & 3) << 8) + r2;


@andrewawise Hmmm.Nope. Compiler threw exceptions.

Here’s the Python code I used on RasPi3 to return the correct voltages.
This is a calibrated +165Vdc (MAX!) voltage divider,
using 220k ohm / 4k3 ohm .125 watt resistors

import spidev   
import time
spi = spidev.SpiDev(),1)

def Read(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  volts = data * 0.1681027412109375
  return volts

while True:,0)
  z1 = Read(0)
  z2 = Read(1)
  z3 = Read(2)
  z4 = Read(3)
  z5 = Read(4)
  z6 = Read(5)
  z7 = Read(6)
  z8 = Read(7),1)