News:

Forum may be experiencing issues.

Main Menu

Relay meets Optocoupler Question

Started by greysun, January 06, 2024, 07:12:00 PM

Previous topic - Next topic

greysun

I decided to start my breadboard from scratch just focused on getting a single relay to work. I think it helped, but I'm not out of the woods.

I wired this diagram: https://handsontec.com/dataspecs/relay/1Ch-relay.pdf (see page 2) almost exactly... The only thing I changed: transistor is wired for logic NOT gate, meaning a 10k resistor between +vcc (5v, not from the Arduino) and pin 3 (collector) of the transistor S8050, and then I send it just to one side of the relay (pin 1 OR 10). This allows the voltage to invert, which is what I want (thank you, mjg!!!).

Off the S8050 transistor, I had 5.8v on the collector (pin 3), .7v on the base (pin 2), 0v on emitter (pin 1).

When I cut off "IN," I had 0v on the collector, .7v on the base, 0v on the emitter. Looking good, feels like it's what we want, BUT...

when I connected the each transistors pin 3 (collector) to pins 1 and 10, respectively, on the relay switch (TQ2-L-5v), the voltage dropped from 5.8v to .15v, which is not enough to engage the relay.

It's almost like the resistance between the coil pins (250ohm) is connecting the 2 circuits and killing the voltage. if it weren't for that, it seems like this would be working... it's almost like I need to have 2 more opto isolators, but that feels like overkill.

Any thoughts? I feel like I'm REALLY close... Thanks again for the help! It's why I keep coming back here! :-)

mjg

I'll see if I have time to breadboard something tomorrow for you.  Hopefully I've got a spare relay sitting around somewhere. 

I think what you need is two pins from the Arduino, connected through a transistor or mosfet each as a buffer, and then switch one pin high, other low.  Then reverse the high and low to switch back the other way. 

I think that diagram you've been looking at is a non latching relay?  That might be why it's not quite working. 

greysun

Quote from: mjg on January 09, 2024, 06:45:53 AM
I'll see if I have time to breadboard something tomorrow for you.  Hopefully I've got a spare relay sitting around somewhere. 

I think what you need is two pins from the Arduino, connected through a transistor or mosfet each as a buffer, and then switch one pin high, other low.  Then reverse the high and low to switch back the other way. 

I think that diagram you've been looking at is a non latching relay?  That might be why it's not quite working.

I do appreciate it, so thank you in advance if you take that step!

In the meantime, I'm seeing folks on the internets using 555 timers to create/operate latching relays - and have a ton of those on-hand.

There's this video: https://www.youtube.com/watch?v=dzcgETRXbOM and also this: https://www.youtube.com/watch?v=f8O44E9RlsY

I know those aren't 1:1 what I'm doing, per se, but it seems like a similar logic may be able to be employed to trigger the relay. I'll do a little sleuthing - 555 timers have always confused me and I have little experience with them, lol, yet somehow I have 16 on-hand!

greysun

Furthering the 555 timer, it seems like I could do something like this: https://www.eeweb.com/voltage-controlled-switch-using-555-timer/ - that appears to be a bistable mode, but there are so many variations of this I can't quite figure it out.

I'd need 2 555s, but I've got plenty and they're cheap - if I have both always set at 0v by the , I can pulse one 555 to activate it (pin 1 5v, then 0v), and the other 555 to deactivate (pin 2 5v, then 0v) it... at least that's what I'm thinking.

I mocked it up quickly in illustrator over lunch. Any thoughts on this one?

mjg

Using a 555 would probably work, but all it's doing there is being a voltage controlled switch.  Which is the same as a transistor or mosfet really.  Not sure it will get you anything different to what you've already tried?

greysun

Quote from: mjg on January 09, 2024, 08:53:34 PM
Using a 555 would probably work, but all it's doing there is being a voltage controlled switch.  Which is the same as a transistor or mosfet really.  Not sure it will get you anything different to what you've already tried?

You are probably right, and that 555 circuit doesn't work anyway. But I just can't get the other inverter circuits to work with this relay - like I said, I'm able to invert the voltage with a logic NOT gate, but once I connect each to the coil pins, the voltage drops and nothing happens when I trigger the coil, as if it's just connecting the 2 NOT gate circuits to one another through the coil instead of .

I just did a quick test using NOT gate with the s8050 - one of the NOT gates on one side of the relay coil at 0v, and direct 5v (straight from power source) on the other side of the relay coil. This setup snaps the relay when I swap the pins, so the relay works, and I know that at least the NOT gate at 0v will work. 

I then did the same test with one of the NOT gates at 5v, the other at 0v. Doesn't work when I swap the pins.

Am I missing a diode(s) between the NOT gates and the relay pins that would keep the voltage from going back to the collectors? I can't figure it out...

greysun

Here's the diagram as it stands now.

I have LEDs in series with the optos for testing only - but I should be able to turn one off, leave the other on, then reverse that, and it should "click" - but it doesn't.

I did a pin readout - on the 5v pin, I read 5.8v with direct power, but only .14v with the NOT gate.

Measuring direct from the collector, it's 5.8v when opto is triggered, 0v when otherwise.

I just don't get it...

greysun

Breakthrough! I replaced the 10k resistor from +5v with 100r, and it's working!

When the relay is triggered, it measures 4.25v to one side of the relay, and between .1 and .3v on the other. (I think it needs at least 75% of 5v to work, or 3.75v, and 200r got me 3.3v, so 100r gives me a good buffer to work from depending on the power supply)

When both optos are on, voltage is .1v each side of the relay.

When I measure the transistor pins - collector matches the relay pins - base is .7v when optos are on, and when they're off it reads -1.1v and grows slowly up toward -1.6v (I imagine it would keep moving up if I left it in that state - but I think the optos are always on except when triggered in the code).

So I guess my last question on this thread then would be: Is there a danger to the transistor using only 100r with the NOT gate circuit, given the above numbers?

If you have any info, I'd love it!

mjg

Glad you got it working.  I breadboarded something very similar and that worked for me.  Only thing I left out is the opto chips.  If you have a common power supply for the Arduino and transistors, you don't need the opto chips.  But if you need that power isolated from each other, put them in. 

I think with your 100r resistors at 5v you will have 50mA going through the transistor, so check the data sheet to see what they can handle.  Or try 1k and see if that still works.

I've got with transistors as a buffer, rather than an inverting buffer.  Makes no real difference, as you just invert the logic on the Arduino pins to do what you want. 

mjg


greysun

Quote from: mjg on January 10, 2024, 06:32:28 AM
Here's what worked for me...

I tried this exactly as you have it, and it was the same as my own - the readings were only like .15v different when triggered and I had to reduce the resistor to get the voltage right across the pins. These TQ2 relays are oddballs.

I also checked the transistor datasheet, which seems to have a 1500mA on the collector pin, so 50mA shouldn't be an issue for it... though 50mA feels high, but I think the relay pulls 40mA (which is why I didn't want to run it directly from the Arduino when I'll have so many) - if you have a minute to explain the math there, I'm all ears (not saying I came up with anything different - I've just never had to measure it before, lol. A quick google search has a lot of multimeters and whole home circuit panels, which may not apply one-to-one against this need).

Thank you thank you thank you again - I would not have gotten to something that works without your help, so I really appreciate it!