I sure need help with programming!
-just the MCP3008 part
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.

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.

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)
165Vdc²
27225
/
.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)
165Vdc²
27225
/
224300 ohms (220k + 4.3k)
0.12137761925991975033437360677664 Watt
Current through divider, 165Vdc IN
V/R = current (Amps)
165Vdc
/
224300 ohms
.00073562193490860454748105216228266 amp
Voltage drop, 165Vdc IN (4k3 grounded resistor)
V= I * R
I= .00073562193490860454748105216228266 amp
X
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)