2
\$\begingroup\$

I'd like to connect a bridge (full wave) rectifier to my Raspberry Pi (RPi), GPIO pin 22 (configured as an input). I have configured the rectifier such that it has a 120VAC input and 3VDC output (I used a voltage divider on the DC output). The circuit works fine. I'm able to power an LED from the 3VDC output. Now my question is, how do I connect this 3VDC output to the RPi? Do I just tie the grounds together (rectifier DC ground to RPi ground) and then connect the bridge rectified 3VDC to the RPi GPIO pin 22? I measured a 68V difference between the RPi ground and the bridge rectifier DC ground. I decided to hold off on connecting anything until I figured out why there is such a large voltage difference between the two grounds. Any help would be appreciated. BTW, the RPi is being powered by the same 120VAC source that is connected to the AC input of the bridge rectifier.

Here's the circuit I ended up implementing: 120VAC Detector Circuit

\$\endgroup\$
  • 2
    \$\begingroup\$ Is the rectifier output a floating ground? Could you share an image of what you have so far, a schematic or sketch helps a lot in understanding the problem statement. \$\endgroup\$ – Anindo Ghosh Mar 21 '13 at 7:36
  • \$\begingroup\$ I must say that what you are describing is very dangerous and risks blowing up the Pi. What on earth are you trying to achieve (what is the purpose of this circuit?) maybe we can suggest a safer way of doing it. \$\endgroup\$ – John U Mar 21 '13 at 14:05
  • \$\begingroup\$ Yes, floating ground. I was just experimenting :] Didn't blow up anything as I didn't connect it to the RPi. I realized I can just use an off-the-shelf 3VDC wall wart as an input to the Raspberry Pi. My goal is to measure if a 120VAC line is energized. \$\endgroup\$ – sizzle Mar 21 '13 at 14:16
  • \$\begingroup\$ In that case I'd suggest an opto-isolator rather than have two wall-warts fighting each other across the pins of the CPU. Almost every chip has some internal protection circuitry, feeding a different 3v supply into an IO pin can have unintended consequences and is not a very nice thing to do. Also, it's quite ugly. \$\endgroup\$ – John U Mar 21 '13 at 18:06
  • \$\begingroup\$ You could also just use a 120v relay, where the coil is connected to the 120vac source and the contacts connect one of the GPIO pins to (the Pi's own) ground or (the Pi's own) 3v3 line. It's basic but with the right relay should provide simple & robust isolation. \$\endgroup\$ – John U Mar 21 '13 at 18:12
0
\$\begingroup\$

The Raspberry Pi is generally powered from a 5V wall-wart type of DC power supply. The secondary is galvanically isolated from the mains voltage for reasons of personal safety (a fault will not expose the end user to the mains voltage).

The DC return of your bridge rectifier circuit is most certainly not isolated from the mains. The Raspberry Pi ground is 'floating' with respect to the bridge rectifier ground - there is no galvanic connection between them, hence your voltage measurement.

If you were to connect the DC return of the bridge rectifier circuit to the Raspberry Pi ground, you bypass the galvanic isolation that the DC power supply gives you. This means your Raspberry PI is now mains-referenced, and any fault could potentially expose you you to lethal voltages. I wouldn't do this.

A further complication comes if you also hook up an earth-referenced return to the Raspberry Pi, like a connection to a PC, with the mains-reference return connected. When you mix a mains-referenced return like your rectifier circuit with earth, things are going to explode (you essentially short out your bridge through the earthed return, which is often a flimsy wire that gets really hot and melts/catches fire while blowing up everything connected to it). Another reason not to do this.

You would be much better off with a small line frequency transformer to (1) step down the mains voltage to a lower level ahead of your resistive attenuator, and (2) provide galvanic isolation from the mains. Put your bridge and attenuator in the secondary of the transformer. With this, you can safely connect the low voltage isolated rectifier return to the Raspberry Pi return.

(You also must include a fuse in the line to isolate the rectifier circuit from the mains if there is a severe fault like a transformer fault or a short circuit.)

\$\endgroup\$
  • \$\begingroup\$ Thanks for your reply. So it sounds like I'd be constructing a 3VDC wall wart. I guess I could just purchase a 3VDC (or 12VDC with a voltage divider on the output) wall wart and use that as my GPIO input. \$\endgroup\$ – sizzle Mar 21 '13 at 14:01
  • \$\begingroup\$ Beware that the output of a wall wart may (in addition to being noisy / not the nameplate voltage) persist for some time after the loss of mains power, as the perhaps quite light load very slowly discharges the filter capacitor inside. So this might now work so well as a detector for brief losses such as power flickers, unless you use a fairly heavy load resistor. \$\endgroup\$ – Chris Stratton Mar 21 '13 at 15:26
  • \$\begingroup\$ @ChrisStratton Bingo. A rectifier with no bulk capacitance and very light averaging is the key to be fast - enough filter to keep the minimum above some low limit, but far from pure DC. \$\endgroup\$ – Adam Lawrence Mar 21 '13 at 15:50
  • \$\begingroup\$ I'm going to perform some tests to see what kind of load resistor I'll need. I'd be okay with it taking 5 seconds to completely discharge. But I don't want to wait minutes. \$\endgroup\$ – sizzle Mar 21 '13 at 16:43
  • \$\begingroup\$ Opto-isolator! Also, it's risky to assume anything about the isolation or lack of in any random wall-wart. \$\endgroup\$ – John U Mar 21 '13 at 18:08
2
\$\begingroup\$

I'm not entirely happy with the answers given about dividing voltages etc. as they are not (IMHO) a good approach, from both safety and engineering angles.

I would suggest a basic opto-isolator circuit or even a small relay with a 120v coil as safer, simpler and more effective ways to detect the presence of mains voltage without exposing the Pi to high voltages, floating grounds, etc.

\$\endgroup\$
  • \$\begingroup\$ So drive an opto-isolator with the output of a wall wart? Makes sense. \$\endgroup\$ – sizzle Mar 21 '13 at 19:05
  • \$\begingroup\$ Not necessarily, I'm sure it's possible to drop the mains voltage in a very basic fashion enough to drive a few mA through the diode in an opto without using a wall wart... although given the availability of dirt-cheap nasty wall-warts these days it may not be worth it. \$\endgroup\$ – John U Mar 22 '13 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.