I Am New To Arduino. I Was Tryıng To Make A Basic Program That If Button Is Pressed Then Turn The Led On else Turn the led off. I Am Using Arduino Uno: Here Is Code
const int led = 13;
const int btn = 12;
void setup()
{
pinMode(led, OUTPUT);
pinMode(btn, INPUT);
}
void loop()
{
if(digitalRead(btn) == HIGH)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
I Connected 5v to "+" on breadboard And Connected GND to "-" On breadboard. I Connected Led's Little pin to gnd and long pin to 13rd pin with 220ohm resistor on arduino via breadboard.
I Connected button's pin to gnd via 10k ohm resistor. second pin to 5v and third pin to 12nd pin on arduino via breadboard. I Uploaded code without any errors. Led Turned On Itself even if i did not pressed button. Then I pressed Button And Nothing happened. Led Is Still On. I tested led without button before like a code: turn led on delay 2 seconds and then turn off led on void loop . And it worked but the code I wrote with button does not Work. Thanks For Your Helps Now. ~Mard