Problem with powering I2C divices .


I am working a project and I need sleep mode to extend battery life. I put the atmega 328p on a breadboard and its working fine. My sleep time is about 5min and during this time a let my 3 I2C devices running on 5V from the power supply (will be batteries when the project is finish). So I was thinking instead of having the power on this devices all the time to power them from an atmega pin and right before the atmega go to sleep I will turn this pin to 0 and when I wake up I will put it back to 5V. When I try this the program stop working. After some reading I am thinking it has to do with the I2C pull up resistors or something like this. Can someone help me please?

“the program stop working” is not helpful. Please provide more details. Is this not your own program?

An ATMega 328P pin is limited to 40 mA, and even then will not be putting out 5 volts. 25 mA is a more practical maximum. How much current are your three I2C devices using?

A logic pin cannot supply more than a tiny amount of power, and its not really capable of handling
decoupling capacitor inrush current, or of being a stiff enough voltage source for a supply - the Arduino
output drivers are about 30 to 40 ohms.

You would normally use a PNP transistor or p-channel logic-level MOSFET to switch power to a peripheral
like that. A small PNP transistor is probably the simplest way. You do need to know the sort of current
the load takes, divide that by about 10, to determine the base current (and thus the base resistor) needed.

Some chips have a handy enable / shutdown input you can use to avoid having to switch the power like this, always worth checking the datasheet.

@nikis93 is currently enjoying a short forum timeout for posting the same question three times in different parts of the forum.