I am just learning Arduino right now. I am trying to make a program where you push a button to turn on an LED using digitalWrite. However, when I push the button the LED stays on even once I have let go of the button. I am not sure what is wrong because I followed a tutorial for this program. I have attached my code and picture of the wiring.
Never post screen shots of code, error messages or serial monitor output. Always copy the text of those things and paste it into your post using code tags. Thankyou.
Welcome. While I'm sure you're impatient to get an answer, please go back and read the How to.
In particular, DO NOT post code pictures. In the IDE, copy for forum, then paste into your message.
Again, Welcome!
Your button is wired incorrectly. Move the black wire to breadboard hole g20.
Better still, remove the resistor, the connection from 5V to the button, connect the black wire to the diagonally opposite pin of the button from the ground connection, and use mode INPUT_PULLUP. The pin will read LOW when the button is pressed. This is not weird at all.
This post doesn't belong in the community section because it is not a community matter, it is a technical matter. Therefore I have moved it here.
Also it is not even a coding matter, but a hardware mistake you are making.
Sorry for posting in the wrong place. First time posting. I managed to fix it thanks to y'all. Appreciate the help
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.


