Lesson 1 Arduino Circuit With An LED and A Button
Lesson 1 Arduino Circuit With An LED and A Button
Materials:
Arduino board
Breadboard.
LED – any color.
Push button.
220 Ohm resistor for the LED. If you don’t have this specific value, any resistor
from 330 to 1k Ohm will do.
10k Ohm resistor for the push button. If you don’t have, you can go until 20k-50k
Ohm.
male to male wires (including if possible black, red, and other colors).
Experiment:
Buttons are a common component used to control electronic devices. They are
usually used as switches to connect or disconnect circuits. Although buttons
come in a variety of sizes and shapes, the one used here is a 12mm Tactile
button as shown in the following pictures. Pins pointed out by the arrows of same
color are meant to be connected.
When the button is pressed, the pins pointed by the blue arrows will connect to
the pins pointed by the red arrows. Generally, the button is directly connected in
an LED circuit in order to turn on or off the LED. This connection is relatively
simple. However, sometimes the LED will light up automatically without pressing
the button, which is caused by various interferences. In order to avoid these
external interferences, a pull-down resistor is used, that is, to connect a 1K–
10KΩ resistor between the button port and GND. It is used to consume external
interferences while connected to GND for as long as the button switch is turned
off. This circuit connection is widely used in numerous circuits and electronic
devices. For example, if you press any button on your mobile phone, the
backlight will light up.
Circuit Diagram:
Codes:
//This code will allow a button press to turn on the LED
//https://www.makerlab-electronics.com/
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
pinMode(buttonPin, INPUT); //initialize the pushbutton pin as an output
}
void loop() {