I am having trouble getting my Arduino Uno to run my code when I disconnect it from my computer.

I have a 9V battery to power it and it is turning on, however, it is not doing anything at all. What can I do to make it run the code when it is using the battery and not connected to the computer?

  • You should probably give some indication in the question on how you know it is behaving differently between battery power and usb power. Also given that 9v are not particularly good batteries beyond their ability to produce 9v, you may want to say what else you have connected to the board.
    – timemage
    Nov 10, 2020 at 18:00
  • If you use a 9V block battery, recycle it and buy better batteries. You could use a series of AA batteries
    – chrisl
    Nov 10, 2020 at 18:15
  • 1
    how do you know that the arduino is doing nothing?
    – jsotola
    Nov 10, 2020 at 18:53
  • 3
    Please provide more information. What is the schematics? What is the code? Nov 10, 2020 at 20:33
  • 1
    What components do you have in your project? Specifically, what are you connecting to the 5V line?
    – Duncan C
    Nov 10, 2020 at 21:24

2 Answers 2


Use a fresh 9V battery, or better, a proper power supply or some AA batteries in series, just to make sure the power supply isn't the problem.

BTW on some Arduinos (though probably not yours) it often pays off to check if there is a while (!Serial); or some such in the code. If there is, it is blocking code execution until the USB is connected and the serial monitor is opened.

  • 1
    A battery a day keeps the environment decay. Nov 10, 2020 at 20:35
  • 1
    "For testing only". I never use primary cells myself.
    – ocrdu
    Nov 10, 2020 at 20:38
  • 1
    while (!Serial); would have no effect on an UNO.
    – timemage
    Nov 10, 2020 at 23:35
  • 1
    @timemage: People with different Arduinos will also read this Q&A without looking at the tag, so I thought it would be a good idea to include it.
    – ocrdu
    Nov 11, 2020 at 19:23
  • 1
    @ocrdu: I was looking at more as UNO having been in the question, the while loop is thing is a more of a rabbit hole. I suppose you could mark it as "for some boards this is also a problem." I don't have really strong feeling about it really. In case you're wondering, I didn't vote down your answer.
    – timemage
    Nov 11, 2020 at 19:31

And Arduino should run the last program installed to it when you apply power to the barrel connector. IT powers up, does a reset, and begins executing the sketch that's installed.

As others have mentioned, the small rectangular 9V batteries have very low current output and total power storage. You will run a fresh 9V battery down to nothing in a short time with just an Arduino, and with other components also drawing power it will happen even faster. I suggest getting a ≥ 1 amp 7V - 9V DC transformer and plugging that into the barrel connector.

You need to tell us what components you are using in your project and their current requirements.

If you are just running a "bare" arduino and very little else then you should get like 24 hours out of a fresh 9V battery, as mentioned by @ocrdu

  • 2
    All pins together can't source more than 150mA. Why should he use a 1000mA power supply? Nov 10, 2020 at 20:32
  • @Duncan-C: Could be it, but power consumption is not THAT bad; 500mAh will run some Arduinos that aren't doing too much for about 24 hours.
    – ocrdu
    Nov 10, 2020 at 20:40
  • I did find some that are 9V 1200mA batteries would these suffice?
    – JohnT
    Nov 11, 2020 at 2:56
  • You mean 1200 mAh? (that stands for milliamp-hours. It tells you the total power storage capability of the battery. A 1200 mAh battery can put out 1200 milliamps for an hour. (Or 120 milliamps for 10 hours. You just multiply current by time).
    – Duncan C
    Nov 11, 2020 at 13:56

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