I have this circuit where it has a battery and a 12v power input. what it should do with the first half of the circuit is to select the 12v when it's avilable else use the battery.
And the rest is simple latching circuit.
but as soon as i connect the 12v power the D9( MBR0540) diode burns.
You are applying 12V directly to an Arduino pin and that is never a good idea.
You may have other wiring errors and/or the MOSFETs may be shorted.
I see you have overlapping pin numbers on the schematic, also never a good idea.
Is anything connected to BATT
What are the MOSFETs part numbers?
I havn't added the MCU yet. so nothing happened there. Can you suggest any solution of to keep the gpio safe maybe?
i can't see any wiring error, i tested both circuit separately but when combined it blows the diode.
A 8.4v(2s 18650) is attached to the fet.
mosfet is AO4407a
There has to be a short circuit somewhere.
With nothing connected to the circuit measure the resistance between the diode cathode and ground. It should be a very high value.
Make sure the diode is not in backwards.
If you have Q4 reversed, then 11.7V could flow back through its body diode to charge the battery with no limit on the charging current. But you said the two sections work ok separately, so my explanation probably isn't the answer.
But I agree with @jim-p that there has to be a short somewhere, or something installed backwards. You should be able to find that with your meter.
However, I don't think R12 should be there at all. You should enable the internal pullup resistor on the GPIO pin, which would be grounded through D7 when the button is pushed.
Guys, it's a fulty mosfet in Q4. I was questioning my career choice and wasted whole day and not to mention time of yours.
I soldered another new board with new ICs and it worked fine. Than i took off each of the IC one by one in the old board until the D9 didn't blow up and when Q4 was out the diode didn't blow up. Than i resolderd the ICs one by one again and all worked fine.
I tested the auto switching and also the latching circuit all works now. I will not use the R12, and use intarnal pullup.
Thanks all, you guys are good people. And special thanks to @jim-p.