Difference between revisions of "Arduino/C2/First-Arduino-Program/English"
(Created page with " <div style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">'''Title of script'''</span><span style="color:#000000;">: </span>'''First<span style="color:#0000...") |
Nancyvarkey (Talk | contribs) |
||
Line 157: | Line 157: | ||
<span style="color:#000000;">So, type: </span><span style="color:#000000;">'''digitalWrite open brackets 13 comma HIGH close brackets semicolon'''</span> | <span style="color:#000000;">So, type: </span><span style="color:#000000;">'''digitalWrite open brackets 13 comma HIGH close brackets semicolon'''</span> | ||
− | <span style="color:#000000;">We want to glow the </span><span style="color:#000000;">'''LED'''</span><span style="color:#000000;">. So, the voltage should be </span><span style="color:#000000;"> | + | <span style="color:#000000;">We want to glow the </span><span style="color:#000000;">'''LED'''</span><span style="color:#000000;">. So, the voltage should be </span><span style="color:#000000;">'''HIGH'''.</span> |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.106cm;color:#000000;" | | | style="border:1pt solid #000000;padding:0.106cm;color:#000000;" | | ||
Line 203: | Line 203: | ||
<span style="color:#000000;">We have to modify this program such that the second parameter value is </span><span style="color:#000000;">'''LOW'''</span><span style="color:#000000;">.</span> | <span style="color:#000000;">We have to modify this program such that the second parameter value is </span><span style="color:#000000;">'''LOW'''</span><span style="color:#000000;">.</span> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.106cm;" | <span style="color:#000000;">Compile and upload the program</span> | | style="border:1pt solid #000000;padding:0.106cm;" | <span style="color:#000000;">Compile and upload the program</span> | ||
Line 226: | Line 221: | ||
| style="border:1pt solid #000000;padding:0.106cm;" | <span style="color:#000000;">We will change the program as shown:</span> | | style="border:1pt solid #000000;padding:0.106cm;" | <span style="color:#000000;">We will change the program as shown:</span> | ||
− | <span style="color:#000000;">'''Delay'''</span><span style="color:#000000;"> is a built in function which pauses the program for certain amount of time.</span> | + | <span style="color:#000000;">'''Delay'''</span><span style="color:#000000;"> is a '''built-in function''' which pauses the program for certain amount of time.</span> |
<span style="color:#000000;">I will type:</span><span style="color:#000000;">''' delay open brackets comma 500 close </span><span style="color:#000000;">brackets semicolon'''</span> | <span style="color:#000000;">I will type:</span><span style="color:#000000;">''' delay open brackets comma 500 close </span><span style="color:#000000;">brackets semicolon'''</span> | ||
Line 255: | Line 250: | ||
<span style="color:#000000;">The pin number 13 connected to the </span><span style="color:#000000;">'''LED'''</span><span style="color:#000000;"> will be in </span><span style="color:#000000;">'''HIGH'''</span><span style="color:#000000;"> state for 500 milliseconds .</span> | <span style="color:#000000;">The pin number 13 connected to the </span><span style="color:#000000;">'''LED'''</span><span style="color:#000000;"> will be in </span><span style="color:#000000;">'''HIGH'''</span><span style="color:#000000;"> state for 500 milliseconds .</span> | ||
+ | |||
+ | |||
<span style="color:#000000;">And then in the </span><span style="color:#000000;">'''LOW'''</span><span style="color:#000000;"> state for 500 milliseconds.</span> | <span style="color:#000000;">And then in the </span><span style="color:#000000;">'''LOW'''</span><span style="color:#000000;"> state for 500 milliseconds.</span> | ||
Latest revision as of 13:14, 16 September 2016
Visual Cue | Narration |
Slide 1: | Welcome to the Spoken Tutorial on First Arduino Program. |
Slide 2:
Learning objectives |
In this tutorial, we will learn how to:
|
Slide 3:
System Requirement |
Here, I am using:
|
Slide 4:
Pre-requisites |
To follow this tutorial, you should have:
|
Let us open the Arduino IDE to write our first program. | |
Point to the menu bar | Here, we can see various menus in the Menu bar. |
Point to the sketch file name on the top bar | In Arduino environment, each program is saved as Sketch.
By default, it creates the name as Sketch underscore and a name. |
Point to File >> Save menu | You can change the name by clicking on File and then on Save. |
Type BlinkLed in filename | Type the filename as BlinkLed.
Now click on the Save button. |
Point to the default code | This is the default program environment with two empty functions -
void setup and void loop. |
Now, we will write an Arduino program to blink the LED. | |
Show the Window with the IDE and Board side by side | I have placed my IDE and the Arduino board side by side.
This will help us to see the execution of the program and the output in the board. |
Point to the pin number 13 with the marker |
For this LED program, I want to blink pin number 13.
It is a digital input/output pin connected to this LED internally. Notice the highlight with the marker. |
Now, we have to write our code. | |
Highlight the Void setup() function
Type, pinMode(13, output) |
void setup function stands for setting up a microcontroller.
In our case, pin number 13 has to be set up first. To do this, we will use an in-built function called pinMode. It has two parameters - pin number comma mode. So, type pinMode open brackets 13 comma output close brackets semicolon |
Why should we keep the mode as output? | |
Highlight the code | This is because the pin number 13 is internally connected to the LED.
It will glow when the voltage is high but it will not glow when the voltage is zero. We have to configure mode as ‘output’ to serve voltage to the LED. |
Point to void loop() | Next we will write code to the void loop function. |
Type, digitalWrite(13, HIGH) |
Before we blink a LED, let us glow a LED.
There is a function called digitalWrite which will write to a digital pin. This function has two parameters as pin number and value or state. Already, we know the pin number as 13. The value should be HIGH or LOW. So, type: digitalWrite open brackets 13 comma HIGH close brackets semicolon We want to glow the LED. So, the voltage should be HIGH. |
That's all. The code is very simple. | |
Next step is to compile the program. | |
Click on the Tick icon
Highlight the compilation status |
Click on the Tick icon on the Menu bar to verify the program.
This will compile our program into binary format which is understandable by the microcontroller. You can see the compilation status at the bottom of the IDE. |
Next we need to upload the program to the microcontroller. | |
Click on right arrow button | Click on Right arrow button on the menu bar to upload.
Alternately, you can select Sketch menu and then upload. |
Point to TX RX blinks | You can see the TX RX blinks for a while. This indicates the transmission is ON.
Now you can see the LED is glowing. |
Modify the program by typing, | How to turn off the LED?
We have to modify this program such that the second parameter value is LOW. |
Compile and upload the program | Now, let us compile and upload this program. |
Point to the LED | You can see the LED is off now. |
We know how to turn ON and OFF the LED. | |
Next we will modify the program to make the LED to blink.
That is ON and OFF, with one second interval. | |
Modify the program, | We will change the program as shown:
Delay is a built-in function which pauses the program for certain amount of time. I will type: delay open brackets comma 500 close brackets semicolon Here 500 means, 500 milliseconds, that is, half a second of delay. |
Type,
digitalWrite(13,LOW) |
Next, type as digitalWrite open brackets 13 comma LOW close brackets semicolon
This makes the digital pin 13 to OFF mode. |
Type,
delay(500); |
How long we want to turn it OFF?
Type: delay open brackets 500 close brackets semicolon Again, we want to OFF it for 500 milliseconds. |
Let me explain the Void loop program line by line again. | |
Point to code line by line | Void loop is an infinite loop and it will execute continuously.
The pin number 13 connected to the LED will be in HIGH state for 500 milliseconds .
This program is executed repeatedly in the loop. |
Click upload | Let us upload the program. |
Point to the LED (24:48) | We can see our LED is blinking. |
This brings us to the end of this tutorial. Let us summarise. | |
Slide 5:
Summary
|
In this tutorial, we learnt about:
|
Slide 6:
Assignment
|
Do the following Assignment.
|
Slide 7:
About Spoken Tutorial project |
The video at the following link summarizes the Spoken Tutorial project.
Please download and watch it. |
Slide 8:
Spoken Tutorial workshops The Spoken Tutorial Project Team |
The Spoken Tutorial Project Team:
For more details, please write to us. |
Slide 9:
Forum for specific questions |
Do you have questions in THIS Spoken Tutorial?
|
Slide 10:
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. |