i'm trying to control my sensors power supply to reduce the current consumption of my project. i'm using ATmega328p that collect information from different sensors (digital and analog sensor) and send it using an xbee.For the xbee part i'm using the sleep mode so i don't think i have a problem with that but for the analog sensor it has its own electronic board that consume 10mA which is too much for an IOT project and even for the digital sensor that consume 1.5 mA it's not acceptable to run all the time consuming 11.5 mA for nothing, that's why i want to control the sensor's power to turn it on only when i need it and switch it off in sleep mode. the problem is, i don't know what device i need to use for something like this. i already know the ULN2003 and L293d but those h-bridges are for motors and using transistor or MOSFET may consume more current.I was thinking if it's enough to power the sensor on using one IO pin as an output since it needs only 3.3v-5.5v and 10mA for the analog sensor and 1.5mA for the digital sensor, but connecting 4 sensors to 4 pins may reduce the output voltage for all of them and i won't be able to turn them on. I'm looking for an advice to how control my sensors to reduce the power consumption. Thank you.
Use a logic-level N-MOSFET to do this. This will require almost no additional power and is very simple to implement.
This is called a low-side switch. You interrupt the common/ground line of the sensor, insert an N-MOSFET. Like this:
Make sure you use a logic level MOSFET. A high signal from the I/O will power up the device, a low signal will turn it off.
Powering your sensors through IO pins could be feasable but you should watch the ATMega's pin voltage drop against the minimum supply voltage for each sensor. At 1.5 mA you'd be fine, but 10 mA would cause a ~0.3 V drop according to Atmel's datasheets and your analog sensors may not like that. Everything is "could" or "may" without knowing the specific sensors. Remember that internally the microcontroller will be using transistors for sourcing/sinking it's IOs and those may not be very efficient for larger-ish currents.
So maybe you could choose your own MOSFET for switching the sensors' supply. It would certainly consume more current than nothing at all but this increase should be much less than your sensors full time current draw. Try to get a low RDS(on) one and it would waste very little energy.
Also remember that powering on the sensors could take some wake up time, during which they could consume more current than they normally do.