Looking for help connecting 3.3v GPIO to either 3.3v or 5v relay

I've poured over so many different tutorials and howto's, but I'm still really confused and would rather pay an expert a couple of hours to provide me with a good direction. I need to connect a 3.3v GPIO to a relay in order to control a 24v/2a DC load. As I understand it, I should be using a transistor and resistor in order to protect the GPIO circuit, but I have no idea what part numbers to use or how to hook them up. I've got several different relays (Songle 3v, Songle 5v, some with optoisolation, etc), and would like to have some guidance on how to choose the correct model.

Some can be connected directly to an Arduino output, others need driver circuits. It depends on the exact relay (module).

You best find one that has the driver circuits built in. "Opto-isolated" is a good sign that this is the case. As you forgot to add links to the specific models you have in mind that's all that can be said about it.

There are plenty of ready made realy modules that includes the driving circuit (the "transistor and resistor") you mentioned. Those can be connected directly to arduino.

I wasn't sure if posting links was allowed, but these are the two units I'm looking at:

As you can see, one of them is opto coupled. However, when I try to trigger it, the little LED comes on, but it doesn't actually trip the relay. The non-opto coupled relay SOMETIMES triggers, and sometimes doesn't.

the second one is a 5V module, so it may or may not work with 3.3V. The first one, however, should work fine. You should post a picture or diagram of how you connect it

Here’s how I have it connected:

Should work indeed, the marking on the image is at least 3V.

Are you sure you have sufficient power available on the 3.3V line? That’s the main issue I can think of now.

Just to make sure: are the two jumpers next to the optocoupler in place? That looks like an external power supply connection (allowing the relay to be really isolated).

I've tested the GPIO in the HIGH position at 2.6-2.7v, which I think is correct?

Yes, check the jumpers, and double check the wires you used too. Once I had something not working and spent hours trying everything before realizing one of the jump wires was not crimped properly....

agaller:
I've tested the GPIO in the HIGH position at 2.6-2.7v, which I think is correct?

should be 3.3 actually

what board are you using?

agaller:
I've tested the GPIO in the HIGH position at 2.6-2.7v, which I think is correct?

Too low - should be close to 3.3V indeed.

What do you measure for Vcc, for that matter?

Unless I'm reading things wrong, according to this link, 2.7v is within spec:

https://learn.sparkfun.com/tutorials/logic-levels/all

You should really tell us which board you are using

wvmarle:
Too low - should be close to 3.3V indeed.

What do you measure for Vcc, for that matter?

I measure 3.1-3.3v on VCC reliably.

That's some serious spread. Vcc should be much more stable than that.

wvmarle:
That’s some serious spread. Vcc should be much more stable than that.

It is likely my meter.

The relay alone can draw 120mA or more, is it possible that's too much for your supply? The low voltage reading could also be result of insufficient supply.

blimpyway:
The relay alone can draw 120mA or more, is it possible that's too much for your supply? The low voltage reading could also be result of insufficient supply.

This is what I think is going on, if the GPIO can only supply 60ma, but the relay requires 120ma, it may never trip, or trip intermittently.

That's why you have that separate Vcc pin: that's where your power supply goes (so you have sufficient power), so your signal doesn't have to provide all that power.

You STILL didn't tell us what controller you're using. But I can tell you quite certainly whatever that controller is, it can not supply 60 mA though a GPIO pin.