Arduino/C2/First-Arduino-Program/English

From Script | Spoken-Tutorial
Jump to: navigation, search
Title of script: First Arduino Program
Author: Manivel and Nirmala Venkat
Keywords: Arduino Hardware, Arduino IDE, Compile and upload, Blink LED, Video tutorials
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:
  • Write an Arduino program
  • Compile and upload the program and
  • Blink an LED
Slide 3:

System Requirement

Here, I am using:
  • Arduino UNO Board
  • Ubuntu Linux 14.04 operating system
  • Arduino IDE
Slide 4:

Pre-requisites

To follow this tutorial, you should have:
  • Basic knowledge of Electronics
  • Basic knowledge of writing a C or C++ Program
  • Arduino UNO Board with USB power cable
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 .


And then in the LOW 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:
  • How to write an Arduino program
  • Compile and upload the program
  • Blink an LED
Slide 6:
Assignment
Do the following Assignment.
  • Change the delay timing to 1500 in the above Blink LED program
  • Compile and upload the program
  • Observe the blinking in the LED
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:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.

For more details, please write to us.

Slide 9:

Forum for specific questions

Do you have questions in THIS Spoken Tutorial?
  • Please visit this site.
  • Choose the minute and second where you have the question.
  • Explain your question briefly.
  • Someone from our team will answer them.
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.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat