My Project Rationale:
A 600 foot deep well provides water to my house. The well only produces 8 gallons/hour. Therefore I also have a 1700 gallon cistern to store the water before it is pumped into the house for use. There is a float valve that turns on the deep well pump when the cistern level drops to a certain level below full and turns off the deep well pump when it is full again. The pump is a 1hp 250VAC induction motor.
My project is to monitor the status of the cistern to make sure that it doesn't run dry. I thought that the easiest way to do this would be to monitor how often, and for how long, the deep well pump is running. I assumed that simply detecting a voltage applied to the motor would be a good indicator of this, so I proceeded to design a circuit for detecting a 250VAC signal and presenting to the Raspberry Pi as a GPIO logic level.
1. Safety: 2500-3500V galvanic isolation between motor circuit and RPi circuit.
2. Cool Operation: low power dissipation…
3. Simple, two-wire interface: GND and GPIO signal to the RPi. No power supply signal required.
4. Small size - it has to fit inside the well "pump-saver" box that is mounted on the garage wall, and it won't be the only circuit in the box.
Effect of Component Failures:
These circuits should be evaluated for failure effects to see what bad things happen when components fail. I did some investigating of how and why electronic components fail. Here's some of what I found:
 Failure mode data was taken from a combination of resistor manufacturer's recommendations, MIL-HDBK-978, "NASA Parts Application Handbook," 1991; MIL-HDBK-338, "Electronic Reliability Design Handbook," 1994; "Reliability Toolkit: Commercial Practices Edition," Reliability Analysis Center (RAC), 1998; and "Failure Mode, Effects, and Criticality Analysis (FMECA)," RAC, 1993.
Failure mode data was taken from a combination of MIL-HDBK-978, “NASA Parts Application Handbook”, 1991; MIL-HDBK-338, “Electronic Reliability Design Handbook”, 1994; “Reliability Toolkit: Commercial Practices Edition”, Reliability Analysis Center (RAC), 1998; and “Failure Mode, Effects, and Criticality Analysis (FMECA)”, RAC, 1993.
Capacitors normally fail with a short circuit. Film resistors most likely fail with an open circuit, but can fail just as often with a parameter change, and only fail shorted 5% of the time.
Only use components rated to withstand the electrical environment to which they are subjected. Design for Reliability guidelines suggest that resistors be derated to 60% of maximum operating limits for voltage and power dissipation. This was an eye-opener for me. This is serious stuff and a failure could cause a fire or other serious issue that places the occupants of the house in danger. It gives credence to the people who say "Don't play with the mains."
This is the circuit that I initially implemented:
Vishay has a handy data sheet that covers multiple general purpose transistor output optos - you can find it here. The data sheet specifies the transfer characteristics of the coupler with a forward current, IF, through the input LED @ 10mA. This is a problem. If the input resistors must generate 10mA with 125VAC across them then they will need to be rated for 2 Watts!
In order to make R1 and R2 larger the opto-isolator has to be operated at lower currents. I selected the 4N37 because its minimum Current Transfer Ratio (CTR) is 100%. There is not a load resistor in the circuit - it is provided by the RPi. The GPIO pull-up resistor is 50K minimum. Therefore the 4N37 must sink 3.3V/50k = 66uA max. And we'll increase that by 50% to make sure that the 4N37's output NPN is fully saturated (producing a low output voltage). So we now know that the output current is 100uA. The CTR of the 4N37 is estimated, using Figures 3 and 5 and iterating a bit, to find IF produces a CTR of about 0.15. (Operating...Read more »