Arduino/C2/Arduino-with-Tricolor-LED-and-Push-button/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:01 Welcome to the Spoken Tutorial on Interfacing Arduino with Tricolor LED and Pushbutton.
00:09 In this tutorial, we will learn to: connect a tricolor LED to Arduino board,
00:17 write a program to blink tricolor LED and use Push button to control the blinking.
00:27 Here I am using: Arduino UNO Board,
00:31 Ubuntu Linux 14.04 operating system and Arduino IDE.
00:39 To follow this tutorial, you should have: basic knowledge of electronics and basic knowledge of C or C++ programming language.
00:52 We also require some external devices such as Tricolor LED, Resistor,
01:01 Breadboard, Jumper Wires and Pushbutton.
01:08 Let us see the images of the external devices that are required for this experiment.
01:16 This is also called as Common Cathode Tricolor LED.
01:22 It has four pins. Cathode is the longest pin.
01:27 The remaining three pins are for the red, green and blue color LEDs.
01:34 Cathode pin is the ground pin common to the red, green and blue LEDs.
01:42 Resistor is an electrical component that limits the flow of current in an electronic circuit.
01:50 Resistors can also be used to provide a specific voltage for an active device.
01:57 This is the breadboard which is commonly used to build electronic circuits.
02:03 It has many holes. Electronic components are inserted into these holes and are connected using wires.
02:12 Jumper wires are short electrical wires with a solid tip at each end.
02:19 Jumper wires are used to interconnect the components in a breadboard.
02:25 Let us see the connection circuit details now.
02:30 This circuit is very simple. Cathode pin is connected to the ground pin in the Arduino board, using the black wire like this.
02:41 The red, green and blue pins are connected to pin numbers 12, 11 and 10 using resistors.
02:51 Why do we need resistors here? This is to control the voltage to the LEDs.
02:58 We need three current-limiting resistors for each color.

Here, I am using 100 ohm resistors.

03:08 Let me show you the live demo.
03:11 This is the mini breadboard where I have connected the tricolor LED and resistors.
03:18 This is exactly what we have seen in the circuit diagram.
03:23 Now we have to write a program for this circuit to work.
03:28 Let us open the Arduino IDE.
03:32 We know that any Arduino program comes with two basic functions -

Void setup and Void loop.

03:41 Void setup function is for setting up a microcontroller.
03:46 Here, we need to setup the pins that we are using in our experiment.
03:52 Now we will write the code for the Void setup function.
03:57 In the circuit diagram, notice that pin number 10 is connected to the blue LED.
04:05 In the Arduino IDE, type: pinMode open bracket 10 comma OUTPUT close bracket Semicolon.
04:16 Similarly, type the code for the other pins as shown:
04:21 Pin number 11 represents the green LED and 12 represents the red LED.

Now we have configured the pins.

04:32 Next we will write the code for the Void loop function.

Void loop function is an indefinite ‘while’ loop.

04:42 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.

04:54 These four lines of code will blink the blue LED with a delay of 500 milliseconds.
05:02 Copy and paste the same code for the other pins.
05:07 Change the pin number to 11 for green LED and 12 for red LED.
05:16 Let us save this program.
05:19 Click File and Save.

Enter the filename as tricolor hyphen LED.

05:28 Now the microcontroller is programmed to send alternate signals HIGH and LOW to pin 10, 11 and 12.
05:40 The next step is to compile and upload the program.
05:44 From the Sketch menu, click on Compile.
05:49 We can see the compilation status at the bottom of the IDE.
05:56 To upload the program to the microcontroller, click on the Sketch menu and then on Upload.
06:04 We can see that the red, blue and green LEDs are blinking.
06:10 The blinking is continuous.

This is because our program executes the void loop function in an indefinite loop.

06:20 Next, we will see how to interface a push button to the same circuit, to control the blinking.
06:28 Pushbutton is a component that connects two points in a circuit when you press it.
06:35 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.

06:48 We are using the same circuit for this experiment with a pushbutton.
06:54 Pushbutton is also known as momentary switch. The moment you press it, the tricolor LED will glow.
07:03 If you release the switch, the tricolor LED will not work.

We have connected the pushbutton to the board.

07:11 One leg of the Pushbutton is connected to 5 volts.

This is shown here in the brown color wire.

07:20 And the other leg is connected to pin number 4 which is shown here in yellow color wire.
07:27 Here, you can see a resistor connected to the pushbutton.
07:32 Why do we need a resistor here?

Pin 4 is configured as input. That means, it expects some input voltage.

07:42 When the pushbutton is pressed, it connects the pin 4 to 5 volts and we read a HIGH.
07:50 At this point, the resistor helps to prevent the current from going to the ground pin.
07:58 If the pushbutton is not pressed, then also we need to pass some voltage.
08:05 The resistor which is connected through the ground pin will provide zero volt.
08:12 This will make microcontroller active as it receives some input.
08:18 Let us see our live video for the connection.
08:22 This is how the push button looks.
08:25 You can see the other connections exactly as I explained in the circuit diagram.
08:32 Now, let us modify our program for this circuit to work.
08:37 Switch back to Arduino IDE. This is our previous program.
08:44 I will add a new setup for the pin number 4.
08:47 Why should we give the mode as INPUT?

This is because - when the Pushbutton is pressed, the circuit gets completed and pin number 4 receives an input.

09:02 We have to write a conditional statement to check whether the switch is pressed or not.
09:09 In the void loop function, we will write the 'if' statement.
09:15 Type the code as shown here.

Let me explain what it means.

09:22 If pin number 4 receives an input, it will execute the code specified between the curly braces.
09:31 Let me reduce the delay to 100 milliseconds so that we can see the output quickly.
09:39 The coding is now done.
09:42 Let us compile and upload our program.
09:47 Next, we will press the pushbutton and see how it works.
09:53 We can see the tricolor LED is ON.
09:58 Press one more time. It works.
10:02 This brings us to the end of this tutorial. Let us summarize.
10:07 In this tutorial, we learnt to: connect the tricolor LED to Arduino board,
10:13 write a program to blink tricolor LED

and use Pushbutton to control the blinking.

10:22 Do the following assignment.

Change the same program in the opposite way.

10:28 If the button is pressed, keep the input as LOW. Compile and upload the program.
10:35 Observe the blinking in the tricolor LED.
10:39 The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

10:46 The Spoken Tutorial Project team: conducts workshops and gives certificates.

For more details, please write to us.

10:55 Please post your timed queries in this forum.
10:59 Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at this link.

11:10 This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.

Thanks for watching.

Contributors and Content Editors

PoojaMoolya, Sandhya.np14