0% found this document useful (0 votes)
25 views

Lesson 1 Arduino Circuit With An LED and A Button

The document describes an Arduino circuit with an LED and button. It lists the required materials including an Arduino board, breadboard, LED, push button, and resistors. It explains how a button works as a switch and describes connecting a pull-down resistor to avoid external interference when the button is off. The circuit diagram and code are provided to turn on the LED only when the button is pressed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lesson 1 Arduino Circuit With An LED and A Button

The document describes an Arduino circuit with an LED and button. It lists the required materials including an Arduino board, breadboard, LED, push button, and resistors. It explains how a button works as a switch and describes connecting a pull-down resistor to avoid external interference when the button is off. The circuit diagram and code are provided to turn on the LED only when the button is pressed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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/

//set pin numbers


const int ledPin = 2; //const won't change
const int buttonPin = 4;

//variables will change


int buttonState = 0; //variables for reading the pushbutton status

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() {

buttonState = digitalRead(buttonPin); //read the state of the pushbutton value

if (buttonState == HIGH) { //check if the pushbutton is pressed


//if it is, the buttonState is HIGH
digitalWrite(ledPin, HIGH); //turn LED on
Serial.println("LED ON +++++++");
}
else {
digitalWrite(ledPin, LOW); // turn LED off
Serial.println("LED OFF -------");
}

You might also like