when simulating the circuit is always working (r1 and r2 at 10k) but will it work in reality?
if not, how are r1 and r2 calculated?
I use esp32 connect with it, high (1) is 3.3V
It's impossible to answer without relay specifications. Ooooops... and input signal specs. If the line running off diagram to the left goes to an ESP32 pin, you should get rid of the 1N4007 diode and power R1 from the ESP32 3.3V instead of 5V. 10K would be a very high value for an opto drive, did you design from PC817 spec sheet, or did you just make wild guesses?
it depends on the current required by the relay.
why not just use a relay module that already can be driven by the arduino pin?
That refers to R2, and I agree. R1 is calculated with R = (Vcc - Vdrop) / I, where I is the optimum drive current for the opto (roughly, maximum). Vdrop is the LED forward voltage.
this is relay: http://www.datasheetcafe.com/srd-12vdc-sl-c-datasheet-pdf-relay/
add this is tutorial where I see the circuit: Arduino Relay Module Tutorial | Microcontroller Tutorials
I use PC817 because it's common
I suppose that being an engineering student, you can imagine the steps to calculate R2. Required base current must exceed the relay current 37.5mA divided by the transistor's high current beta. I already covered R1.
As a start, consider the rank. It determines the range of CTR you can expect from the part.
I've destroyed several 2222s with relays, not a good choice, get something stronger.
The 37.5mA load is well within the capability of a 2N2222, provided that there is sufficient base current. The modules use a similar transistor and circuit.
Why do you have an opto and a relay? Do you specifically need isolation?
Is it a school assignment?
There are two versions of that 12volt relay. 30mA and 37.5mA coil current.
To properly switch 30mA with a 2N2222 you need ≥ 5% base current, so 1.5mA.
(Beta is irrelevant for switching).
That works out to 10volt/1.5mA = 6k8, assuming 2volt combined volt drop of the opto transistor and BE junction of the 2N2222.
If you have the basic/unbinned PC817, with a 50% CTR (current transfer ratio),
then LED current should be twice the opto transistor current, so 3mA.
With a 1.3volt drop of the IR opto LED and 3.3volt ESP pin drive and no 1N4007,
R1 works out to (3.3volt - 1.3volt) /0.003A = 680 ohm.
The circuit should be tested by measuring collector voltage of the 2N2222.
It should be < 0.5volt when the relay is 'on'.
Leo..
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.