I'm doing a hobby project at home involving an atmega128 at 5V. It's going to run from battery, but during development, I'll need some other power supply. What is the cheapest and most simple solution?

Is there a way to pull 5V from USB? What is a component that converts the mains to 5V called? I'll need around 5 mA.

  • 1
    \$\begingroup\$ Will your Atmega128 operate with just 5 mA? \$\endgroup\$ Jun 19, 2013 at 7:46
  • \$\begingroup\$ The data sheet claims 0.4 mA at 1MHz and 1.8V, so that seems reasonable. (If I'm reading it correctly. I'm new to this.) \$\endgroup\$
    – Andreas
    Jun 19, 2013 at 8:04
  • 1
    \$\begingroup\$ @Andreas: Consider that you probably also have to drive peripherals (using I/Os) with the controller. Further, the current consumption is highly dependent on what internal components you use. And you may want to increase clock speed at some point. Regardless of this, 500mA on USB (2.0) is plenty. \$\endgroup\$
    – Rev
    Jun 19, 2013 at 8:08
  • \$\begingroup\$ @Rev1.0: Thanks, I miss a lot of these details. What do you mean by internal components? \$\endgroup\$
    – Andreas
    Jun 19, 2013 at 8:13
  • \$\begingroup\$ @Andreas Basically with a microcontroller such as the ATmega, there are several functional blocks (internal components), such as timers, ADC and so on. Each of these modules consumes power when enabled and operating. Datasheet ratings are typically best case, since actual consumption would be highly dependent on what your code is doing, and what modules are activated. Also, an average consumption is often calculated with the MCU in low power sleep mode a lot of the time, to make the figures enticing. Reality bites. \$\endgroup\$ Jun 19, 2013 at 8:35

1 Answer 1


Mains to 5V power supplies with USB connectors are plentiful and cheap. Buy online from any electronics retailer or go to a phone shop.

Is there a way to pull 5V from USB?

USB is designed for that, you can draw at least 100 mA at 5V from any true USB port on a computer, USB hub or any USB host device.

What is a component that converts the mains to 5V called?

It's called a "5V power supply".

  • \$\begingroup\$ Could I buy this USB-DC plug and cut the DC part up to access the two cables inside, that I could then wire to my board? The USB end would go into my laptop. Would there be any risk of damaging the laptop this way? There would be no other power supply. \$\endgroup\$
    – Andreas
    Jun 19, 2013 at 9:49
  • \$\begingroup\$ @Andreas: Yes you can chop the cable. There are always risks, especially if your ATMega128 hobby project is to control a 240 Volt device (say) and you don't take adequate precautions. For blinking LEDs the risk is negligible but don't expect me to take the blame if your PC catches fire and burns down New York unleashing a zombie apocalypse that destroys the USA ;-) \$\endgroup\$ Jun 19, 2013 at 10:44
  • \$\begingroup\$ You can use any USB cable you may have laying about (they seem to multiple when left alone in dark corners). Cut off the square end and strip the sheath. There are 4 wires, "usually" Red=+ Black=- and two data wires which (again) "usually" are of a thinner gauge - cut those off. Use a multimeter to verify you are getting +5v and within whatever tolerance you need. Personally, I don't trust the USB power source to be exactly 5V, my laptop gives between 5.1 and 5.3 volts for whatever reason. \$\endgroup\$
    – Ron J.
    Jun 19, 2013 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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