Yes, I've been looking at the schematic too. But I don't know if it's the version he has. I can't find the 5V pin that he connects the gate to. Do you see it?
Yes, that's it.
You are right. ![]()
It turns out, the whole premise was wrong:
This was true when I was wasing 4 AA batteries instead of 3, i.e. 6V (for no good reason). That's more than the 5V of the USB and that is why the power would be drawn from the batteries and not the USB. In that scenario, the diode wouldn't have helped and a mosfet switch would have made sense (maybe the diode would have been needed in addition to that for when the batteries got discharged but I didn't think of that).
But then at some point long ago, I realized that 4.5V was enough and started using 3 batteries, and I never checked again. I didn't realize that this changed everything.
Now I do not need to stop current from flowing from the batteries when USB is connected, but to the batteries. And it's way more important because it's no longer a matter of not wasting battery power, it's a matter of preventing fire. I guess my circuit also happened to serve this purpose out of sheer luck (or at least limit the current somehow) because I never smelled smoke. ![]()
Yes it did. But if the batteries were discharged enough, the body diode of the mosfet would have become forward biased, so even when the mosfet is off, current would have flowed to the batteries from USB. Using a diode instead solves that problem, but introduces a voltage drop in the battery line which effectively reduces battery life. The best solution is using your mosfet circuit, but orienting the mosfet in the opposite direction so the body diode opposes current flowing back to the batteries. The mosfet will conduct equally well in either direction when it's on, with negligible voltage drop, but it will only be on when USB is absent.
Of course current could flow forward through the body diode when USB is present, but only if the battery voltage minus 0.7V is greater than the 4.7V or so of the USB supply after its schottky diode drop. So three AAs would have to be 5.4V or greater for that to happen, which is 1.8V each. Not gonna happen.
This has the additional advantage that if for some reason the mosfet is slow to turn on when USB power is removed, battery current can temporarily flow through the body diode to power the load, which may prevent a reset from occurring.
So I'd say keep your mosfet, but orient the drain to the batteries and the source to the load.
(* according to my calculations, by a lot!!)
That got me thinking...
Maybe using 4 batteries wasn't that stupid after all. Hear me out...
With 4 AA batteries (6V), my original circuit should hold (and be necessary), but now on top of that I'd need to add the schottky diode, with its voltage drop.
Even with the voltage drop, according to my "calculations", assuming the discharge curve below (souce), the battery life should increase by approximately 1.4 (wrt to my current design lacking the diode) which is >1.33. That is you use 1.33 times more batteries, but they last 1.4 longer so overall it's a win ![]()
No, it doesn't, as the current goes through a linear regulator. The voltage dropped over the diode, is not dropped any more on the regulator. The current draw from the batteries remains the same.
Do use a Schottky diode, for its low voltage drop of ~0.3V. The ~0.7V of a silicon diode will cause problems even with full batteries. When your batteries are near empty they're at 3.6V and with a Schottky diode that's 3.3V to the regulator.
Now we have another problem: the minimum dropout of the AMS1117 regulator, which is about 1V. So the output of the regulator is always at least 1V lower than the input, so if you deliver 4.2V to the regulator, you get 3.2V out. That's already less than the 3.3V you're expecting! Still OK for the ESP8266, but when battery voltage drops you will quickly end up below the minimum for this processor to operate.
I think it does. Yes the current drawn from the batteries remains the same but that's not the point. The point is when the batteries reach the voltage where the circuit stops working.
Let's say the voltage needed at the input of the 3.3V regulator is 3.6V (replace this with the value whatever it is).
Without a diode (or more in general, without anything that has a voltage drop), the circuit stops working when the battery voltage reaches, in our example, 3.6V.
With a diode, the circuit stops working when the battery voltage reaches 3.6V + the voltage drop of the diode. So, earlier. You haven't technically reduced the battery life, because you are throwing them away with more residual charge in them, but it reduces the amount of time that a new set of batteries is going to last on this circuit, so for all practical purposes, that's effectively reducing battery life.
Yes, the diode does indeed shorten effective battery life.
If you go to four AAs, you would have to find a mosfet with a greater threshold voltage to be sure that 5V at the gate will turn off the mosfet when the source is 6+V. Four brand new AAs could be close to 6.5V. You would have to find a mosfet with a mininum threshold voltage of about 2V, but still be fully on when the batteries are mostly discharged and USB is absent.
But if you did find such a mosfet, instead of adding the diode, you could add another mosfet with the opposite orientation, with their gates wired in common, so when you turn both of them on, the diode drops disappear, and your battery life is preserved.
What simulator software do you guys use/recommend? (The question of course is open to everybody)
BTW thank you all very much for all the replies.
Indeed, I pointed that out - including the actual minimum dropout of the regulator - in the second half of my post.
Regulators generally don't stop working entirely when the input voltage is too low. They just output a lower voltage than they should.
What about using a simple BJT instead of MOSFET?
Yeah but that's irrelevant. At a certain voltage, whatever that is (when the voltage at the output of the regulator is not enough for the load to operate correctly), the circuit as a whole will stop working or become useless, and it will be time to change the batteries. Without the additional dropout of an additional diode, that will happen when the batteries reach voltage X; with the additional dropout D of an additional diode, that will happen when the batteries reach voltage X+D, which is earlier.
You could use a PNP instead of a mosfet, but then you have to have some base current to turn it on. And that would have to come from the battery. So it would be simple, and I think eliminate any reverse current, but would impose the additional battery load current.
I like using Tinkercad

