0

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.

Timberwolf
  • 105
  • 5
  • 2
    Use a cheap USB charger to put out 5VDC from 120VAC? – Finbarr Jul 12 '19 at 12:06
  • 1
    You might like [AC Optocoupler for 230V line detection](https://electronics.stackexchange.com/a/367997/36731). – Andrew Morton Jul 12 '19 at 12:37
  • 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. – TonyM Jul 12 '19 at 13:13
  • @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. – Timberwolf Jul 12 '19 at 22:34
  • Just looked into the Wiki for an Opto-isolator... I may be able to make my own. – Timberwolf Jul 12 '19 at 22:36
  • Forget the 'may's, an opto-isolator will work and you can make such a circuit :-) Unless costs are very tight, it's by far the (my) best option. You get logic output ones and plain transistor outputs. I'd head for the latter and you can get any logic voltage from them you want using a pull-up or pull-down resistor to the rail voltage you want. Again, plenty on this on the interweb or this site. – TonyM Jul 13 '19 at 07:41
  • I just picked up a 4 channel AC Input module from eBay to see how well it works for me. However for production I may use a 120vac lamp and photoresistor on the 3.3v rail, since that would be much cheaper than buying new AC Input modules. This is more or less just a prototype for a product I'm planning on putting on Kickstarter. – Timberwolf Jul 14 '19 at 08:20
  • The one thing that I don't like about that option is I'm limited to a certain number of hours, depending on the bulb I pick. – Timberwolf Jul 14 '19 at 08:26
  • I had a thought... What about a relay? I don't even know where I would start looking for a relay with 120vac control and 3 or 5vdc out, but the concept wouldn't be difficult. Hell I could make a relay with an electromagnet... – Timberwolf Jul 16 '19 at 20:39

5 Answers5

2

@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.

Spehro Pefhany
  • 376,485
  • 21
  • 320
  • 842
  • I'm relatively new to schematics. I don't understand how I would use the AC input module. Could you explain it to me? – Timberwolf Jul 12 '19 at 22:20
  • The datasheets are not too clear on stand-alone use, unfortunately. [Here](http://www.crydom.com/en/products/catalog/m_input_modules.pdf) 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**. – Spehro Pefhany Jul 12 '19 at 22:34
  • 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. – Spehro Pefhany Jul 12 '19 at 22:36
  • 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? – Timberwolf Jul 12 '19 at 22:41
  • 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. – Spehro Pefhany Jul 12 '19 at 22:44
  • Last question for you: does this module require a load or do I just hook up hot and neutral to the pins, making it the "load"? – Timberwolf Jul 12 '19 at 22:50
  • The device will switch if the input current is more than a small current. If your switching device leaks too much you might require a "load" but generally no you don't need it for mechanical switching. If there's a dimmer or some kind of solid state switch, that's different, as they often have snubber networks that pass significant current even when "off". – Spehro Pefhany Jul 12 '19 at 22:53
  • Ok, so it came in, but it seems I'm doing something wrong. https://photos.app.goo.gl/yuizvjDnuvYRyuzE6 – Timberwolf Jul 15 '19 at 22:24
  • Yellow is +5vdc and green is ground on the pi. – Timberwolf Jul 15 '19 at 22:25
0

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.)

Tony Stewart EE75
  • 1
  • 3
  • 54
  • 182
  • Put me down gently... I understood pretty much none of this. Could you dumb it down to untrained hobbyist level? – Timberwolf Jul 12 '19 at 22:29
  • 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. – Tony Stewart EE75 Jul 12 '19 at 22:52
0

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.

Simon Richter
  • 12,031
  • 1
  • 23
  • 49
  • 1
    "*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. – Transistor Jul 12 '19 at 13:23
  • @Transistor, well, if they put it in a plastic box and only talk to it via WiFi... :P – Simon Richter Jul 12 '19 at 16:37
  • 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? – Timberwolf Jul 12 '19 at 22:27
  • @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](https://en.wikipedia.org/wiki/Appliance_classes) 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. – Simon Richter Jul 15 '19 at 08:09
0

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.

Transistor
  • 168,990
  • 12
  • 186
  • 385
0

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.

Timberwolf
  • 105
  • 5
  • As the contacts are only used for signalling, keep [Why does a relay have a minimum applicable load?](https://electronics.stackexchange.com/q/214139/36731) in mind. – Andrew Morton Jul 19 '19 at 10:59
  • @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. – Timberwolf Jul 20 '19 at 03:07