Let’s enjoy Arduino! LED With Button
void setup() { // put your setup code here, to run once: pinMode(7, OUTPUT); pinMode(2, INPUT); } void loop() { // put your main code here, to run repeatedly: int buttonState = digitalRead(2); if (buttonState == HIGH) { digitalWrite(7, HIGH); } else { digitalWrite(7, LOW); } }