I'm using a MCP23017 [I2C] switching 16 relays. 12 of them relays i already have 2N2222 transisters switching without an issue [ Relays wired direst to transisters ]. In my project i have an existing quad relay module that would be a pain to replace & i would like to use. I basicly need all 16 IO on the MCP23017 to have 2N2222 transisters. Is the is the correct witing to allow the transister to controll tre relay module?.
You should have a resistor in series with the transistor base (maybe 1k). The Base-Emitter voltage is about 0.7V (basically a diode) and without a current limiting you are stressing the transistor and the microcontroller.
It's the same reason LEDs need a resistor, although they operate at slightly-higher voltage.
Whether you need a pull-up resistor or not (on the collector) depends on the whatever circuitry is on the relay board. If it's working as you've shown it, just add a base resistor.
I can’t see from the picture, but if the relay coil is connected directly to the transistor collector you need a fly back diode in parallel with the relay coil.
If the relays are driven by an optocoupler you are OK with just the base resistor (~220R-370R) suggested by @DVDdoug
You should have a resistor in series with the transistor base (maybe 1k). The Base-Emitter voltage is about 0.7V (basically a diode) and without a current limiting you are stressing the transistor and the microcontroller.
I forgot to ilastrate it but there is a 1.2K resistor between MCU & Transister base.
I can’t see from the picture, but if the relay coil is connected directly to the transistor collector you need a fly back diode in parallel with the relay coil.
If the relays are driven by an optocoupler you are OK with just the base resistor (~220R-370R) suggested by @DVDdoug
as mentioned above i have a 1.2k resister between MCU & Transister i forgot to ilastrate, The first 12 relays are driven from the transister with flybacks across the coils, i was not not sure if what i have ilastrated would switch the relay module with octocouplers.
what im basicly attempting to do is design a circuit where i can use either or, i have a few home automationn systems where pre assembled relay modules are used. id like the ability to use one of my own relay boards [ 5v coil flyback ] or a pre made module.
Again thankyou for the help with the sanity check.
I have just finished designed a PCB for this projec. [ Images attached ]
This board allow for the ESP32 to be mounted [Hotswapable], the MCP23017 mounted [Hotswapable] & both input or output to terminals via jumpers. This will primarialy be all outputs with the transisters doing the switching for relay modules / custom relays, moving 2 jumpers per terminal will bypass the transister [Disconecting it] and converts the terminals from the transisters Collector & Emittrt to the MCP23017 GPIO & GND plane, this will allow me to activate the MCP internal pullup resister through code and use it as an input instead.
I have given the ESP Safe at boot pins [ pins which are not not required to be held high or low at boot ] terminals to allow for further expansion & done the same witht the SDA / SCL to allow for daisy chaining on these or other I2C devices.
Jumper1 - GPB0 is the pin from the MCP23017 into the middle of the jumper allowinng connection to either the terminal or the resister on the base of the 2N222A transister. The transisters collector pin is still connected when the jumper is set to the terminal direct.
Jumper 2 - Disconects the transisters emitter from the terminal, conennecting the terminal to GND. Both jumpers have to be in the Input possition to acheive this.
The board itself & all compnents are powered by a 5v switching power supply and have output terminals to allow for powering of further devices.
Thankyou again for the rapid reply & help
The redesign of the PCB will be having large copper pads underneith the chip on all layers to allow for heat disapation & provisions for a mounted heatsink if needed, Dont want to take the chance for any heating issues.