When the button is not being pressed, the pin the button is connected to, is going to be pulled down to ground. But when we do press the button, the electricity will flow from 5v to the digital pin. Remember that electricity follows the path of least resistance. The electricity then would not take the path through the resistor when the button is pressed. The resistor inside the circuit is a 10 kohm resistor. Terminals (11 / 12) and (21 / 22) are connected together. But when we press the button all four terminals are connected together. Without the resistor inside the circuit, a floating pin will be created. A floating pin will be created which is telling us that the pin the button is connected to nor (0 volts - 5 volts). A floating pin will then result in electrical noise. Electrical noise may give us false values of HIGH or LOW to the pins surrounding the pin the button is connected to.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
You can do it, too! Sign up for free now at https://www.jimdo.com