Mega 2560 i/o unstable

hi=)

my Mega 2560 r3 is i/o unstable .
When i put cables in digitalinput ports 23-37 it activates the inputs just by putting the cables in.
i programmed the ports as inuts.
Power supply 7,5v 1500mA

#include <Stepper.h>
#include <LiquidCrystal.h>
#include <Servo.h>

Servo myservo;

int pos = 0;
int posa = 0;
const int stepsPerRevolution = 48;

Stepper myStepper(stepsPerRevolution, 12,13);
LiquidCrystal lcd(49, 48, 51, 50, 53, 52);

const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

////////////////////////////////////////////
const int buttonPin = 22;
const int buttonPinrr = 23;
const int buttonPin2 = 24;
const int buttonPinrr2 = 25;
const int buttonPin3 = 26;
const int buttonPinrr3 = 27;
const int buttonPin4 = 28;
const int buttonPinrr4 = 29;
const int buttonPin5 = 30;
const int buttonPinrr5 = 31;
const int buttonPin6 = 32;
const int buttonPinrr6 = 33;
const int buttonPin7 = 34;
const int buttonPinrr7 = 35;
const int buttonPin8 = 36;
const int buttonPinrr8 = 37;
///////////////////////////////////////////

int buttonState = 0;
int buttonStaterr = 0;
int buttonState2 = 0;
int buttonStaterr2 = 0;
int buttonState3 = 0;
int buttonStaterr3 = 0;
int buttonState4 = 0;
int buttonStaterr4 = 0;
int buttonState5 = 0;
int buttonStaterr5 = 0;
int buttonState6 = 0;
int buttonStaterr6 = 0;
int buttonState7 = 0;
int buttonStaterr7 = 0;
int buttonState8 = 0;
int buttonStaterr8 = 0;
//////////////////////////////////////////

int x = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(buttonPinrr, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPinrr2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPinrr3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPinrr4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPinrr5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPinrr6, INPUT);
pinMode(buttonPin7, INPUT);
pinMode(buttonPinrr7, INPUT);
pinMode(buttonPin8, INPUT);
pinMode(buttonPinrr8, INPUT);
pinMode(45, OUTPUT); //Relä 1
myservo.attach(44); // attaches the servo on pin 9 to the servo object
//////////////////////////////////////////

pinMode(10, OUTPUT); // gör att pin 10 är output och används till servo för dosör
pinMode(4, OUTPUT) ; //Drar i programmet
pinMode(14, OUTPUT) ; //BLINK

Serial.begin(9600);

pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

Serial.begin(9600);

myStepper.setSpeed(600);
}

void loop() {

//// help please =))

If your inputs are GND i.e. u are "switching the negative", use internal pull-ups.
If your inputs are +5V i.e. u are "switching the positive", use external pull-down resistors.

This video explains pull-up resistors and floating pins.

Which is what you're doing wrong.

Also, naming variables "buttonpin2" is a very bad practice. Why not name it "leftButton" or whatever the button's function is? That way, when you read the code it reads more like this:

thanks now it works

//S