# Using a specific optocoupler to turn on relay

I have already done research on how to turn on a relay with an optocoupler but I am still confused on some aspects. My diagram works great even though I am doing things incorrectly.

simulate this circuit – Schematic created using CircuitLab

## Diagram explanation:

• On the right side:

I have an atmega328p chip (arduino) running on 3.3V instead of just a 3.3 battery. I drew it that way to make it simple to illustrate. Arduino datasheet states that it should run on 5V but it runs fine on 3.3V. That circuit uses 40 mA.

• On the left side:

I have a relay connected to a 6V battery. That circuit uses 112 mA.

## Questions

1. I first used 100 Ohms on the right side of the diagram instead of 50 because that used 20mA of current. Arduino states that you should not use more than 20mA of current per pin. My question is why is it that it does not work with a 100 Ohm resistor? Here is a picture of what I had to do in order to make it work:

as you can see on the image I had to solder another 100 Ohm resistor in parallel in order to make it 50 Ohms because it was not triggering the relay. So now I know I am braking the rule and the pin of Arduino is outputting more than 20mA.

1. If it works now with 50 Ohms resistor how long could it run without breaking?

2. Let's say I use another microcontroller where I am able to output as many amps I want per pin. Or just to make it simple I have a battery connected just like on the diagram instead of having a microcontroller like Arduino. How can I know if 40mA is to much current for that optocoupler running at 3.3V? Moreover, on the left side of the diagram how can I know if 112mA is to much current? I been trying to find the datasheet for that optocoupler and I cannot find those specs.

3. Let's say I decide to buy a different optocoupler because I cannot find the datasheet of that one. Let's say I decide to buy this one:

I can see on those specs that it can take up to 20mA so I will have to use 100Ohm resistor assuming I still use 3.3V. Where is the info on what is the max current it can take in and what is the max current it can output? For example will 112mA will be a lot of current for that optocoupler? Where can I find that info on the datasheet? I know I can make use more components in order to follow the specs but it will be nice if I could understand what are the maximum values I can use

• My diagram works great - not for me it doesn't - it's confusing and you appear to have the input supply connected incorrectly. The output transistor connections are unfathomable. Aug 5, 2021 at 13:58
• LED polarity is backwards. Opto-transistor is backwards too if it is an NPN. Aug 5, 2021 at 14:54