Going from GPIO to relays - Page 1
Forum section: electronics / general

author: rthorntn
author_rank: Frequent Contributor
timestamp: May 04, 2020, 04:20:54 am
content: tl:dr what IC's do I use to configure six DPDT using eight GPIO's.Hi All,I'm still a newbie after all this time, I'm sure this is a very basic question but I'm not sure how to find the answer.Where am I going with this, lets say I want to build a networked R2R volume control (can we please avoid any sound quality discussions).Say I want to have 128 volume levels, I want to be able to set and query the volume level over the network.I have an Espressif ESP32-ETHERNET-KIT, let's use that. Let's say it has eight GPIOs and not much else.So I want to control all possible combinations of six DPDT (G6K-2F-Y) relays.I'm thinking I use the GPIO's in parallel, 7 of them to get 128 and 1 GPIO to go high on data ready, stupid?What do I put in between the GPIO and the relays, a similar volume circuit (relaixedPassivehttp://www.vaneijndhoven.net/jos/relaixedpassive/) has a PIC18F connected by i2c to an MCP23017 which is connected to a DRV777 and then the relays but I don't have i2c and they are controlling input selection with the MCP23017 also?I probably want to use ESPHome (hence the ESP32) that allows you to easily set GPIO's over the network and integrate into HASS automation.Thanks for looking.CheersRichard

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: May 04, 2020, 04:28:12 am
content: How about a ULN2003 or similar? It also includes the catch diodes.

author: jackthomson43
author_rank: Contributor
timestamp: May 04, 2020, 04:38:15 am
content: You can use shift registers like74HC595, it works on serial in and parallel out protocol. Moreover, you can also attach multiple shift registers in parallel so can easily control 128 outputs using 3 pins.

author: awallin
author_rank: Frequent Contributor
timestamp: May 04, 2020, 04:39:44 am
content: I've used a 16-output SPI IO-expander (MCP13S17T) driving ULN2803a for TE HF3 relays over here:https://www.ohwr.org/project/rf-mux-8ch/uploads/5241386edf0df7bb423b737b56b15a73/rf-mux-8ch_2018.03_Schematic.pdfThe relay you mentioned G6K-2F-Y seems to require less current, so ULN2803a should be fine.https://www.microchip.com/wwwproducts/en/MCP23S17http://www.ti.com/lit/ds/symlink/uln2803a.pdfEven if you don't have hardware SPI-outputs on your uC it is fairly easy to 'bit-bang' SPI on any three GPIO pins.There should be plenty of libraries for this on arduino or PIC out there.

author: rthorntn
author_rank: Frequent Contributor
timestamp: May 04, 2020, 05:39:27 am
content: Thanks everyone, what a great bunch you all are!So this is the relay circuit, VLx comes from an output on the DRV777:The audio signal goes from bottom to top through multiple potential paths through different resistors, giving you different volumes (stereo, with left channel on the left and right channel on the right).How would the relays be set if you wanted full volume?Say we chose the ULN2803a, I just need one for six DPDT relays then?I guess in the circuit I'm confused about the relay's "states" in the diagram, it only has two?So I look at K209:It has the G6K-2F-YWhat's the symbol between VL2 and +5V on pins 1 & 8 on the relay, a diode?Pins 2-7 on the relay are the DPDT, what is the schematic showing for K209 the L/R going through 47K resistors, is this low, basically how do the electrons flow through R207, R208, R220 & R221:- If VL2 GPIO is low- If VL2 GPIO is highAs you can tell I'm not great at reading schematics. I'm figuring it out as I go along:We are going through the resistors in parallel?:220K100K47K18K5k6820R27K alwaysSo we add all of those resistance values together.Is there an "open-source" or "free for hobby use" way to see the circuit as an animation, so I can understand it?Thanks.Richard

author: rthorntn
author_rank: Frequent Contributor
timestamp: May 04, 2020, 08:48:11 am
content: Thanks all, just wondering now, a board I like has 200mA @ 5V free for additional circuits, trying to figure out if the ULN2803A plus six G6K relays needs more than 200mA @ 5V, looking at the respective datasheets isn't making it any clearer haha?

author: rthorntn
author_rank: Frequent Contributor
timestamp: May 04, 2020, 09:40:58 am
content: Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"I have 1W (200mA * 5V) budget.Do the relays each use 100mW (33mA * 3V), so six relays would use 600mA and the ULN2803A dissipation doesn't really factor in because it's just "amplifying" the current to what the relays are drawing (600mA)?

author: Back2Volts
author_rank: Unknown
timestamp: May 04, 2020, 08:26:31 pm
content: Quote from: rthorntn on May 04, 2020, 04:20:54 amI wonder if a digital potentiometer would be a possibility.

author: themadhippy
author_rank: Super Contributor
timestamp: May 04, 2020, 10:19:34 pm
content: Quoteall i can see is a rectangle with a line through it, thats the relay coil

author: rthorntn
author_rank: Frequent Contributor
timestamp: May 04, 2020, 10:31:13 pm
content: I figured it out in my 4th post...Polarised relays use the magnetic flux of the permanent magnet in their electromagnetic sections, I think this answers my "what's the symbol between VL2 and +5V on pins 1 & 8 on the relay"

author: james_s
author_rank: Super Contributor
timestamp: May 05, 2020, 04:41:08 am
content: There's also the TPIC595, it's similar to the 74HC595 except it can switch 150mA per output at up to 50V.

author: macboy
author_rank: Super Contributor
timestamp: May 14, 2020, 01:50:05 pm
content: Quote from: rthorntn on May 04, 2020, 10:31:13 pmNot exactly. A typical relay has no permanent magnet at all. When energized, the magnetic force from the coil pulls the contact one way, and when not energized, a spring action pushes it back the other way. A polarizedlatchingrelay does use a permanent magnet. A latching relay "latches" into place and does not need to be constantly powered. Most relays are not latching, and require constant power to the coil in order to close the "normally open" contacts.The circuit uses DPDT relays. DP is Dual Pole, and means twoseparate setsof contacts, in this case these are used for the two (stereo) audio signals. DT is Dual Throw and this means that (for each Pole) the relay connects a "common" pin to one contact when idle and to another when energized. So instead of being "on-off", it is "on-on". The schematic symbol is illustrative of function. The triangles on pin 2, 4, 5, and 7 are contacts. The bendy line on pin 3 and 6 is the armature which physically moves toward the coil when you energize the relay. It is illustrated as floating between the two contacts, but actually, it is touching on or the other. When the relay coil is not energized, pin 2 is open/floating (not connected) and pin 3 is connected to pin 4, which is the "normally closed" or NC contact. When energized, the coil (illustrated between pin 1 and 8 ) physically pulls the switch armature away from the NC contact, and toward the NO (normally open) one, on pin 2. Then pin 3 and pin 2 are connected, and pin 4 is open/floating. When you remove power from the coil, it snaps back to connect pin 3 and pin 4 once again. The same thing happens at the same time on pins 5,6,7 on the other side (the other "pole" in the dual-pole relay). If you want to visualize the full path, use a paint program to trace the path through each relay when on or off. Example attached.Note that with a 6-relay attenuator as pictured, you get 2^6 = 64 steps, not 128 steps.The ULN2003 suggested above is a good choice to drive the relays. You need only 6 pins from your microcontroller, one for each relay.

author: Jeroen3
author_rank: Super Contributor
timestamp: May 14, 2020, 02:26:00 pm
content: You can also use deserializers on spi or i2c. Either directly with power capability like an TLE75008-ESD. Or just use discretes after a SN74LV595APWR or the likes.

author: themadhippy
author_rank: Super Contributor
timestamp: May 14, 2020, 03:27:26 pm
content: Quotehttp://www.falstad.com/circuit/circuitjs.html

author: Scrts
author_rank: Frequent Contributor
timestamp: May 14, 2020, 09:01:14 pm
content: How about using a shift register? Just use 2 GPIOs. One toggles as a 'clock' another sets outputs as 'data'. Search for "shift register & relay".

author: hamster_nz
author_rank: Super Contributor
timestamp: May 15, 2020, 08:05:59 am
content: If I was wanting to do something like this, I would mount an RC servo mechanically connected to a potentiometer, acting actimg as a volume control.Clocking relays to change volumes seems like a terrible idea, due to clicks, pops and thumps as relays open and close.

author: Bassman59
author_rank: Super Contributor
timestamp: May 16, 2020, 06:33:36 am
content: Quote from: hamster_nz on May 15, 2020, 08:05:59 amSome very high-dollar audio gear (like the Dangerous Monitor) uses relays to change the volume of studio monitors.* They match resistors in the ladders so that gain changes between steps are "exact" values (to some precision) and more importantly so that gain steps for each channel are identical. Channel-to-channel matching is the critical parameter.A DC blocking cap is used to get mitigate the pops and thumps, possibly with zero-crossing detection to make sure switching happens when they occur. They have to worry about unequal relay turn-on and turn-off times and ensure that the network is always rationally connected, so it doesn't go to full output briefly.I've heard the Dangerous in a very well done mastering studio (the quietest room I've been in that wasn't an anechoic chamber) and with the switching module buried in the equipment rack (it's driven by a desktop remote) you can't hear the relays clicking. And it doesn't click or pop when you change the volume level.Whether you need a $2,000 monitor controller depends on your needs. I did up a monitor controller based on four PGA2320s and it works well enough for my use.* To be clear, the Dangerous operates at line level, and its outputs feed the monitor amplifiers. It doesn't attenuate at speaker level.

author: james_s
author_rank: Super Contributor
timestamp: May 17, 2020, 03:46:23 am
content: It's not entirely outlandish audiophool territory to do such a thing. It's actually a bit shocking how terrible the tolerances are on typical potentiometers. An audio taper pot is supposedly logarithmic but if you actually graph the resistance through the full rotation it's only a vague approximation of a logarithmic curve and in the case of a double gang pot for stereo audio the two sides may not be all that well matched. Most people are probably never going to notice, but if you're dealing with signals in a recording studio you want everything to be well matched.

author: ajb
author_rank: Super Contributor
timestamp: May 17, 2020, 05:58:26 am
content: Quote from: Bassman59 on May 16, 2020, 06:33:36 amI fixed a couple of monitors for a friend recently and noticed the level adjustments on the back had detents, I assumed they were detented pots which I thought was strange, but them actually being rotary switches for better channel-to-channel matching makes a lot more sense. Thanks for the info!

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: May 26, 2020, 01:30:05 am
content: Quote from: rthorntn on May 04, 2020, 10:31:13 pmSometimes they are polarized because they have a LED indicator or diode supressor. I’ve never seen a relay with any type of perm magnet.