Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →How does Arduino know when you pressed the button?
Connect one side of the button to GND and the other to pin 2. We'll use INPUT_PULLUP internally.
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop() {
// الزر يعطي LOW عند الضغط لأنه موصل بالـ GND
if (digitalRead(2) == LOW) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}Forgetting to use PULLUP, causing the LED to blink randomly just by moving your hand near the button.