0

members

Easy Basics: Project 012b LED control by momentary switch or button

of Acoptex.com in UNO

Basics: Project 012b

Project name: LED control by momentary switch(button)

Attachments: program1 and program2

In this project, you needed these parts :

1.Aruduino Uno R3 (you can also use the other version of Arduino)

2.Arduino IDE ( you can download it from here  )

3.Jumper cables

4. LED 1 pc optional

5. Resistor 2 pcs (220 Om optional and 10 KOm)

6. Breadboard

7. Momentary switch(button)

8. Capacitor 1 pc 100 nF

General

In this project you will learn how to turn on/off an LED by using an I/O port and a momentary switch(button). The "I/O port" refers to the INPUT and OUTPUT port. Here the INPUT port of the Arduino Uno board is used to read the output of an external device. Since the board itself has an LED, which is conneced to Pin 13, you can use this LED for this project or you can use different LED, connected to other Pin (for example, Pin 11). If you want to use other LED (not from Arduino Uno board) - you need to have resistor for it. 

Momentary switches (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 6mm mini-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. 

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Signals and connections of momentary switch (button)

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 – 10 KOm 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. The capacitor 0.1uF (104) is used to eliminate jitter and output a stable level when the button is working.

Build the circuit

The following picture shows the needed connections with the Arduino Uno 

1. With LED on Arduino Uno board

2.With other LED conected to Pin 11

Code

Connect the button to pin 12. LED has been connected to pin 13 (or to pin 11 as in sketch/program2). Define a variable buttonState to restore the state of the button.We need to know the status of the button in this experiment, so here set the buttonPin as INPUT; to set HIGH/LOW of the LED, we set LedPin as OUTPUT. buttonPin(Pin12) is a digital pin; here is to read the value of the button and store it in buttonState. digitalRead (Pin): Reads the value from a specified digital pin, either HIGH or LOW. when the buttonState is High level, write ledPin as High and the LED will be turned on. As one end of the button has been connected to 5V and the other end to pin 12, when the button is pressed, pin 12 is 5V (HIGH). And then determine with the if(conditional); if the conditional is true, then the LED will light up. Else means that when the if(conditional) is determined as false, run the code in else. 

 

Step by Step instruction

  1. Plug your Adruino Uno board into your PC and select the correct board and com port
  2. Open up serial monitor and set your baud to 9600 baud
  3. Verify and upload the the sketch to your Adruino Uno
  4. Press the button and the LED on the Arduino Uno board or breadboard will light up (depends on which sketch uploaded)

Summary

In this project you learned how to turn on/off an LED by using an I/O port and a momentary switch(button). 

Libraries:

  • No libraries required for this project

Program/Sketch

  • See attachments on the begining of this project description. 
  • Program 1 with LED on Arduino Uno board and Program 2 with LED connected to Pin 11 on Arduino Uno board


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 20-07-2017
Viewed: 370 times