I am wondering if it is possible or even safe to power peripherals like sensors or bluetooth modules from the ATmega328P by setting pins of the microcontroller (uC) to high given that the peripherals are within the current sourcing capabilities and voltage limits of the pins.

I'm asking this because it seems more convenient to enter power-down mode on the uC and control the high/low of the switches in software before and after this mode to turn on or off the peripherals. I'm probably missing something and I'd like some clarification on the above.

up vote 7 down vote accepted

If you source much current from the uC, it's likely for its output voltage to drop below what's acceptable for your peripheral. Changes in current consumption can also cause ripple at the output pins because of the uC's output resistance.

Your peripheral is likely to have power decoupling and filter capacitors. Charging them at the first moment will cause inrush current that can be outside current limits acceptable for your uC. It may either cause the capacitors to take a long time to charge at each power-up or damage your uC.

Anyway, it's better to have a proper power key (an external MOSFET, for example) than to power anything from the uC output except the case when the specific uC output is designed to be used as a power source.

  • 1
    The mosfet way is the best option for sure. – Vladimir Cravero Apr 29 '14 at 14:37

Microcontroller should not have problems when you drain current from its pins below limits.

But you have to keep in mind voltage drop across MCU's output driver. It may cause voltage to be lower than expected (see Fig 35-23,24, note also, they give typical, not min-max values). See if your perpherial accepts wide enough voltage range while operating. If you need voltage regulation for peripherial when it is better to get regulator with dedicated enable pin, rather than powering it from MCU.

Also internal driver resistance may cause interference through power line. You may need filtering capacitor. Then, you should check if MCU outputs tolerant to capactive or short-circuit loads (quick look in datasheet gives me nothing).

E. g. it is common to power LEDS, but very uncommon to power IC's of any sort.

It may be okay, but there are a couple of gotchas. First, you want to make sure that there is not excessive voltage drop at the maximum peak current that the device draws (and maximum ambient temperature and minimum supply voltage). Some things, like your Bluetooth module example, may draw current in bursts that far exceed the average current, and the voltage must not dip excessively during those peaks. For Bluetooth, those will likely easily exceed the capacity of a port pin.

Secondly, it's generally a really bad idea to run an unprotected port pin outside of an enclosure due to lack of substantial ESD protection, short circuit protection, protection against external voltages being applied and so on. So, that would tend to rule out external sensors unless you add some circuitry to protect the micro against damage and upsets.

If you want to run (say) a temperature or humidity sensor that draws a few hundred uA from a port pin, and can verify that the voltage drop of the pin is not excessive (and that the lack of a bypass capacitor is not a problem) then it may be a good way to measure the local PCB temperature or humidity and allow zero-power shutdown of the sensor when it is not being used.

Otherwise, it's quite easy to add a hefty high-side switching using a tiny multi-ampere p-channel MOSFET that can control the power, and to add a TVS for transients and a polyfuse and or other short circuit protection. For high reliability applications, it may be best to derive the supply that goes off-board from a separate regulator so you're not giving the outside world any kind of a window into what powers the microcontroller.

It's perfectly fine to do this as long as the peripheral consumes less than the rated current of the output pin. Typically I'd avoid any draw more than 20mA for the atmega328p.

While there will be some voltage drop, the CMOS design of the atmega328p uses mosfets internally for the I/O, and the voltage drop will be minimal as long as you don't draw too much current.

If you need more current, use an external mosfet.

As long as you are under the individual (per I/O) limits of the chip, the total (all I/O added together) limits of the chip, and within the operating parameters of the peripheral you're powering, you will be fine.

  • I think you may have understated the risks of running directly off an I/O that the other answers have hit upon. – rjp Apr 30 '14 at 14:01

If you are in doubt, use a MOSFET. If you don't want to shop online, radio$hack generally has one or two of them. They are really great; I've used them for driving servos. And they are pretty inexpensive. Basically they are special transistors where the arduino can act as the gate and allow a larger current/voltage source to supply the power. The arduino merely can cut it off, like opening a circuit or closing it.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.