Arduino/C2/Arduino-with-Tricolor-LED-and-Push-button/English
Title of script: Arduino with Tricolor LED and Pushbutton
Author: Manivel and Nirmala Venkat
Keywords: Arduino UNO board, Arduino IDE, Compile and upload, Tricolor LED, Push button, Video tutorials
Visual Cue | Narration |
Slide 1: | Welcome to the Spoken Tutorial on Interfacing Arduino with Tricolor LED and Pushbutton. |
Slide 2:
Learning objectives |
In this tutorial, we will learn to:
|
Slide 3:
System Requirement |
Here I am using:
|
Slide 4:
Pre-requisites |
To follow this tutorial, you should have:
|
Slide 5:
External devices |
We also require some external devices such as:
|
Let us see the images of the external devices that are required for this experiment. | |
Slide 5:
Show image: Tricolor LED |
This is also called as Common Cathode Tricolor LED.
It has four pins. Cathode is the longest pin. The remaining three pins are for the red, green and blue color LEDs. Cathode pin is the ground pin common to the red, green and blue LEDs. |
Slide 6:
Show image: Resistor |
Resistor is an electrical component that limits the flow of current in an electronic circuit.
Resistors can also be used to provide a specific voltage for an active device. |
Slide 7:
Show image: breadboard |
This is the breadboard which is commonly used to build electronic circuits.
It has many holes. Electronic components are inserted into these holes and are connected using wires. |
Slide 8:
Show image: Jumper wires |
Jumper wires are short electrical wires with a solid tip at each end.
Jumper wires are used to interconnect the components in a breadboard. |
Let us see the connection circuit details now. | |
Slide 9:
Show image: |
This circuit is very simple.
Cathode pin is connected to the ground pin in the Arduino board, using the black wire, like this. The red, green and blue pins are connected to pin numbers 12, 11 and 10 using resistors. Why do we need resistors here? This is to control the voltage to the LEDs. We need three current-limiting resistors for each color. Here, I am using 100 ohm resistors. |
Let me show you the live demo. | |
This is the mini breadboard where I have connected the tricolor LED and resistors
This is exactly what we have seen in the circuit diagram. | |
Now we have to write a program for this circuit to work. | |
Switch to Arduino IDE | Let us open the Arduino IDE. |
Point to the default loop statements | We know that any Arduino program comes with two basic functions -
Void setup and Void loop. |
Void setup function is for setting up a microcontroller.
Here we need to setup the pins that we are using in our experiment. | |
Now we will write the code for the Void setup function. | |
Switch to the circuit diagram.
Point to the blue wire and pin number 10 |
In the circuit diagram, notice that pin number 10 is connected to the blue LED. |
Type,
pinMode(10, OUTPUT); |
In the Arduino IDE, type:
pinMode open bracket 10 comma OUTPUT close bracket Semicolon. |
Point to the green wire and pin number 11
Point to the red wire and pin number 12 Type: pinMode(11, OUTPUT); pinMode(12, OUTPUT); |
Similarly, type the code for the other pins as shown:
Pin number 11 represents the green LED and 12 represents the red LED. Now we have configured the pins. |
Point to void loop() | Next we will write the code for the Void loop function.
Void loop function is an indefinite ‘while’ loop. |
This code is the same as the one we wrote for the Blink LED program.
But we will need to write the same lines of code for all three LEDs. | |
Type,
digitalWrite(10, High) delay(500); digitalWrite(10, Low) delay(500); |
These four lines of code will blink the blue LED with a delay of 500 milliseconds. |
Copy and paste the code and change the code | Copy and paste the same code for the other pins.
Change the pin number to 11 for green LED and 12 for red LED. |
Let us save this program. | |
Click File>> Save | Click File and Save.
Enter the filename as tricolor hyphen LED. |
Point to micro controller in the board | Now the microcontroller is programmed to send alternate signals HIGH and LOW, to pin 10, 11 and 12. |
The next step is to compile and upload the program. | |
Sketch>>Compile | From the Sketch menu, click on Compile. |
Compile and upload | We can see the compilation status at the bottom of the IDE. |
Sketch >> Upload | To upload the program to the microcontroller, click on the Sketch menu, and then on Upload. |
We can see that the red, blue and green LEDs are blinking. | |
The blinking is continuous.
| |
Next we will see how to interface a pushbutton to the same circuit, to control the blinking. | |
Slide 10:
Pushbutton image: |
Pushbutton is a component that connects two points in a circuit when you press it.
You can see a button on the top which can be pressed. In our experiment, it turns on the tricolor LED when you press the button. |
We are using the same circuit for this experiment with a pushbutton. | |
Point to the push button in the circuit diagram | Pushbutton is also known as momentary switch. The moment you press it, the tricolor LED will glow.
If you release the switch, the tricolor LED will not work. We have connected the pushbutton to the board. |
Point to the brown color wire
Point to the yellow color wire |
One leg of the Pushbutton is connected to 5 volts.
This is shown here in the brown color wire. And the other leg is connected to pin number 4 which is shown here in yellow color wire. |
Here, you can see a resistor connected to the pushbutton. | |
Why do we need a resistor here?
Pin 4 is configured as input, that means it expects some input voltage. When the pushbutton is pressed, it connects the pin 4 to 5 volts and we read a HIGH. At this point, the resistor helps to prevent the current from going to the ground pin. If the pushbutton is not pressed, then also we need to pass some voltage. The resistor which is connected through the ground pin will provide zero volt. This will make microcontroller active as it receives some input. | |
Switch back to live connection. | Let us see our live video for the connection. |
Show the Push button from the video | This is how the push button looks. |
You can see the other connections exactly as I explained in the circuit diagram. | |
Now, let us modify our program for this circuit to work. | |
Switch back to Arduino IDE. | Switch back to Arduino IDE.
This is our previous program. |
Type,
pinMode(4, INPUT): |
I will add a new setup for the pin number 4. |
Highlight the INPUT keyword | Why should we give the mode as INPUT?
This is because -
|
We have to write a conditional statement to check whether the switch is pressed or not. | |
In the void loop function, we will write the if statement. | |
Type,
if (digitalRead(4) == HIGH) { |
Type the code as shown here.
Let me explain what it means. If pin number 4 receives an input, it will execute the code specified between the curly braces. |
Change the code wherever it is 500 to 100 | Let me reduce the delay to 100 milliseconds so that we can see the output quickly. |
The coding is now done. | |
Switch back to Arduino IDE | Let us compile and upload our program. |
Next we will press the pushbutton and see how it works. | |
Point to the blinking | We can see the tricolor LED is ON. |
Press one more time. | |
It works. | |
This brings us to the end of this tutorial. Let us summarize. | |
Slide 11:
Summary |
In this tutorial, we learnt to:
|
Slide 12:
Assignment |
Do the following assignment.
|
Slide 13:
About Spoken Tutorial project |
The video at the following link summarizes the Spoken Tutorial project.
Please download and watch it. |
Slide 14:
Spoken Tutorial workshops The Spoken Tutorial Project Team |
The Spoken Tutorial Project Team:
For more details, please write to us. |
Slide 15:
Forum for specific questions |
Please post your timed queries in this forum. |
Slide 16:
Acknowledgement |
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
Thanks for watching. |