0
\$\begingroup\$

For a background, I have 3 DPST bistable (latching flip-flop) relays that I have 120VAC input and 2 outputs. On one side, I have a 120VAC appliance. On the other side I need to find a way to feed it back into a Raspberry Pi's GPIO pins to detect whether it's live. What is the simplest way to accomplish this? I thought about step-down transformers and induction, but the transformer would get expensive, since I can't seem to find any other way to do it besides chaining 120vac to 5vdc and 5vdc to 3vdc and I have no idea how to use induction.

UPDATE:

Thanks for all of your answers. The Bistable relay requires a 0.2s pulse to trigger to switch, so as long as the response time is less than or equal to that, it will work just fine. As such, using a cheap USB charger should work if @Transistor is correct in his assessment about ~100ms response time. However, it seems a bit hackish and I'd rather find something ready to be used in a DIY circuit rather than tearing apart the casing to extract the guts of a product.

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Use a cheap USB charger to put out 5VDC from 120VAC? \$\endgroup\$
    – Finbarr
    Commented Jul 12, 2019 at 12:06
  • 1
    \$\begingroup\$ You might like AC Optocoupler for 230V line detection. \$\endgroup\$ Commented Jul 12, 2019 at 12:37
  • \$\begingroup\$ Use an opto-isolator. Then you have safety isolation from the mains and no worries about earth current loops. Search on SE or Google for more, this has been covered many times and there should be plenty about. \$\endgroup\$
    – TonyM
    Commented Jul 12, 2019 at 13:13
  • \$\begingroup\$ @TonyM An opto-isolator may work... I'll look into it. The biggest thing is the GPIO pin cannot exceed 3.3v input per everything I have read. \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:34
  • \$\begingroup\$ Just looked into the Wiki for an Opto-isolator... I may be able to make my own. \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:36

5 Answers 5

2
\$\begingroup\$

@Finbar's suggestion is the easiest and safest if you just want to plug it in and don't care about response time. Use a genuine safety-agency approved charger, not some dollar store item made of Shenzhen street sweepings, some of them are very bad (and unsafe) indeed.

You should add a bleeder resistor to drain the output votlage in a reasonable length of time and you'll also need to reduce the 5V USB output to 3.3V or so for the Raspberry Pi. A single pair of resistors can accomplish both requirements, say 1.8K and 3.3K.

schematic

simulate this circuit – Schematic created using CircuitLab

Test it to make sure it responds fast enough, some chargers can take close to 1 second to start up and there will also be a noticeable turn off time. Because the turn-off is "soft" you should apply software debouncing if you're looking for edges.


Alternatively, you could use a standard "AC input" module made for industrial use. They are multiple-sourced and made to be safe and reliable.

\$\endgroup\$
9
  • \$\begingroup\$ I'm relatively new to schematics. I don't understand how I would use the AC input module. Could you explain it to me? \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:20
  • \$\begingroup\$ The datasheets are not too clear on stand-alone use, unfortunately. Here is another manufacturer. The AC input (hot/neutral) goes to pins 1 & 2 on the module (series fuse is recommended), you supply +3.3 and GND from the RPi on pins 3 & 5 respectively, and the RPi input with a pullup resistor or enabled pullup in the Rpi goes to pin 4 (a 4.7K external pullup would be better). Response time is in the 10's of ms for on or off. Be sure to keep the AC and low voltage WELL separated and properly insulated inside a box for safety. \$\endgroup\$ Commented Jul 12, 2019 at 22:34
  • \$\begingroup\$ You can try following the training videos available at Digikey etc. but even after that you should have someone familiar with mains wiring looking it over before applying power. \$\endgroup\$ Commented Jul 12, 2019 at 22:36
  • \$\begingroup\$ Based on what you just linked me, it seems that an AC input module is just a type of Opto-isolator, or did I just misinterpret that? \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:41
  • \$\begingroup\$ Yes, it’s an isolator with additional circuitry to accept AC mains directly and to provide a clean logic-level output. Nothing that can’t be done with a handful of individual components, but it also has good creepage and clearances and is safety-agency listed. \$\endgroup\$ Commented Jul 12, 2019 at 22:44
0
\$\begingroup\$

If you know how to make compute an impedance voltage transformer with caps and resistors like a scope probe, you can divide 100:1 and rectify with some slow rise or fast risetime specs and threshold to logic and shunt Neutral to 0V with another cap.

A suitable detection window for time and frequency must be specified by you for noise immunity, depending on your noise environment.

If you define your input , output and range / tolerances & thresholds, then a solution can easily be defined. Vin min(on), Vin max(off), Logic “0” Vil(max), Logic “1” Vih(min,max), Time detect, min, max) Noise reject at 1kHz to 1MHz= __ dB, ( nearest interference dI/dt, dV/dt and distance to input.)

\$\endgroup\$
2
  • \$\begingroup\$ Put me down gently... I understood pretty much none of this. Could you dumb it down to untrained hobbyist level? \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:29
  • \$\begingroup\$ Ok. Using a film cap rated for say>500Vac = 1nF with a 1:100 ratio means 1% of the Vac using 100nF ceramic rectified to a a much smaller cap with >=10MOhm input and impedance with 10nF gives a decay sag time constant of 100ms which is much greater than 8.3ms of 120Hz full wave rectified line voltage yields about 1.2 * sqrt(2) Vdc. You need to understand to design things. \$\endgroup\$ Commented Jul 12, 2019 at 22:52
0
\$\begingroup\$

If your neutral is (or can safely be) connected to GND, you can use a diode, a capacitor and a voltage divider. Rectify the AC to DC (keep in mind that this will be peak voltage!), buffer in the capacitor and pull down to the voltage you want.

The difficulty there is that when you do that, your circuit ground will no longer be floating, which brings you into "you need a suitable enclosure" territory.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ "If your neutral is (or can safely be) connected to GND ..." Oh-oh. The GND in this case is a Pi with USB, video ports etc. This is unlikely to ever be safe. \$\endgroup\$
    – Transistor
    Commented Jul 12, 2019 at 13:23
  • \$\begingroup\$ @Transistor, well, if they put it in a plastic box and only talk to it via WiFi... :P \$\endgroup\$ Commented Jul 12, 2019 at 16:37
  • \$\begingroup\$ Well I have 120VAC coming in from a household outlet. I have no idea whether they are connected in this house or any other house that I may plug it into. Is it standard electrical code in America? If not is it safe to connect them? \$\endgroup\$
    – Timberwolf
    Commented Jul 12, 2019 at 22:27
  • \$\begingroup\$ @Timberwolf, it's not about the electrical installation, but about the way your box is built. If there are no other connections, you can go for a Class II device with double insulation. If there are other connections, this will not work at all, because the GND of the Pi needs to be connected to your neutral for this, while normally it would be connected to protective earth -- so if you connect HDMI to a TV, the HDMI cable would connect earth to neutral, which is forbidden. The "resistor divider" alternative is cheap, but limited. \$\endgroup\$ Commented Jul 15, 2019 at 8:09
0
\$\begingroup\$

Since you haven't specified a response time I guess that it is not important for your application so 5 V USB power supplies which are available for a couple of €/$/£ would be suitable.

You will find that they take maybe 100 ms or so to turn on and the turn-off time will depend on how long it takes to discharge the internal capacitors. You can speed this up by adding a load such as a resistor and LED.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. PSU with indicator / discharge LED.

\$\endgroup\$
0
\$\begingroup\$

I was looking at a mechanical relays internals and had an epiphany - relays are just electromagnetic versions of an opto isolator. So I started looking for relays and I found a relay that has 120vac control and a 28vdc contact. By the answer provided in my other question, I found it was feasible to use the relay for my purpose. I feel this is the simplest way to do this. If anyone has any better ideas, please feel free to add another answer because I'm always open to suggestions.

\$\endgroup\$
2
  • \$\begingroup\$ As the contacts are only used for signalling, keep Why does a relay have a minimum applicable load? in mind. \$\endgroup\$ Commented Jul 19, 2019 at 10:59
  • \$\begingroup\$ @AndrewMorton this is a fair point, but the input mode for the Pi's GPIO pins are around 80mA if I recall correctly and based on what I could find, 10mA seems to be a common minimum. \$\endgroup\$
    – Timberwolf
    Commented Jul 20, 2019 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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