Input Pullup is always HIGH ! :°

Hello All,

I’m trying to understand what is wrong with me and the Input Pullup!

Let me explain, I’m trying to build a dice with LED, it is supposed to start when i Hit the button.

Easy.

I am supposed to use INPUT PULLUP function but when I do the result is always the same : 1 and the Dice restart alone, over and over again with this code :

(Button between GND and Pin No 7)

int ledHautGauche = 2;
int ledBasGauche = 3;
int ledCentre = 4;
int ledHautDroite = 6;
int ledBasDroite = 5;
int buttonPin = 7;
boolean buttonState;

//=================================================
//===================== FONCTION D'INITIALIZATION =
//=================================================

void setup() {
  //mise en mode OUTPUT des pins 2 à 6 et positionnement en LOW
  for (int t = 2; t < 7 ; t++) {
    pinMode(t, OUTPUT);
    digitalWrite(t, LOW);
  }
  pinMode(buttonPin, INPUT_PULLUP);
  randomSeed(analogRead(0));
  Serial.begin(9600);
  setZero();
}

//=================================================
//============================= BOUCLE PRINCIPALE =
//=================================================

void loop() {
  int temp = 1;
  buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);
  delay(100);
  if (buttonState){ {
    int result = random(0, 6);
    for (int t = 0; t < 4; t++) {
      for (int nb = 0; nb < 6; nb++) {
        affichage(nb);//appel de la fonction d'allumage des LEDs
        delay(temp * 100);
      }
      temp = temp + 1;
    }
    for (int nb1 = 0; nb1 < result; nb1++) {
      affichage(nb1);//appel de la fonction d'allumage des LEDs
      delay(600);
    }
    delay(3000);
  }
}
}

BUT, if I set the PIN7 as an OUTPUT, it is working! :o Like this :
(Button between 5v and Pin No 7)

//=================================================
//================ DECLARATION VARIABLE GENERALES =
//=================================================
int ledHautGauche = 2;
int ledBasGauche = 3;
int ledCentre = 4;
int ledHautDroite = 6;
int ledBasDroite = 5;
int buttonPin = 7;
boolean buttonState;

//=================================================
//===================== FONCTION D'INITIALIZATION =
//=================================================

void setup() {
  //mise en mode OUTPUT des pins 2 à 6 et positionnement en LOW
  for (int t = 2; t < 7 ; t++) {
    pinMode(t, OUTPUT);
    digitalWrite(t, LOW);
  }
  pinMode(buttonPin, OUTPUT);
  randomSeed(analogRead(0));
  Serial.begin(9600);
  setZero();
}

//=================================================
//============================= BOUCLE PRINCIPALE =
//=================================================

void loop() {
  int temp = 1;
  buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);
  delay(100);
  if (buttonState){ {
    int result = random(0, 6);
    for (int t = 0; t < 4; t++) {
      for (int nb = 0; nb < 6; nb++) {
        affichage(nb);//appel de la fonction d'allumage des LEDs
        delay(temp * 100);
      }
      temp = temp + 1;
    }
    for (int nb1 = 0; nb1 < result; nb1++) {
      affichage(nb1);//appel de la fonction d'allumage des LEDs
      delay(600);
    }
    delay(3000);
  }
}
}

I have been working a bit too long on the project, I am not sur if I am confused or it my arduino is damaged…

Thanks for your help!

if (buttonState){ {

should probably be

if ( ! buttonState){ {

if the button is wired between ground and the arduino pin.

If you use INPUT_PULLUP and the button is wired from pin to ground, a pressed button gives a LOW, not a HIGH.

And if you connect 5V via the button to a pin that is configured as output, you have more than likely blown up the pin at the moment that the output was set LOW and you pressed the button.

First thanks for your answers! I didnt expected anything so fast!

6v6gt, I have tried all combinason, but it wasnt working the arduino keep sending HIGH! Whatever I do with my Button!

sterretje: If you use INPUT_PULLUP and the button is wired from pin to ground, a pressed button gives a LOW, not a HIGH.

And if you connect 5V via the button to a pin that is configured as output, you have more than likely blown up the pin at the moment that the output was set LOW and you pressed the button.

Sterretje, Yeah I am pretty sure I have damaged the Arduino, I dont really know how. But this has happen before the connexion to 5v. I tried on another Arduino and same, the mega was waiting for the push on the button, once I did it never stopped to play the dice over and over again!

I Guess I killed 2 Arduino today!

I with I can Understand why, and how it comes that it's not PERFECTLY working with the PIN as OUTPUT, and plugged between 5v and Pin! Totally insane!

the arduino roll the dice each time I press the button!

I need now to test all my pins... on Both Uno and Mega!

To Close the Topic,

Pin are not damaged finally! here is the code that’s working :

//=================================================
//================ DECLARATION VARIABLE GENERALES =
//=================================================
int ledHautGauche = 2;
int ledBasGauche = 3;
int ledCentre = 4;
int ledHautDroite = 6;
int ledBasDroite = 5;
int buttonPin = 7;
boolean buttonState;

//=================================================
//===================== FONCTION D'INITIALIZATION =
//=================================================

void setup() {
  //mise en mode OUTPUT des pins 2 à 6 et positionnement en LOW
  for (int t = 2; t < 7 ; t++) {
    pinMode(t, OUTPUT);
    digitalWrite(t, LOW);
  }
  pinMode(buttonPin, INPUT_PULLUP);
  randomSeed(analogRead(0));
  Serial.begin(9600);
  setZero();
}

//=================================================
//============================= BOUCLE PRINCIPALE =
//=================================================

void loop() {
  int temp = 1;
  buttonState = digitalRead(buttonPin);
  Serial.print(buttonState);
  delay(100);
  if (!buttonState){ {
    int result = random(0, 6);
    for (int t = 0; t < 4; t++) {
      for (int nb = 0; nb < 6; nb++) {
        affichage(nb);//appel de la fonction d'allumage des LEDs
        delay(temp * 100);
      }
      temp = temp + 1;
    }
    for (int nb1 = 0; nb1 < result; nb1++) {
      affichage(nb1);//appel de la fonction d'allumage des LEDs
      delay(600);
    }
    delay(3000);
  }
}

With Button between Gnd and digital Pin 7

Thanks for your help!