Don't know what the problem is, anyone know

I am a new programmer and maker, and as I was making this "simple" project, I ran into an issue. I don't know why it is not working so can someone maybe look through the code and my Arduino setup. Thanks
Code:
int ledPin = 12;
int buttonPin = 8;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
;
if(digitalRead(buttonPin) == HIGH){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}

When you say it doesn't work, what do you mean by that. What happens? How does that compare with what you expected to happen?

Well that seems to be an important detail that I left out XD. Basically, the LED is supposed to be on while I hold the button, but the LED just doesn't turn on. Thanks for the fast response by the way =p

Sure you've got the led put in the right way round? Try switching the leads on it.

I tried that out and switching the leads from the LED did not work either. I did however take some inspiration from this project here:

and tried to copy it as best I could

I just updated the ohm ?amount? to 10 kOhms for the resistor on the button and 100ohms for the LED

Do you understand how the tactile switches function? You should only use 2 pins (diagonal corners) to get the effect you are looking for. Pin 8 should go to your resistor and one pin of the switch, and the other side of the resistor goes to ground (pulldown). The opposite corner pin of the switch goes to 5V. Sometimes the pins of the switch don't fit in a breadboard well, so check that too.

Hi,
Take the wire that goes from pin 8 and connect it to gnd then to 5V then to gnd, with the button removed.
See if your LED turns on and off.

Do you have a DMM to measure some voltages?

Tom... :slight_smile:

The LED works in the configuration you suggested, but I think it might be the way I am wiring the pushbutton. I also think that the code may have some errors.

tinman13kup:
Do you understand how the tactile switches function? You should only use 2 pins (diagonal corners) to get the effect you are looking for. Pin 8 should go to your resistor and one pin of the switch, and the other side of the resistor goes to ground (pulldown). The opposite corner pin of the switch goes to 5V. Sometimes the pins of the switch don't fit in a breadboard well, so check that too.

I don't understand what you mean by "Pin 8 should go to your resistor and one pin of the switch, and the other side of the resistor goes to ground (pulldown)." Do you want me to lead a wire from pin 8 to a resistor and from the resistor to the switch? If so, then I don't see what you mean by the second part of the suggestion "other side of the resistor goes to ground". Thanks for the help anyways

ok never mind I figured out the solution. I took tinman13kup 's suggestion and finally got the button to power the LED like I wanted it to. thanks for the help everyone =p