Arduino: How to program an arduino

Programming an Arduino

The arduino board can be programmed with using the arduino(IDE) software,and the programming in that software is done in C language,which is very easy to understand.Now let's get started

Suppose,you want to glow an LED for a fixed time interval   or blinking then first you need to specify the pin to which the led is connected by creating a variable name and attach it to that pin like this 

int LED=13;

here any pin and any variable name can be selected 
and int is the initialize for that variable.
Now you need to declare the variable or PIN as an OUTPUT ,in the void setup field like this

void setup()
{
pinMode(LED,OUTPUT);
}

now,you have declared the variable as output,this means  that arduino will only send signals to that pin and will not receive any that from that pin.

now you need to write the loop statement in the void loop field, All the statement or functions written in the void loop field will be repeated again and again

Write the loop statements like this for the glowing led:-
void loop()
{
digital write(LED,HIGH);
delay(1000);
digitalwrite(LED,LOW);
}
here we have used delay function and 1000 denotes 1sec and  digitalwrite means that arduino will send a signal to to that pin

Full code will be like this-:

int LED=13;

 void setup()
{
pinMode(LED,OUTPUT);
}
void loop()
{
digitalwrite(LED,HIGH);
delay(1000);
digitalwrite(LED,LOW); 
}


this code will continuously blink the led  at delay of 1sec 
see the vedio :-



This is the easiest code in arduino,
Now there are may types of loops like 

1.While loop
2.For loop
3.Do while loop
and there are some conditional statements like 
1.if/else  statement
2.else if
3.case statemats

We can use these loops to make very interesting types of things like an AI robot,Robots for home cleaning and automation etc

All these loop and statements are described in our next post Click here

Comments

Popular posts from this blog

Arduino:How to program an arduino using loop statements

Automatic Door Locking with Arduino

Arduino:How to make a RC car with arduino