Is it safe to power things from outputs?

I have a sparkfun accelerometer wired like this:

AN5 | VDD
AN4 | VCC
AN3 | YA
AN2 | XA
AN1 | YP
AN0 | XP

It works by setting AN5 to 5V and AN4 to 0V.
But i want to know if it’s safe to design this way, or do i should use external source (for example arduino 5V pin) to power it?

Thanks

The Atmega can source a fair amount of current from it's I/O pins (a number of mA anyway). Many designs, like the BlinkM and the Wii nunchuck adapter, use the 'analog' pins to supply the power connections. Personally I've used this to power analog sensors and such without issue.

Look at your sensor's datasheet and see how much current it draws. Look at the mega168 datasheet and see how much current you can safely source using an I/O pin (I believe it's 40 mA, if I remember right). If the maximum current draw of the sensor is less than the I/O pins maximum current rating, you can safely power your sensor from the I/O pin. Note that some sensors can have low average current draws but might in reality draw large currents in short bursts (e.g. sharp IR distance sensors); you do not want to power these from an I/O pin if the bursts exceed the maximum I/O pin ratings.

Also, I recommend against using I/O pins for both power AND ground, because it's just too easy for you to make a mistake in your code and accidentally reverse the power connections to the device, thereby destroying it (and possibly your I/O pins in the process). Why not hard-wire VCC (are you sure VCC is GND? Usually both VCC and VDD refer to positive supply voltages) to GND and use AN5 to deliver power to the device (drive it high for "on", drive it low or set it as an input for "off")?

  • Ben

sorry, it's not VCC but GND hehe finally i'll drive from the 5v pin. thanks!

Look at your sensor's datasheet and see how much current it draws. Look at the mega168 datasheet and see how much current you can safely source using an I/O pin (I believe it's 40 mA, if I remember right). If the maximum current draw of the sensor is less than the I/O pins maximum current rating, you can safely power your sensor from the I/O pin.

I thought it would be useful to add a comment on this.

The outputs may be able to supply 40mA, but that will not be at the full VCC rail. As the current supplied increases, the output coltage will decrease, although it will still be considered a logic 1.

If your external circuitry needs 5V to work, you should not assume that the AVR chip will supply that.

There is data for this in the data sheet, but I don't have it to hand right now.

Mike

This data starts around page 328 of the current ATmega168 datasheet.

Theres a graph about sourceing current (logic high):

and one about sinking current (logic low):

These are esy to read, pick the temperature your interested in, find the amount of current your drawing, and read across to see how much voltage drop to expect. Alternately, look at how much voltage drop you'll allow (1V is normal for I/O) and find the current draw you're allowed. This is where people come with the 40mA number.

Your sensors datasheet will have specifications on the minimum VCC levels and it's peak current draw. Using the peak current draw, find the voltage drop on both graphs and subtract the sink voltage from the source voltage (because your both sinking and sourcing current). If you end up with a number larger than your sensors minimum VCC level, you should be OK.

It is interesting to note that the ATmega is nearly identical in sourcing and sinking current.

That's great - thanks for posting the graphs, spiffed.

Regards,

Mike

That’s great - thanks for posting the graphs, spiffed.

Anytime, datasheet dissection was pretty much my full-time job as an intern. :stuck_out_tongue: