Arduino Project 2

LED w/ Switch

Now it’s time to talk switches and how they can be incorporated into Arduino projects. A switch is an electrical component that completes a circuit when pushed and breaks the circuit when released.  In this project, we will be using a small pushbutton switch to control an LED.

Project Diagram :

Required Parts :

  • Arduino Uno Board
  • Breadboard – half size
  • Jumper Wires
  • USB Cable
  • LED (5mm)
  • Push button switch
  • 10k Ohm Resistor
  • 220 Ohm Resisto

Connect The Parts :

You can build your Arduino circuit by looking at the breadboard image above or by using the written description below.  In the written description, we will use a letter/number combo that refers to the location of the component.  If we mention H19 for example, that refers to column H, row 19 on the breadboard.

Step 1 – Connect the blue jumper wire from the GND on the Arduino to the GND rail (blue line) on the breadboard near A13

Step 2 – Connect the blue jumper wire from the GND rail on the breadboard near A17 to H19

Step 3 – Connect the red jumper wire from the power rail on the breadboard around row A27 to H26

Step 4 – Connect the green jumper wire from pin 2 on Arduino to J24 on the breadboard

Step 5 – Place one leg of a 10k Ohm resistor in G19 and the other leg in G24

Step 6 – Place the pushbutton switch into F24, F26, E24 and E26

Step 7 – Place one leg of a 220 Ohm resistor in D5 and the other leg in G5

Step 8 – Insert the short leg of the LED in the GND rail around A5 and the long leg in B5

Step 9 – Connect the black jumper wire from pin 13 on the Arduino to I5 on the breadboard

Step 10 – Connect the red jumper wire from 5V on the Arduino to power rail (+) near A8

Step 11 – Connect the Arduino Uno to your computer via USB cable

Upload The Switch Sketch

Now it’s time to upload the sketch to the Arduino that will allow us to use a switch.  As with the blink sketch, there are example programs already loaded in the Arduino IDE that we will be using.

In order to use a switch, we have to load the file called “Button” which can be found here:  File > Examples > Digital > Button

Now you should have a fully coded button sketch that looks like the image below.

Next, you need to click on the verify button (check mark) that’s located in the top left of the IDE box.  Once it says “Done Compiling” you are ready to upload it.  Click the upload button (forward arrow) to send the program to the Arduino board.

Press the button switch on the breadboard and you should be able to turn on and off the LED

Post Author: Electronic Project YEP

Ahmed Amorri

Leave a Reply