random analogRead on resistor when arduino powered by batteries

On my arduino uno r3 I have 12 buttons on a resistor ladder connected to analog pin 0.

The buttons also have lamps on them, so I have 12 1,5v AA batteries in series to supply voltage for the lamps, and also a 9v regulator (l7809cv) to use the 18v to produce 9v for the arduino board. This has been working fine until now. When I shift between pushing two buttons (thus starting one sample on a waveshield and stopping another) a third random sample+button-light gets activated. This doesn't happen when no buttons are being pushed, and it hasn't happened before.

I then tried running it on USB-power instead (without the lamps), and it was all fine.

So I figured it must have something to do with the battery-powering.. no? So I tried measuring voltage on the output pin of the regulator, both when pushing buttons and not, and this gave me a reading around 9v, sometimes dropping just below 9v. This should be more than enough for the arduino on-board regulator, right? I mean - could this really make changes in the analogRead that I'm doing?

Here's my code: http://sorenandreasen.com/machine-nr-1-code/

EDIT: In the code, if I outcomment everything that has to do with pin 0 and 1, and instead initializes serial communication and asks it to constantly print out the analogRead-value in my loop - then it works fine. How could this be? I really don't understand how that has any effect on the readings

A lot of the code could be consolidated in loops

digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(15, LOW);
digitalWrite(16, LOW);
digitalWrite(17, LOW);

Yes I know, thank you but that's not really relevant to the issue

If your supply voltage has changed then the values you're getting back from analogRead may have shifted slightly. Suggest you print them out and adjust your thresholds if necessary.

There's no obvious way for serial output to affect the analog read results unless you have something connected to pins 0 and 1 - do you have anything connected?

Your posted code is completely unindented which makes it hard to read. Various minor typos jump out on a scan through - none that would cause these symptoms, but there are enough of them to make me wonder whether there may be some other software bug in your code which is causing this.

PeterH:
Your posted code is completely unindented which makes it hard to read. Various minor typos jump out on a scan through - none that would cause these symptoms, but there are enough of them to make me wonder whether there may be some other software bug in your code which is causing this.

I should have elaborated on my post. What I was implying is that the code is very jumbled and redundant making it hard to read.

Yes, please do a CTRL-T to format the code and re-post it here using the code tags (the # button in the Reply section).