I have a small app that works just fine when the Uno R3 board is attached to my Windows computer with the USB cable. However, if I remove the USB cable and power the board with a 9V battery then the program will not work. When the board is attached to the computer the "L" led, near pin D13, is on and is yellow. When the 9V battery is attached the led is off. In both cases, the green led near pin D2 is on.
I suspect the "L" led being on and off may be the key, if I only knew what that key is.
Do you have a line of code that is waiting for Serial to be connected ?
Please post your full sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Using a "smoke detector" 9v battery with Arduino is not recommended because it extremely weak capacity. Depending of the circuit current consumption the battery may emptied in less than 15-20 minutes.
In all my years of working with Arduino, I've never paid much attention to this LED. It's unlikely to be relied upon as a diagnostic tool; the problem is usually obvious from other factors.
Yeah, that's attached to pin 13 on the UNO R3, and is controlled by your code. Maybe you commented out some statement like pinMode(13, OUTPUT);
or, digitalWrite(13, HIGH);
because you had no clue?
Seriously, on this forum, not showing your code is close to a capital offence when asking a question like yours.
I'm just making a guess and will have to do a little more testing. However, it looks like that LED could be an indicator of power level available to the board. I suspect that if I get a fresh battery then the led will start to light up.
I use the "L" LED as a heartbeat for the sketch. If my "L" stops toggling on... off... on... off.. et c. I know my code has severely slowed or stopped.
Yes, a "power only" cable will let you know if the power supply (battery here) is insufficient.
Just an update.
I ordered a 6 AA battery holder to take the place of the 9V battery. Pretty cheap on Amazon.
I put all of the serial print coded back into my sketch and it does not cause an issue with the code running while not connected to the computer. The code runs fine when attached to my phone charger adapter.
There is nothing in my code that does anything with pin 13 and the "L" led. By default it looks like the on/off state of the led is an indicator of the battery power output.
I am 99.52% convinced that my new battery pack will solve the issue. I think that I may have been taking into account that TV remote controls can go months without changing batteries. I just thought that the 9V battery would run for months without issue. Obviously, a bad assumption.