input pin constantly high

The code below produces a constant output message of "nBackPin Value high!" on a Arduino Uno with no hardware attached. I don't understand why? Any1 care to enlighten me? Thanks.

int             nLeftPin = 13;
int             nRightPin = 5;
int             nBackPin = 11;
int             nLeftVal;
int             nRightVal;
int             nBackVal;
int             nState;

void setup() 
  pinMode(nLeftPin, INPUT);
  pinMode(nRightPin, INPUT);
  pinMode(nBackPin, INPUT);

void loop() 
  nLeftVal = digitalRead(nLeftPin);
  nRightVal = digitalRead(nRightPin);
  nBackVal = digitalRead(nBackPin);
    Serial.println("nLeftPin Value high!");
    Serial.println("nRightPin Value high!");
    Serial.println("nBackPin Value high!");

NB, I've also tried other pins for nBackPin including 5, 0 and 1

When you have nothing connected to an arduino pin, it is in a "floating" state. This means that it is not in either on/off state. You need to connect something to it (a resistor to either ground (for low) or +5( for high)).

pin13 has a led attached so should be stable in a low state, but the rest of the pins need a connection.

You cannot measure what isn't there!

thanks for the quick reply but I have tried connecting it to ground and to 5 v and still get the same message. Pin 5 works ok, I can set that to either ground or 5v with no problems.

Are you using a resistor when you connect the pins to +5?

yes, 10K

Sry, I though this problem [u]must[/u] result from something I've done wrong with the program but perhaps not? Now I'm thinking something wrong with the board. I don't have time now but I will look to the board over the weekend.

thanks again.

isenhand: NB, I've also tried other pins for nBackPin including 5, 0 and 1

Pins 0 and 1 are used for serial communication. You should not use them as general purpose IO.

I'm intending to use pin 5 but just checked the other as pin 5 look like it got stuck in hi.

Over the weekend I took the board out of the robot I'm using it in and just tested it on the bench. Check underneath and it looks ok and worked ok. Put it back in the robot and it worked ok but failed again when I attached the other hardware (motor driver board). So, I think the program works ok but I've done something silly on the hardware side.

Thanks for your help.