Arduino Programming Notes
Arduino Programming Notes
1
7. Curly brackets ({}) are used to start and end
the void setup and void loop.
8. The program/code Arduino Uno is case
sensitive; means we can't change any format.
For e.g. we cannot write void loop as Void loop.
9. // is used to write any important point in code
for our understanding. And by adding // in front
of that point the Arduino Uno will not consider
that point and will execute next line.
10. Putting semicolon after every end of the
code is compulsory, otherwise is will show error
in the code
-----------------------------------------------------------
End of Tutorial 1
2
Tutorial 2: Using Variables
1. Variables are used to store information or
data in Arduino program. And when we have to
access that data or information we can use that
variable to access that data or information.
2. To store data in variables in Arduino
programming, we require following three
things:-
i. Data type
ii. Variable name
iii. Value
i. Data type:-
It defines the type of the data that we
have to store. For e.g. the data which we
have to store is in numeric form or in
alphabetic form.
ii. Variable name
To store the information or data we give a
specific name to that variable.
iii. Value
Value means the data which me have to
store in variable.
Syntax:-
data_type variable_name = value
For e.g. int val = 10;
Note
We can also write int val; but the value of val
will be 0.
3
int full form is integer which is used to store
numbers
-----------------------------------------------------------
End of Tutorial 2
4
Tutorial 3: Writing Our First Program
1. Some Basic function For Controlling the
Arduino Board
a.pinMode()
-> Definition: We use this function to tell the
Arduino Board that which pins we have to use.
And also we tell to Arduino board that from
that pin we have to send output or receive any
input.
-> Syntax: pinMode(pin,mode);
-> pin: Arduino pin
mode: INPUT/OUTPUT
-> For e.g. pinMode(13,OUTPUT);
b. digitalWrite()
-> Definition: Through digitalWrite() we can
send two types of signal to digital pin of
Arduino to any output device. These two type
of signal are HIGH or LOW. From HIGH we can
send 5v to any digital pin and from LOW we
can send 0v to any digital pin.
-> Syntax: digitalWrite(pin,value);
-> pin: Arduino pin
value: HIGH/LOW
-> For e.g. digitalWrite(13,HIGH)
c.delay ()
5
-> Definition: We use delay function to pause
our program at a particular line for some
time(in milliseconds).
-> Syntax: delay(ms);
-> ms: The number of millisecond to pause the
code.
-> For e.g. delay (1000);
Arduino Uno Programming
-----------------------------------------------------------
End of Tutorial 3
6
Tutorial 4: Serial Monitor
1. Digital pin 0 and 1 which is also known as TX
and RX respectively uses UART communication
protocol to communicate data, and this UART
communication is known as Serial
communication too. In any sensor, if we see RX
and TX pin, it means that that sensor
communicate data by UART communication
protocol.
Note
UART full form is Universal Asynchronous
Receiver Transmitter.
Full form of:-
TX – Transmitter pin
RX – Receiver pin
7
Sending
TX RX
Microcontroller Device
RX TX
Receivin
1. Some g
Basic function For
Serial Monitor
a) Serial.begin()
We use it to start the Serial Communication.
b) Serial.read()
It will read the communication between
Microcontroller and device.
c) Serial.print()
It is used to print the communication at the
screen.
d) Serial.avaliable()
It is used to print the message send by
microcontroller when the communication has
started.
-----------------------------------------------------------
End of Tutorial 4
8
-> Definition: A byte stores an 8-bit
unsigned number, from 0 to 255
(maximum value of (28) - 1).
-> Syntax: byte var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. byte var = 155;
b) word
-> Definition: A word can store an
unsigned number of at least 16 bits from 0
to 65535 (maximum) value of (216) - 1).
-> Syntax: word var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. word var = 2568;
9
c) short
-> Definition: A short is a 16-bit data type.
A short stores a 16-bit (2-byte) value. This
yields a range of -32,768 to
32,767(minimum value of -215 and a
maximum value of (215) - 1).
-> Syntax: short var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. short var = 1552;
d) int
-> Definition: An int stores a 16-bit (2-
byte) value. This yields a range of -32,768
to 32,767 (minimum value of -215 amd a
maximum value of (215) - 1).
-> Syntax: int var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. int var = -282;
e) long
10
-> Definition: Long variables are extended
size variables for number storage, and
store 32 bits (4 bytes), from -
2,147,483,648 to 2,147,483,647
(maximum value of -231 and a maximum
value of (231) - 1).
-> Syntax: long var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. long var = -25682;
f) float
-> Definition: Data type for floating-point
numbers, a number that has decimal point.
Floating-point numbers can be as large as
3.4028235x1038 and as low as
-3.4028235x1038.
-> Syntax: float var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. float var = -25.26;
g) double
-> Definition: The double implementation
is exactly the same as the float.
11
-> Syntax: double var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. double var = 25.26;
h) unsigned int
-> Definition: Unsigned ints (unsigned
integers) are same as ints in that they
store a 2 byte value. Instead of storing
negative however they only stores positive
values, yielding a useful range of 0 to
65,535 ((216) - 1).
-> Syntax: unsigned int var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. unsigned int var = 25;
12
i) unsigned int
-> Definition: 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 ((216) - 1).
-> Syntax: unsigned int var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. unsigned int var = 25;
j) unsigned long
-> Definition: Unsigned long variables are
extended size variables for numbers
storage, and stores 32 bits (4 bytes).
Unlike standard longs unsigned longs
won’t store negative numbers, making
their range from 0 to 4,294,967,295 ((232 )
- 1).
-> Syntax: unsigned long var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. unsigned long var = 2525487;
-----------------------------------------------------------
End of Tutorial 5
13
Tutorial 6: Text Data Types
Text Data Types In Arduion Programming
a) char
-> Definition: A
-> Syntax: byte var = value;
-> var: variable name
value: the value to assign to that
variable
-> For e.g. byte var = 155;
14