Arduino Uno doesn't work properly when NOT powered through USB

Hi everyone!

The circuit I'm building is a fairly simple motion activated motor, consisting of a button, an LED, and a motor. The button starts out as "false" and the LED is "low", meaning the motor is not sensitive to motion. Then when the button is pushed it becomes "true" and the LED becomes "high", which indicates that the motor is now sensitive to motion. Then, I have a simple if statement that turns on the motor if the analog input level is more than a certain number (i.e. when something passes in front of the sensor). I will be putting this on a small battery powered car so that it is initiated by another passing car.

When the Arduino is powered through USB from a computer, I can let the motion detector sit there all day and not trigger the motor until something actually crosses its path (like it's suppose to). I can also watch the serial monitor and see the different values the motion detector is inputting, with none of them being above the critical level until something actually passes in front of it. This leads me to conclude that both my circuit and sketch work. However, my problem is that when I power the Arduino using a 9V battery connected by a 2.1mm power plug (that I soldered myself) instead of by USB, the circuit no longer works and become quite unpredictable! When I press the button to activate the motion sensitive motor, the motor goes off within a matter of seconds regardless if anything passes over it. Can anyone explain what might be happening and any solutions? My circuit would be rather useless if I had to connect my car to a computer for it to work...

Any help would be greatly appreciated. Thanks in advance!

Is the 9V battery one of those small rectangle batteries?

If so, it is probably dead or close to it. Their current capacity is so low one would be exhausted in a matter of minutes with a high current draw device like a motor.

Also are the motors powered directly from the battery or through a regulator (like the 5v reg used when you aren't powered through USB. )

Yes, I am using the rectangular 9V batteries and I believe that might be the problem...

"The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts."

Found the above on the Arduino Uno website. Just checked my battery and it was supplying 6.8V, even though I bought it this morning! Just for clarification, this is the 9V that is connected to my Arduino, not my motor, that was causing me problems. I guess I'll need a ample supply of 9V batteries.

Thanks for the help!

Use Lithium if you can. 2-3 times the capacity of alkaline, and they hold their output voltage for longer. Alkaline drops off relatively quickly.

Coincidently I seam to be having the same problem as above.

The code and circuit I have run perfectly when connected up to my laptop or any computer. But when connected to an external power supply the analogRead input is constantly taking a reading of 1023.

I’ve narrowed it down and its defiantly a problem with the analogRead

Ive checked the code on a few 5v pro mini boards and a regular duemilanove. The pro minis running off 9v PSUs and the TTL cable to USB conversion.

Any help solving this problem would be greatly appreciated