Arduino receives HIGH when the button is LOW I just got a simple scheme where i have a button connected to the 5V connector and to the 4th digital PIN and then i got a led connected to the 2nd PIN and to the GND. When i press the button the LED should switch on and when i don't press it, it shouldn't bright. The problem here is that i got a True value when i'm not pressing the button. What could it be? Here goes the code:

int Button=0;

void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);        
pinMode(4, INPUT);         
}

void loop() {

Button = digitalRead(4);

Serial.println(Button);

if (Button == HIGH) {

  digitalWrite(2, HIGH);

} else {

  digitalWrite(2, LOW);

}

  delay(200);

}
You will need a pushbutton connected as follows:

The signal labeled Vout will connect to digital pin 4.



Explanation:

When the pushbutton is NOT pressed, no current flows through the resistor, and Vout = 0V. When the pushbutton IS pressed, current flows through the resistor, and Vout = 5V.

This resistor is called a pull-down resistor, because it pulls the signal down to ground. A pull-up resistor would reverse the operation of the pushbutton (i.e. Vout = 5V when not pressed, and 0V when pressed.)