I am a beginner at electronics and recently got an arduino and the Arduino Project Handbook and I am having trouble with the push button led project.
I have followed the directions and have the correct resistors but every time I go to press the button the led stay on and if I touch the cable or put my hand near the cable the led comes on.
am I missing something?
Below is the Circuit and Code I am using....
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}