My button control working in reverse I built this circuit to learn button control. 



But my code (or button) is working in reverse. I want to initialize led flash effect when the button is pressed with this code

buttonState = digitalRead(8);
if (buttonState == HIGH)
  doFlash();


Instead the effect runs continuously and pauses if I push and hold the button. If change the condition as if (buttonState == LOW) code is working as expected. (Effect starts when I push the button.)

This is just the opposite of what I read in tutorials. What is wrong in my circuit or code?

Full code:

 void setup(){
  for(int i=2;i&lt;=6;i++) 
  pinMode(i,OUTPUT);
  pinMode(8,INPUT_PULLUP);
 }

 void loop(){
  int buttonState;

  buttonState = digitalRead(8);
  if (buttonState == LOW)
    doFlash();
 }

void doFlash() {
    int i;
    for (i=2;i&lt;=6;i++) {
        digitalWrite(i,HIGH);
        delay(100);
        digitalWrite(i,LOW); 
    }   
    for (i=6;i&gt;=2;i--) {
        digitalWrite(i,HIGH);
        delay(100);
        digitalWrite(i,LOW); 
    }
}
This behavior is expected: INPUT_PULLUP means the pin is pulled up via the internal pull up, i.e. it will read as high if not connected externally. 

With your push button you connect it to ground (0 volts), thus bringing it to low level and it will read as low. Therefore, in your code, you need to check for low level (LOW) to check if the button is pressed (as you found out by changing the code).