0% found this document useful (0 votes)
30 views7 pages

Arduino Setup by Prof Vaibhav Srivastava

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views7 pages

Arduino Setup by Prof Vaibhav Srivastava

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Arduino Setup By Prof Vaibhav Srivastava

How to use Arduino:


Rules of Arduino
1. Every Arduino Program has void setup() and void loop().
2. Program runs in a linear fashion.
3. Remember the {} Curly bracket.
4. Program is Case sensitive.
5. Use // to add comments in Program.
6. Put “ ; ” after every statement.
Rules to Apply Variables
1. Variables are used to information to be referenced & manipulated in a computer
program.
2. Three things are required to declare a variable
 Data Type
 Variable Name
 Value
Ex: - data type variable_name = value;
int start = 0;
3. Global Variables can be accessed (used) on any function in the program.
4. Local Variables are declared inside the functions and can be used inside that function.
Some Basic Functions for Controlling the ARDUINO Board
1. pinMode(): - Configures the specified pin to behave either as an input or an output.
Syntax: -
pinMode(pin,mode);
Here pin stands for Digital pin or Analog pin where as mode stands for “INPUT” to
receive a signal or “Output” to send a signal.
Ex: - pinMode(13,OUTPUT);
2. digitalWrite(): - Write a HIGH or a LOW to a digital pin.
Syntax: -
digitalWrite(pin,value);
Here pin stands for only Arduino Digital pin whereas value stands for HIGH (5V) or
LOW (0V)
Ex: - digitalWrite(13,HIGH);
3. delay(): - Pauses the program for the amount of time (in milliseconds) specified as
parameter.
Syntax: -
delay(ms);
Here ms stands for the number of milliseconds to pause.
Ex: - delay(1000);
Note: - 1 second = 1000 ms
Let’s us go with a small program i.e. WAP to blink a light led using Arduino.

Serial Monitor
Serial Communication: Used for communication between the Arduino board and a
computer or other devices. All Arduino boards have at least one serial port (also known as a
UART or USART), and some have several.
UART Communication: UART, or “Universal Asynchronous Receiver-Transmitter”, is one
of the most used device-to-device communication protocols.
Let’s us understand with a small program i.e. WAP to print the output for the given
character as an input.

Numeric Data Types in Arduino Programming


 byte: A byte stores an 8-bit unsigned number, from 0 to 255 (maximum value of
(2^8)-1).
Syntax:
byte var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: byte var = 155;
 word: A word can store an unsigned number of at least 16 bits from 0 to 65535
(maximum value of (2^16)-1).
Syntax:
word var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: word var = 2568;
 short: A short is a 16-bit data type which stores a 16-bit (2 byte) value. This yields a
range of -32,768 to 32,767 (minimum value of 2^15 and a maximum value of (2^15)-
1).
Syntax:
short var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: short var = 1552;
 int: An int stores a 16-bit (2 byte) value. This yields a range of -32,768 to 32,767
(minimum value of 2^15 and a maximum value of (2^15)-1).
Syntax:
int var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: int var = -282;
 long: Long variable are extended size variables for number storage, and store 32 bits
(4 byte). From -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a
maximum value of (2^31)-1).
Syntax:
long var = value
where,
var: variable name.
value: the value to assign to that variable.
Ex: long var = -25682;
 float: Datatype for floating-point numbers, a number that has a decimal point.
Floating-point numbers can be as large as 3.4028235 x 1038 and as low as -3.4028235
x 1038.
Syntax:
float var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: float var = 25.26;
 double: The double implementation is as exactly as float.
Syntax:
double var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: double var = 25.26;
 unsigned int: unsigned ints (unsigned integers) are the same as ints in that they store
a 2 byte value. Instead of storing negative numbers however they only store positive
values, yielding a useful range of 0 to 65,535 ((2^16)-1).
Syntax:
unsigned int var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: unsigned int var = 535;
 unsigned long: unsigned long variables are extended size variables for number
storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won’t store
negative numbers, making their range from 0 to 4,294,967,295 (2^32-1).
Syntax:
unsigned long var = value;
where,
var: variable name.
value: the value to assign to that variable.
Ex: unsigned long var = 2525487;

Text Data Types in Arduino Programming


 char: A data type used to store a character value. Character literals are written in
single quotes, like this: ‘A’.
https://www.arduino.cc/reference/en/ //Character ASCII Code
Syntax:
char var = val;
where,
var: variable name.
value: the value to assign to that variable.
Ex: char var = ‘A’;
 String: A data type used to store set of characters that can also contain spaces and
numbers. Strings are always defined inside double quotes (“Abc”).
Syntax:
String var = val;
where,
var: variable name.
value: the value to assign to that variable.
Ex: String var = “Abc”;
Let us understand Numeric and Text Data Type with an example, i.e. WAP to print
all the Numeric and Text Data Type

Array Data Type in Arduino Programming


Array: An array is a collection of variables that are accessed with an index
number.
Examples:
int val[6];
int val[] = {2,3,4,5,6,7};
int val[6] = {2,3,4,5,6,7};
int val[] = {‘a’, ‘b’, ‘c’, ‘d’};
int val[4] = {‘a’, ‘b’, ‘c’, ‘d’};
int val[] = “abcd”;
int val[4] = “abcd”;

Let us understand more with a help of program i.e. WAP to print element 4 from
integer array {2,3,4,5,6}, print element e from character array {‘a’, ‘b’, ‘c’, ‘d’,
‘e’} and print element banana from String array {“apple”, “mango”, “banana”}
Digital I/O Functions in Arduino Programming
 pinMode(): - Configures the specified pin to behave either as an input or an output.
Syntax: -
pinMode(pin,mode);
Here pin stands for Digital pin or Analog pin where as mode stands for “INPUT” to
receive a signal or “Output” to send a signal.
Ex: - pinMode(13,OUTPUT);
 digitalWrite(): - Write a HIGH or a LOW to a digital pin.
Syntax: -
digitalWrite(pin,value);
Here pin stands for only Arduino Digital pins whereas value stands for HIGH (5V) or
LOW (0V)
Ex: - digitalWrite(13,HIGH);
 digitalRead(): - Reads a value from a specified digital pin, either HIGH or LOW.
Syntax: -
digitalRead(pin);
Here pin stands for Arduino Digital pins
Ex: - digitalRead(12);
Note: - INPUT_PULLUP: - Makes the Digital Pin High initially, until it receives a LOW
Signal from an external device.
Constants in Arduino Programming:
HIGH = 1 = true
LOW = 0 = false
Examples to turn ON LED:

 digitalWrite(13,1);
 digitalWrite(13,true);
 digitalWrite(13,HIGH);

Examples to turn OFF LED:

 digitalWrite(13, 0);
 digitalWrite(13, false);
 digitalWrite(13, LOW);

Lets us understand Digital Pins with a help of Program i.e. WAP to Turn ON or OFF the LED
from the Ardino UNO inbuilt chip.

You might also like