Writing First program on Arduino


Language for Arduino

Arduino is programmed in a language that is a modified version of C++. You don't need to be master in C/C++ for this. Just knowledge of functions, loops and constants things are good enough to get started.

Basic Structure of Arduino Program

Every Arduino program consist of two main modules, setup() and loop().

void setup(): This function takes no argument and returns void. It is automatically called when you press reset. This module is used to define initialization of pins for input and output.
Syntax:
void setup()
{
 pinMode(pin_number, MODE);
}

void loop(): This is the main loop for program that will run eternally. It starts execution when the Arduino is powered on. This contains the actual function of the system. It takes input, process information and provide some output.
Syntax:
void loop()
{
digitalWrite(pin number, Power);
}

Program to Power LED (Pin 13)


void setup()
{
    pinMode(13 ,  OUTPUT);
}
void loop()
{
    digitalWrite(13 , HIGH);
}

Running The Code

Firstly, connect the Arduino Board with CPU via USB cable. After the code is written, save the code and click Verify.
Highlighted Verify option for compiling.

Once the code is compiled successfully, it is ready to go on the board! Click Upload.
Highlighted Upload after successful compilation.

When the code is uploaded on Arduino, press the Reset switch on the board. And voila! You see Pin 13 light up your world. (It is Arduino's way to say "Hello World")
Pin 13 LED On (Orange color)

Hope that was of some help! Stay tuned for more posts.



Comments

Popular posts from this blog

Print in Python

Coding Digits

Calculating bits of bits.