MK14, i have to say i totally agree with your statement about poor designs floating on the web since i have used one here
Also seeing your second post about the 8 channel relay board i see where the optocoupler would be useful. That is not in my case where i have a single regulated power supply.
Ian.M, you are right i should have have attached the corresponding datasheets so that there would be no room for error.
Fortunately i was clear about the different diode and optocoupler used. Also i cannot thank you enough for the analysis you have done here. It really gave me an insight of the circuit. I had just copied and did not think about how it would function. Changing the logic should not be a problem since the code is finished already i will have to change a few bits of it. I will drive the transistor directly.
Furthermore the bullet points will be copied and kept as notes with the additions from MK14. The points you made WILL be very useful for me. Thank you so much.
Also Manul and eblc1388 thank you for your feedback and additions so much.
TBH i have little to no experience in designs that implement optocouplers, thus i just found a basic "proven" schematic to base my design on.
In addition from reading what you all had to say i made the changes to the board but something is not yet right. I am driving the MMBT2222A directly but the relay does not get activated. I will post the new schematic below for you to take a look. Its straight forward the MCU pin in series with an LED and a resistor connected to the 2222. I will take a look at the joints , diode orientation and bridges then start taking some measurements. Its odd that the relay is not active when a logic "1" is applied. I would like to troubleshoot on my own for a bit then ill post what the culprit was (if I solve the issue).
UPDATE: It was too naive of me to rely that my PCB design skills would not fail me. This whole time while troubleshooting (since before i posted the question on the forum) the second pin of the transistor was floating.
See when you have made a polygon pour that is used as a ground plane and is cut in pieces by traces on the bottom of the PCB, its good practice to connect these pieces together.
I will attach a picture below of my bottom layer. It is evident that the area marked as ground on the pin of Q2 and Q1 respectively is not connected to the ground plane.
In the photo i marked the "ground" areas with red. As seen they are not connected to the ground plane at all. Call it a rookie mistake but i would call it just dumb
Edit : Of course after connecting these two areas to the ground plane the problem was fixed.