In a battery powered project, I put my Atmega328PAU to sleep, and also need to power down a couple things to conserve power. An LCD, and an RTC (DS3231M), neither of which use very much power.
I've come up with this schematic (photo), and am wondering if 1) the schematic is suitable, and 2) the MOSFET is a viable selection. Find attached the schematic and the MOSFET data sheet.
PMV48XPA2 20 V, P-channel Trench MOSFET
I feel like I barely scratch the surface on understanding MOSFETS. this one appears to be logic level, as it gives the Vgs for a 4.5Volts, and the Rds(on) is 43mOhm, which I think is good?
Your mosfet is fine. The spec you want to look at for logic level is VGSth in Table 7. That's the threshold voltage at which the mosfet starts to conduct. See also Figure 10. It looks like this one would work for 5V or even 3.3V Arduinos.
If you're going to use R10, you need to get into the habit of connecting R11 to the A1 end of R10, not the gate end. It doesn't matter in this case, but as drawn you have a voltage divider, so when A1 goes low, the gate doesn't go all the way to ground.
But I'm not sure you need a mosfet at all. You can easily drive the DS3231 from any GPIO pin. Just make sure the pullup resistors' top end also switches with the DS3231. And I would think the same could be done with the display.
One other thing you may need to do to save battery power is to change the I2C pins to be INPUT before you go to sleep. If you don't, Wire.h will leave them as INPUT_PULLUP, and current will flow.
interesting food for thought. I know the RTC uses very little power, but I thought the backlight of the LCD used a lot, I'll have to look into that.
...the I2C pull ups? So I'd want them to pull up to the switched voltage (either from the MOSFET or the Atmega pin directly), not pull-ups to the constant +5volts, correct?
I wondered if the I2C lines would be draining anything, thanks for the tip. I've learned that before switching off the LCD power, I need to set all the data pins to LOW also.
Yes. You don't want to apply voltage to a device which has its power switched off. It could damage the device, or at the least pump lots of current through the protection diodes. Remember that most I/O pins have a diode from the pin to the chip's Vcc. So if Vcc goes to zero, an I/O pin can sink lots of current - until it loses its smoke. So you want to turn everything off together.
Well, you just don't know what's going to happen with the I2C pins on the RTC and LCD when their power is cut. So you just don't want to leave the internal pullups enabled.
In response to the schematic I posted in the first post. Regarding the resistor between the arduino pin (I'm using pin A1) and the MOSFET: I had a 150 ohm, but I was getting very strange, buggy problems, and after whittling my sketch down to simplicity, I found that the next line after I turned the power on to the LCD (setting A1 LOW) would not work.
setup:
pinMode(PowerPin, OUTPUT);
digitalWrite (PowerPin, LOW); //LCD ON
loop:
digitalWrite (PowerPin, HIGH); //HIGH turns off the power
Serial.println("PWR OFF");
...more code
digitalWrite (PowerPin, LOW); //LOW turns on the power
Serial.println("PWR IS BACK ON");
...that last Serial.println command would not work, but print garbage.
I am assuming there's too much outrush of current from the arduino pin to the MOSFET? With 150 ohm, it'd be 33mA? Even if I put a delay() immediately after setting the powerPin LOW, it still ask buggy.
Anyway, I swapped it out for a 1K resistor, and everything works fine. It's just I don't like fixes that I don't completely understand why it's fixed. There's always the question in the back of your mind, is it going to act up again in the end product?