Arduino programming tutorial


#1

Getting the Board ready and running:

The board should be connected to the USB port of your PC and install the USB driver that comes with the IDE(Integrated Development Environment). Open up the Arduino IDE port and select COM port, usually COM 1 or Com 2 for windows port.

Within the IDE, select the BAUD rate (communication speed for serial connection). Set BAUD rate on 9600 on windows.

One can check the program in the software and burn it into the Arduino board if the program is correct. For that click the reset button on the board and then click ‘Upload to I/O board’ in the IDE.

Arduino Programming:

Arduino Company provides user-friendly software which allows writing any code for any function wanted to be performed by the Arduino-Uno and upload it to the board.

Basic structure and coding:

The programming is much similar to C++. The basic programming consists of two parts, statements are enclosed in it within curly braces. The first part is the Setup() part and the other is the Loop() part.

Void setup()
{
statement;
}

Void loop()
{
statement;
}

In the setup() function, declares the variables included in programming. It runs only once in the program. The loop() function includes codes to executed continuously in the program, reading input, execution and triggering output.

{} Curly braces:

Curly braces define the beginning and end of the function block. All opened curly braces should be closed at the end of the function.

type of function()
{
statements;
}

; Semicolon

A semicolon is used at the end of each statement and to separate elements of the program.

eg: int x = 3;

Setup():

Setup() function is called when the program is called, at the beginning of the program. It is compulsory to this function even if there is no statement to run.

syntax:

Void setup()
{
pinMode(pin, OUTPUT); // Set the ‘pin’ as output
}

Loop();

Only after calling the setup() function, we can start the loop() function. The loop() continuously run to allow the program to change the output with respect to the changing input.

syntax:

void loop()
{
digitalWrite(ledPin, LOW); // it takes two values, the pin number and the level, HIGH/ LOW the off state.
}