I can't get a simple button to work

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

I can't get a simple button to work

Post by bgambrell »

I am apparently very bad at this.

I have a button, which is essentially a switch, and I've got it set up as a pull-down. I have some simple arduino code that reads the corresponding pin and if it is HIGH, it turns on the LED_BUILTIN.

I press the button. Nothing happens.

Code: Select all

int btn11Pin = 11;
int btn11State = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(btn11Pin, INPUT);
}

void loop() {
  btn11State = digitalRead(btn11Pin);
  if (btn11State == HIGH) {
    digitalWrite(LED_BUILTIN, HIGH);
  } else {
    digitalWrite(LED_BUILTIN, LOW);
  }
  
}
I'm doing this on a Feather Bluefruit LE 32u4

Image
Last edited by bgambrell on Tue Sep 14, 2021 12:54 pm, edited 3 times in total.

User avatar
adafruit_support_bill
 
Posts: 88039
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

Post by adafruit_support_bill »

If you post a photo of your circuit we can try to spot the problem.

User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

Post by bgambrell »

edited

User avatar
adafruit_support_bill
 
Posts: 88039
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

Post by adafruit_support_bill »

Try turning your button 90 degrees. The two pins you are connected to may be connected together internally.

User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

Post by bgambrell »

Not the issue. I can wire the pin directly to the logic power and it still does nothing.

Is there a different way to reference the pins?

User avatar
adafruit_support_bill
 
Posts: 88039
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

Post by adafruit_support_bill »

What do you have connected to pin 13?

User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

Post by bgambrell »

It was grounded but I removed it from ground and now the button is sort of working. The LED is very dim when I press the button. Not as bright as it should be.

User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

Post by bgambrell »

I decided off-hand to re-upload my sketch. And now it works! I am happy because it works. I am sad because I do not understand what was happening.

User avatar
adafruit_support_bill
 
Posts: 88039
Joined: Sat Feb 07, 2009 10:11 am

Re: I can't get a simple button to work

Post by adafruit_support_bill »

Pin 13 drives the on-board LED. With it shorted to ground, it cannot not go HIGH to turn on the on-board LED. (That is also a good way to burn-out the output drivers for the pin.)

User avatar
bgambrell
 
Posts: 6
Joined: Tue Sep 14, 2021 12:07 pm

Re: I can't get a simple button to work

Post by bgambrell »

Thank you!

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”