SlideShare a Scribd company logo
ARDUINO FUNCTIONS
G. MAHALAKSHMI MALINI, AP/ECE
AVINASHILINGAM INSTITUTE FOR HOME SCIENCE AND HIGHER EDUCATION FOR WOMEN,
SCHOOL OF ENGINEERING
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
DATA TYPES
The following table provides all the data types that you will use during Arduino programming.
void
 The void keyword is used only in function declarations. It indicates that the function is
expected to return no information to the function from which it was called.
Boolean
 A Boolean holds one of two values, true or false. Each Boolean variable occupies one byte of
memory.
 Example
boolean val = false ; // declaration of variable with type boolean and initialize
it with false
boolean state = true ; // declaration of variable with type boolean and initialize
it with true
CHAR
 A data type that takes up one byte of memory that stores a character value. Character literals are written
in single quotes like this: 'A' and for multiple characters, strings use double quotes: "ABC".
 However, characters are stored as numbers. You can see the specific encoding in the ASCII chart. This
means that it is possible to do arithmetic operations on characters, in which the ASCII value of the
character is used. For example, 'A' + 1 has the value 66, since the ASCII value of the capital letter A is
65.
UNSIGNED CHAR
 Unsigned char is an unsigned data type that occupies one byte of memory. The unsigned char data
type encodes numbers from 0 to 255.
Example
Unsigned Char chr_y = 121 ; // declaration of variable
with type Unsigned char and initialize it with character y
BYTE
 A byte stores an 8-bit unsigned number, from 0 to 255.
 Example
byte m = 25 ;//declaration of variable with type byte
and initialize it with 25
INT
 Integers are the primary data-type for number storage. 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).
 The int size varies from board to board. On the Arduino Due, for example, an int stores a 32-bit (4-byte)
value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum
value of (2^31) - 1).
Example
int counter = 32 ;// declaration of variable with type int
and initialize it with 32
UNSIGNED INT
 Unsigned ints (unsigned integers) are the same as int in the way 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). The Due stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295 (2^32 - 1).
 Example
Unsigned int counter = 60 ; // declaration of variable with
type unsigned int and initialize it with 60
WORD
 On the Uno and other ATMEGA based boards, a word stores a 16-bit unsigned number. On the Due and
Zero, it stores a 32-bit unsigned number.
 Example
word w = 1000 ;//declaration of variable with type word
and initialize it with 1000
LONG
 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.
 Example
Long velocity = 102346 ;//declaration of variable with type
Long and initialize it with 102346
UNSIGNED LONG
 Unsigned long variables are extended size variables for number storage and store 32 bits (4 bytes).
Unlike standard longs, unsigned longs will not store negative numbers, making their range from 0 to
4,294,967,295 (2^32 - 1).
 Example
Unsigned Long velocity = 101006 ;// declaration of
variable with type Unsigned Long and initialize it with
101006
SHORT
 A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based), a short 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).
 Example
short val = 13 ;//declaration of variable with type short
and initialize it with 13
FLOAT
 Data type for floating-point number is a number that has a decimal point. Floating-point numbers are
often used to approximate the analog and continuous values because they have greater resolution than
integers.
 Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are
stored as 32 bits (4 bytes) of information.
 Example
float num = 1.352;//declaration of variable with type
float and initialize it with 1.352
DOUBLE
 On the Uno and other ATMEGA based boards, Double precision floating-point number occupies four
bytes. That is, the double implementation is exactly the same as the float, with no gain in precision. On
the Arduino Due, doubles have 8-byte (64 bit) precision.
Example
double num = 45.352 ;// declaration of variable with type
double and initialize it with 45.352
WHAT IS VARIABLE SCOPE?
 Variables in C programming language, which Arduino uses, have a property
called scope. A scope is a region of the program and there are three places
where variables can be declared. They are −
 Inside a function or a block, which is called local variables.
 In the definition of function parameters, which is called formal parameters.
 Outside of all functions, which is called global variables.
LOCAL VARIABLES
 Variables that are declared inside a
function or block are local variables. They
can be used only by the statements that
are inside that function or block of code.
Local variables are not known to function
outside their own. Following is the example
using local variables −
GLOBAL VARIABLES
 Global variables are defined outside
of all the functions, usually at the top
of the program. The global variables
will hold their value throughout the
life-time of your program.
 A global variable can be accessed by
any function. That is, a global variable
is available for use throughout your
entire program after its declaration.
OPERATORS
 An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C
language is rich in built-in operators and provides the following types of operators −
 Arithmetic Operators
 Comparison Operators
 Boolean Operators
 Bitwise Operators
 Compound Operators
ARITHMETIC OPERATORS
COMPARISON OPERATORS
Assume variable A holds 10 and variable B holds 20 then −
Arduino Functions
BOOLEAN OPERATORS
 Assume variable A holds 10 and variable B holds 20 then −
Arduino Functions
 Bitwise Operators
 Assume variable A holds 60 and
variable B holds 13 then −
Arduino Functions
COMPOUND OPERATORS
Arduino Functions
Arduino Functions
CONTROL STATEMENTS
 Decision making structures require that the programmer specify one or more
conditions to be evaluated or tested by the program. It should be along with a
statement or statements to be executed if the condition is determined to be
true, and optionally, other statements to be executed if the condition is
determined to be false.
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
EXAMPLE
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
Arduino Functions
LOOPS
 A loop statement allows us to execute a
statement or group of statements multiple times
and following is the general form of a loop
statement in most of the programming
languages −
 C programming language provides the following types of loops to handle looping requirements.
 while loops will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes
false. Something must change the tested variable, or the while loop will never exit.
 while loop Syntax
while(expression) {
Block of statements;
}
Arduino Functions
 The do…while loop is similar to the while loop. In the while loop, the loop-continuation condition is tested at the
beginning of the loop before performed the body of the loop. The do…while statement tests the loop-continuation
condition after performed the loop body. Therefore, the loop body will be executed at least once.
 When a do…while terminates, execution continues with the statement after the while clause. It is not necessary to
use braces in the do…while statement if there is only one statement in the body. However, the braces are usually
included to avoid confusion between the while and do…while statements.
do…while loop Syntax
do {
Block of statements;
}
while (expression);
 A for loop executes statements a predetermined
number of times. The control expression for the
loop is initialized, tested and manipulated
entirely within the for loop parentheses. It is
easy to debug the looping behavior of the
structure as it is independent of the activity
inside the loop.
 Each for loop has up to three expressions, which
determine its operation. The following example
shows general for loop syntax. Notice that the
three expressions in the for loop argument
parentheses are separated with semicolons.
for loop Syntax
for ( initialize; control; increment or decrement) {
// statement block
}
Example
for(counter = 2;counter <= 9;counter++) {
//statements block will executed 10 times
}
Arduino Functions
Arduino Functions
Arduino Functions
 There are two required functions in an
Arduino sketch or a program i.e. setup ()
and loop(). Other functions must be
created outside the brackets of these two
functions.
 The most common syntax to define a
function is −
FUNCTION DECLARATION
 We can declare the function in two different
ways −
 The first way is just writing the part of the
function called a function prototype above
the loop function, which consists of −
 Function return type
 Function name
 Function argument type, no need to write
the argument name
 Function prototype must be followed by a
semicolon ( ; ).
 The second part, which is called the
function definition or declaration,
must be declared below the loop
function, which consists of −
 Function return type
 Function name
 Function argument type, here you
must add the argument name
 The function body (statements inside
the function executing when the
function is called)
ARRAYS
 The illustration given below shows an integer array
called C that contains 11 elements. You refer to any
one of these elements by giving the array name
followed by the particular element’s position number
in square brackets ([]). The position number is more
formally called a subscript or index (this number
specifies the number of elements from the beginning
of the array). The first element has subscript 0 (zero)
and is sometimes called the zeros element.
 Thus, the elements of array C are C[0] (pronounced
“C sub zero”), C[1], C[2] and so on. The highest
subscript in array C is 10, which is 1 less than the
number of elements in the array (11). Array names
follow the same conventions as other variable
names.
 Let us examine array C in the given figure, more closely. The name of the entire array is C. Its 11
elements are referred to as C[0] to C[10]. The value of C[0] is -45, the value of C[1] is 6, the value of
C[2] is 0, the value of C[7] is 62, and the value of C[10] is 78.
 To print the sum of the values contained in the first three elements of array C, we would write −
 Serial.print (C[ 0 ] + C[ 1 ] + C[ 2 ] );
 To divide the value of C[6] by 2 and assign the result to the variable x, we would write −
 x = C[ 6 ] / 2;
DECLARING ARRAYS
 use a declaration of the form −
 type arrayName [ arraySize ] ;
 For example, to tell the compiler to reserve 11 elements for integer array C, use the declaration −
 int C[ 12 ]; // C is an array of 12 integers
STRINGS
 There are two types of strings in Arduino programming −
 Arrays of characters, which are the same as the strings used in C programming.
 The Arduino String, which lets us use a string object in a sketch.
 In this chapter, we will learn Strings, objects and the use of strings in Arduino sketches. By the end of
the chapter, you will learn which type of string to use in a sketch.
STRING CHARACTER ARRAYS
 The first type of string that we will learn is the string that is a series of characters of the type char. In the
previous chapter, we learned what an array is; a consecutive series of the same type of variable stored
in memory. A string is an array of char variables.
 A string is a special array that has one extra element at the end of the string, which always has the
value of 0 (zero). This is known as a "null terminated string".
Arduino Functions
 This same example can be written in a more convenient way as shown below −
MANIPULATING STRING
ARRAYS
 We can alter a string array
within a sketch as shown in
the following sketch.
Arduino Functions

More Related Content

What's hot (20)

PPTX
Basics of arduino uno
Rahat Sood
 
PPTX
Lesson sample introduction to arduino
Betsy Eng
 
PPT
Intro to Arduino
avikdhupar
 
PDF
Arduino - Classes and functions
Emertxe Information Technologies Pvt Ltd
 
PPTX
Embedded System Tools ppt
Halai Hansika
 
PPT
arduino-ppt
jhcid
 
PDF
Arduino IDE
Mrunal Deshkar
 
PPTX
Introduction to Node MCU
Amarjeetsingh Thakur
 
PPTX
Architecture of 8051
hello_priti
 
PPTX
Programming with arduino
Makers of India
 
PPT
Arduino
vipin7vj
 
PPTX
Combinational circuit
Satya P. Joshi
 
PPTX
Introduction to Arduino
yeokm1
 
PPTX
Interfacing Stepper motor with 8051
Pantech ProLabs India Pvt Ltd
 
DOCX
Instruction set of 8086
Vijay Kumar
 
PPTX
Introduction of CPU.pptx
GauravSharmaIAHAP
 
PDF
Arduino Lecture 1 - Introducing the Arduino
Eoin Brazil
 
PPTX
Arm instruction set
PriyangaKR1
 
PPT
Adc interfacing
Monica Gunjal
 
PPTX
microcontroller vs microprocessor
sobhadevi
 
Basics of arduino uno
Rahat Sood
 
Lesson sample introduction to arduino
Betsy Eng
 
Intro to Arduino
avikdhupar
 
Arduino - Classes and functions
Emertxe Information Technologies Pvt Ltd
 
Embedded System Tools ppt
Halai Hansika
 
arduino-ppt
jhcid
 
Arduino IDE
Mrunal Deshkar
 
Introduction to Node MCU
Amarjeetsingh Thakur
 
Architecture of 8051
hello_priti
 
Programming with arduino
Makers of India
 
Arduino
vipin7vj
 
Combinational circuit
Satya P. Joshi
 
Introduction to Arduino
yeokm1
 
Interfacing Stepper motor with 8051
Pantech ProLabs India Pvt Ltd
 
Instruction set of 8086
Vijay Kumar
 
Introduction of CPU.pptx
GauravSharmaIAHAP
 
Arduino Lecture 1 - Introducing the Arduino
Eoin Brazil
 
Arm instruction set
PriyangaKR1
 
Adc interfacing
Monica Gunjal
 
microcontroller vs microprocessor
sobhadevi
 

Similar to Arduino Functions (20)

PPS
Programming in Arduino (Part 1)
Niket Chandrawanshi
 
PDF
Lecture 2
Mohamed Zain Allam
 
PPTX
Microcontroller lec 3
Ibrahim Reda
 
PDF
Arduino for Beginners
Sarwan Singh
 
PPT
Lập trình C
Viet NguyenHoang
 
PPTX
Introduction to c
Ajeet Kumar
 
PPTX
dinoC_ppt.pptx
DinobandhuThokdarCST
 
PPT
Arduino Section Programming - from Sparkfun
JhaeZaSangcapGarrido
 
PPTX
C programming
PrincyMaria
 
PPT
C the basic concepts
Abhinav Vatsa
 
PPT
C tutorial
Anurag Sukhija
 
PPTX
Lecture 3
marvellous2
 
PPTX
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
PDF
Embedded_C_1711824726engéiiiring_with_the_best.pdf
AliAbdelli
 
PDF
Functions
Learn By Watch
 
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
Rai University
 
PPTX
C programming
AsifRahaman16
 
PDF
C Programming
Adil Jafri
 
PPTX
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 
Programming in Arduino (Part 1)
Niket Chandrawanshi
 
Microcontroller lec 3
Ibrahim Reda
 
Arduino for Beginners
Sarwan Singh
 
Lập trình C
Viet NguyenHoang
 
Introduction to c
Ajeet Kumar
 
dinoC_ppt.pptx
DinobandhuThokdarCST
 
Arduino Section Programming - from Sparkfun
JhaeZaSangcapGarrido
 
C programming
PrincyMaria
 
C the basic concepts
Abhinav Vatsa
 
C tutorial
Anurag Sukhija
 
Lecture 3
marvellous2
 
CHAPTER 3 STRUCTURED PROGRAMMING.pptx 2024
ALPHONCEKIMUYU
 
Embedded_C_1711824726engéiiiring_with_the_best.pdf
AliAbdelli
 
Functions
Learn By Watch
 
Bsc cs i pic u-2 datatypes and variables in c language
Rai University
 
C programming
AsifRahaman16
 
C Programming
Adil Jafri
 
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 
Ad

More from mahalakshmimalini (17)

PPTX
Arduino
mahalakshmimalini
 
PPTX
Electronics components and connections
mahalakshmimalini
 
PPTX
Arduino Family
mahalakshmimalini
 
PPTX
Arduino IDE
mahalakshmimalini
 
PPTX
Design challenges in embedded systems
mahalakshmimalini
 
PPT
Dc machines
mahalakshmimalini
 
PPTX
Introduction to python
mahalakshmimalini
 
PPTX
18 beps02 electrical technology
mahalakshmimalini
 
PPTX
Presentation1
mahalakshmimalini
 
PDF
Pic 16 f877a architecture1
mahalakshmimalini
 
PDF
8086 memory segmentation
mahalakshmimalini
 
PDF
Energy Harvesting for Wearable Devices
mahalakshmimalini
 
PPTX
Artifical Neural Network
mahalakshmimalini
 
PPTX
Memory interfacing
mahalakshmimalini
 
PPTX
Background to nanotechnology
mahalakshmimalini
 
PPTX
Introduction to nano technology
mahalakshmimalini
 
PPTX
Unit I - Introduction to VLSI
mahalakshmimalini
 
Electronics components and connections
mahalakshmimalini
 
Arduino Family
mahalakshmimalini
 
Arduino IDE
mahalakshmimalini
 
Design challenges in embedded systems
mahalakshmimalini
 
Dc machines
mahalakshmimalini
 
Introduction to python
mahalakshmimalini
 
18 beps02 electrical technology
mahalakshmimalini
 
Presentation1
mahalakshmimalini
 
Pic 16 f877a architecture1
mahalakshmimalini
 
8086 memory segmentation
mahalakshmimalini
 
Energy Harvesting for Wearable Devices
mahalakshmimalini
 
Artifical Neural Network
mahalakshmimalini
 
Memory interfacing
mahalakshmimalini
 
Background to nanotechnology
mahalakshmimalini
 
Introduction to nano technology
mahalakshmimalini
 
Unit I - Introduction to VLSI
mahalakshmimalini
 
Ad

Recently uploaded (20)

PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Digital water marking system project report
Kamal Acharya
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Design Thinking basics for Engineers.pdf
CMR University
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 

Arduino Functions

  • 1. ARDUINO FUNCTIONS G. MAHALAKSHMI MALINI, AP/ECE AVINASHILINGAM INSTITUTE FOR HOME SCIENCE AND HIGHER EDUCATION FOR WOMEN, SCHOOL OF ENGINEERING DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
  • 2. DATA TYPES The following table provides all the data types that you will use during Arduino programming.
  • 3. void  The void keyword is used only in function declarations. It indicates that the function is expected to return no information to the function from which it was called.
  • 4. Boolean  A Boolean holds one of two values, true or false. Each Boolean variable occupies one byte of memory.  Example boolean val = false ; // declaration of variable with type boolean and initialize it with false boolean state = true ; // declaration of variable with type boolean and initialize it with true
  • 5. CHAR  A data type that takes up one byte of memory that stores a character value. Character literals are written in single quotes like this: 'A' and for multiple characters, strings use double quotes: "ABC".  However, characters are stored as numbers. You can see the specific encoding in the ASCII chart. This means that it is possible to do arithmetic operations on characters, in which the ASCII value of the character is used. For example, 'A' + 1 has the value 66, since the ASCII value of the capital letter A is 65.
  • 6. UNSIGNED CHAR  Unsigned char is an unsigned data type that occupies one byte of memory. The unsigned char data type encodes numbers from 0 to 255. Example Unsigned Char chr_y = 121 ; // declaration of variable with type Unsigned char and initialize it with character y
  • 7. BYTE  A byte stores an 8-bit unsigned number, from 0 to 255.  Example byte m = 25 ;//declaration of variable with type byte and initialize it with 25
  • 8. INT  Integers are the primary data-type for number storage. 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).  The int size varies from board to board. On the Arduino Due, for example, an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) - 1). Example int counter = 32 ;// declaration of variable with type int and initialize it with 32
  • 9. UNSIGNED INT  Unsigned ints (unsigned integers) are the same as int in the way 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). The Due stores a 4 byte (32-bit) value, ranging from 0 to 4,294,967,295 (2^32 - 1).  Example Unsigned int counter = 60 ; // declaration of variable with type unsigned int and initialize it with 60
  • 10. WORD  On the Uno and other ATMEGA based boards, a word stores a 16-bit unsigned number. On the Due and Zero, it stores a 32-bit unsigned number.  Example word w = 1000 ;//declaration of variable with type word and initialize it with 1000
  • 11. LONG  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.  Example Long velocity = 102346 ;//declaration of variable with type Long and initialize it with 102346
  • 12. UNSIGNED LONG  Unsigned long variables are extended size variables for number storage and store 32 bits (4 bytes). Unlike standard longs, unsigned longs will not store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1).  Example Unsigned Long velocity = 101006 ;// declaration of variable with type Unsigned Long and initialize it with 101006
  • 13. SHORT  A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based), a short 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).  Example short val = 13 ;//declaration of variable with type short and initialize it with 13
  • 14. FLOAT  Data type for floating-point number is a number that has a decimal point. Floating-point numbers are often used to approximate the analog and continuous values because they have greater resolution than integers.  Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.  Example float num = 1.352;//declaration of variable with type float and initialize it with 1.352
  • 15. DOUBLE  On the Uno and other ATMEGA based boards, Double precision floating-point number occupies four bytes. That is, the double implementation is exactly the same as the float, with no gain in precision. On the Arduino Due, doubles have 8-byte (64 bit) precision. Example double num = 45.352 ;// declaration of variable with type double and initialize it with 45.352
  • 16. WHAT IS VARIABLE SCOPE?  Variables in C programming language, which Arduino uses, have a property called scope. A scope is a region of the program and there are three places where variables can be declared. They are −  Inside a function or a block, which is called local variables.  In the definition of function parameters, which is called formal parameters.  Outside of all functions, which is called global variables.
  • 17. LOCAL VARIABLES  Variables that are declared inside a function or block are local variables. They can be used only by the statements that are inside that function or block of code. Local variables are not known to function outside their own. Following is the example using local variables −
  • 18. GLOBAL VARIABLES  Global variables are defined outside of all the functions, usually at the top of the program. The global variables will hold their value throughout the life-time of your program.  A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration.
  • 19. OPERATORS  An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −  Arithmetic Operators  Comparison Operators  Boolean Operators  Bitwise Operators  Compound Operators
  • 21. COMPARISON OPERATORS Assume variable A holds 10 and variable B holds 20 then −
  • 23. BOOLEAN OPERATORS  Assume variable A holds 10 and variable B holds 20 then −
  • 25.  Bitwise Operators  Assume variable A holds 60 and variable B holds 13 then −
  • 30. CONTROL STATEMENTS  Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program. It should be along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
  • 49. LOOPS  A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages −
  • 50.  C programming language provides the following types of loops to handle looping requirements.  while loops will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit.  while loop Syntax while(expression) { Block of statements; }
  • 52.  The do…while loop is similar to the while loop. In the while loop, the loop-continuation condition is tested at the beginning of the loop before performed the body of the loop. The do…while statement tests the loop-continuation condition after performed the loop body. Therefore, the loop body will be executed at least once.  When a do…while terminates, execution continues with the statement after the while clause. It is not necessary to use braces in the do…while statement if there is only one statement in the body. However, the braces are usually included to avoid confusion between the while and do…while statements. do…while loop Syntax do { Block of statements; } while (expression);
  • 53.  A for loop executes statements a predetermined number of times. The control expression for the loop is initialized, tested and manipulated entirely within the for loop parentheses. It is easy to debug the looping behavior of the structure as it is independent of the activity inside the loop.  Each for loop has up to three expressions, which determine its operation. The following example shows general for loop syntax. Notice that the three expressions in the for loop argument parentheses are separated with semicolons. for loop Syntax for ( initialize; control; increment or decrement) { // statement block } Example for(counter = 2;counter <= 9;counter++) { //statements block will executed 10 times }
  • 57.  There are two required functions in an Arduino sketch or a program i.e. setup () and loop(). Other functions must be created outside the brackets of these two functions.  The most common syntax to define a function is −
  • 58. FUNCTION DECLARATION  We can declare the function in two different ways −  The first way is just writing the part of the function called a function prototype above the loop function, which consists of −  Function return type  Function name  Function argument type, no need to write the argument name  Function prototype must be followed by a semicolon ( ; ).
  • 59.  The second part, which is called the function definition or declaration, must be declared below the loop function, which consists of −  Function return type  Function name  Function argument type, here you must add the argument name  The function body (statements inside the function executing when the function is called)
  • 60. ARRAYS  The illustration given below shows an integer array called C that contains 11 elements. You refer to any one of these elements by giving the array name followed by the particular element’s position number in square brackets ([]). The position number is more formally called a subscript or index (this number specifies the number of elements from the beginning of the array). The first element has subscript 0 (zero) and is sometimes called the zeros element.  Thus, the elements of array C are C[0] (pronounced “C sub zero”), C[1], C[2] and so on. The highest subscript in array C is 10, which is 1 less than the number of elements in the array (11). Array names follow the same conventions as other variable names.
  • 61.  Let us examine array C in the given figure, more closely. The name of the entire array is C. Its 11 elements are referred to as C[0] to C[10]. The value of C[0] is -45, the value of C[1] is 6, the value of C[2] is 0, the value of C[7] is 62, and the value of C[10] is 78.  To print the sum of the values contained in the first three elements of array C, we would write −  Serial.print (C[ 0 ] + C[ 1 ] + C[ 2 ] );  To divide the value of C[6] by 2 and assign the result to the variable x, we would write −  x = C[ 6 ] / 2;
  • 62. DECLARING ARRAYS  use a declaration of the form −  type arrayName [ arraySize ] ;  For example, to tell the compiler to reserve 11 elements for integer array C, use the declaration −  int C[ 12 ]; // C is an array of 12 integers
  • 63. STRINGS  There are two types of strings in Arduino programming −  Arrays of characters, which are the same as the strings used in C programming.  The Arduino String, which lets us use a string object in a sketch.  In this chapter, we will learn Strings, objects and the use of strings in Arduino sketches. By the end of the chapter, you will learn which type of string to use in a sketch.
  • 64. STRING CHARACTER ARRAYS  The first type of string that we will learn is the string that is a series of characters of the type char. In the previous chapter, we learned what an array is; a consecutive series of the same type of variable stored in memory. A string is an array of char variables.  A string is a special array that has one extra element at the end of the string, which always has the value of 0 (zero). This is known as a "null terminated string".
  • 66.  This same example can be written in a more convenient way as shown below −
  • 67. MANIPULATING STRING ARRAYS  We can alter a string array within a sketch as shown in the following sketch.