What is ARDUINO?
Arduino uses as a varient of C++ programming language.
The code written in C++ with an addition of special method and functions .
When you create a 'sketch'(the name given to code files in this language),to machine language.
👉What are the uses of Arduino Programming language?
Used to program microcontroller boards such as the Arduino UNO to interact with sensors, actuators and other devices connected to the board.
Basically used in projects involving robotic,home automation and Internet of Things (IoT) applications.
To download software of Arduino IDE:https://www.arduino.cc/en/main/software
//When you open the software of Arduino IDE the program will be shown on the screen .This is given below 👇
In the preparation block the program will be run only one time .Here, the void is the command for function declaration.
And in the Execution block your main program will be written and the it will run repeatedly.
👉 There are some basic rules:
Every Arduino program has void setup() and void loop().
Program always run in linear pattern.
Example:-
void setup ()
{. ..............(1)
}
void loop()
{. ...............(2)
}
Always remember the curly brackets {}.
Arduino program are Case sensitive program.
// Is used for single line comment.
(;) Semi colon is used after every statement.
⭐ Variables:-
Variables are used to store information to be referenced and manipulated in a computer program.
👉There are three things require to declare a variables:-
Data type
Variable Name
Value
👉 There are two types of Variables:-
Global Variables: Used in any function in program.
Local Variables: Inside a function and can be only used in Inside the function.
⚫ Arduino Board is a open source electronics plateform based on easy to used hardware and software . Arduino board are able to reads inputs - light on a sensor, finger on a button and turn it into an output - activating motor.
👉Some basic functions for controlling the Arduino board.
pinMode() - which pin we are going to used for input/output.
Syntax: pinMode (pin,mode);
Example: pinMode (13, OUTPUT);
digitalWrite() - High voltage or Low voltage to a digital pin .
HIGH -5 Volt
LOW -0 Volt
Syntax: digitalWrite (pin , value);
Pin - Arduino pin
Value -high/low
Example: digitalWrite (13, HIGH);
delay ()- pauses the program for the amount of time (in milliseconds i.e 1 second=1000 millisecond) specified as parameter .
Syntax: delay(ms);
Example: delay(1000);
⭐ Program for a blinking of LED.
void setup ()
{
pinMode (13, OUTPUT);
}
void loop ()
{
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (13,LOW);
delay(1000);
}
⭐ Serial Communication
Serial communication basically used in the RX and TX pins of the Arduino board in which they used the UART communication.
UART - Universal Asynchronous Transmitters Receiver.
In every sensor inside the RX and TX pins which uses the UART communication protocol for data transfer. In which communication protocol one transmitter and receiver pins are present.
Example:
void setup ()
{
Serial. begin(9600);
}
void loop ()
{
if(Serial. available ()==1)
{
chat val = Serial. read();
Serial. print (val);
}
}
👉 Numeric Data type in Arduino Programming
Byte - A byte stores am 8 bit (only positive number) unsigned number ,from 0 to 255 .
Syntax:byte var = value;
Example - byte var=155;
• word- A word can store an unsigned number of at least 16 bits from 0 to 65535
Syntax: word var =value;
Example - word var=2567;
Short - A short is a 16 bit data type.A short stres a 16 bit value.
It's range = -32768 to 32767.
Syntax - short var =value;
Example - short var = - 1552;
👉 Text data type in Arduino Programming
char - A data type used to share a character value character literals are written in single quotes like this 'A'
Syntax -char var =val;
Example = char var = 'A';
• string- A data type used to store set of characters that can also contain space and numbers.
Syntax - string var = val ;
Example - string var = "Abc";
👉 Array Data type:-
An array is a collection of variables that are accessed with an index number.
Example - int val [6]={2,3,4,5,6,7};
void setup ();
{
Serial. begin (9600);
Serial. print ( val[1]);
}
void loop ();
{
}
👉 Digital input/output function in Arduino Programming
digitalRead(): Reads the value from a specified digital pin either high or low.
Syntax - digitalRead(pin);
Example- void setup ()
{ pinMode(12,INPUT_PULLUP);
Serial:begin(9600);
}
void loop ()
{
int val= digital. Read (12);
Serial. println(val);}
⚫ INPUT_PULLUP:- Makes the digital pin HIGH initially until it receive a LOW signal from an external device.
👉If ...else statement
The if statement checks for a condition and executes the proceeding statement if the condition is true.
Syntax -
if(condition)
{Statement 1;
}
else
{ Statement 2;
}
👉If.... elseif statement
The if statement can be followed by an optional elseif.... else statement,which is very useful to test various condition.
Syntax:-
if(condition 1)
{ Statement 1;
}
elseif( condition 2)
{Statement 2;
}
else
{
Statement 3;
}
👉 Switch - switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. The break keyword exits the switch statement, and is typically used at the end of each case.
👉Break -break is a keyboard exits the switch statement and is typically used at the end of each case , without a break statement,the switch statement will continue executing the following expression until a break or the end of a the switch statement is reached.
Syntax-
switch (var)
{
Case 1:
Statement 1;
break;
Case 2:
Statement 2;
break;
default://if nothing else matches do the default
Statement 3;
break;
}
👉For loop
The for statement is used to repeat a block of statement enclosed in curly brackets.An increment counter is is usually used to increment and terminate the loop the first statement is useful for any repetitive operation and often use is combination within arrays to operate and collection of data /pins.
Syntax -
for (initialization; condition; increment)
{Statement;
}
∆ initialization: happens first and exactly once .
∆Condition : each time through the loop condition is tested if its true the statement block and the increment is executed then the conditions tested again when the condition becomes all the loops end .
∆Increment: executed each time through the loop when condition is true.
👉 While loop
Used to repeat a section of code and unknown number of time and tell us specific condition is met .
Syntax : while (condition)
{Statement;
}
Comments