(solved) Newbie Question : Do I have a dodgy board?

Hiya... just working my way through various tutorials... and am beginning to suspect that all is not well with this arduino (duemilanove ATmega 168).

So I wrote a little programme to test input on every pin...

/*

  • Switch test program
    */

int s1 = 1;
int s2 = 2;
int s3 = 3;
int s4 = 4;
int s5 = 5;
int s6 = 6;
int s7 = 7;
int s8 = 8;
int s9 = 9;
int s10 = 10;
int s11 = 11;
int s12 = 12;
int s13 = 13;

void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(s1, INPUT);
pinMode(s2, INPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);
pinMode(s5, INPUT);
pinMode(s6, INPUT);
pinMode(s7, INPUT);
pinMode(s8, INPUT);
pinMode(s9, INPUT);
pinMode(s10, INPUT);
pinMode(s11, INPUT);
pinMode(s12, INPUT);
pinMode(s13, INPUT);
}

void loop() // run over and over again
{
Serial.print(digitalRead(s1));
Serial.print(digitalRead(s2));
Serial.print(digitalRead(s3));
Serial.print(digitalRead(s4));
Serial.print(digitalRead(s5));
Serial.print(digitalRead(s6));
Serial.print(digitalRead(s7));
Serial.print(digitalRead(s8));
Serial.print(digitalRead(s9));
Serial.print(digitalRead(s10));
Serial.print(digitalRead(s11));
Serial.print(digitalRead(s12));
Serial.print(digitalRead(s13));

Serial.println("");
delay(100);
}

And when I upload it - with absolutely nothing connected to the board, it outputs this:

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

1110000000000

Which makes it look as though the first 3 pins are permanently receiving "1"

Is that what it's supposed to do?

It also does this thing where if I set any of the 0 pins above to high, not only does that pin go to 1, but several of the neighbouring ones do as well.

Any help most appreciated

Nick

First point is that serial communications with the PC uses pins 0 and 1, so you shouldn't be setting pin 1 to input mode as it's the transmit pin to the usb serial link. So don't use pins 0 and 1 until you gain more experiance and understand the trade-offs of when you can and cannot use those pins.

Second, you should be aware of what are called 'floating input pins'. When there is nothing wired to a digital input pin it has no valid logic voltage reference and is just responding to circuit noise as to if it will read as a high or a low. One thing you can do to prevent that floating condition is to turn on the internal pull-up resistor for each pin you want to play with. That way it will read as a steady 1 with nothing connected to the pin, and read as a 0 if you wire a jumper (or switch) wired to a ground pin.

Here is how you enable the pull-up:

pinMode(s3, INPUT); // set the pin as a input pin
digitalWrite(s3, HIGH); // this turns on the internal pull-up for this pin

Lefty

Ah - I'm with you. Fantastic thank you.

Nick