Iot Unit-4 Arduino
Iot Unit-4 Arduino
Arduino is an open source electronics platform accompanied with a hardware and software to
The hardware consist of a micro-controllers with other electronics components which can be
Arduino was created in the year 2005 by two Italian engineers David Cuartielles & Massimo Benzi.
Introduction to ARDUINO
To program the Arduino we require the Arduino IDE Software that runs on regular personal
Arduino shields are pre-built circuit boards that are easily plugged on top of your Arduino headers to
It is an open source.
It has large community of people using and troubleshooting it.This makes it easy to help in
debugging projects.
Arduino IDE is cross-platform which means you can run it on Windows,MacintoshOSX,Linux etc.
Disadvantages:
Requires effort to accomplish some tasks such as scheduling and database storage.
If you need more processing power and working memory than you have to switch from Arduino
environment.
Types of Arduino Board
. The hardware features with an open-source hardware board designed around an 8-bit Atmel AVR
Current models consists a USB interface, 6 analog input pins and 14 digital I/O pins that allows the
user to attach
Real time applications of Arduino
The project is designed by using Arduino uno board for the development of home automation
system with Bluetooth which is remotely controlled and operated by an Android OS smart phone.
Houses are becoming smarter and well developed by using such kind of advanced technologies.
Modern houses are gradually increasing the way of design by shifting to centralized control system
This system overcomes this problem by controlling the intensity of LED lights on street by gradually
This system uses arduino board to produce PWM pulses and it is programmed in such a way that it
decreases the voltage applied to these lamps gradually till late nights and completely shutdowns at
morning.
Types of Arduino Board
Arduino Leonardo: Arduino Leonardo is another entry level board that uses the ATmega32u4
microcontroller.
It is Arduino?s first development board to use one microcontroller with built-in USB.
Types of Arduino Board
Arduino 101:
The Arduino 101 is simple and has 32-bit Intel Curie microcontroller.
It?s a board that combines the universal appeal of Arduino with the latest technologies ?like the Intel
Arduino ESPLORA:
The Arduino ESPLORA is an Arduino Leonardo based board with integrated sensors and actuators.
The Esplora has built-in USB communication;it can appear to be connected as a mouse or
Arduino Mini :
It is the smallest Arduino product which is a 24 ?pin microcontroller without any connectors
soldered.
The unit features 8 analog pins and 14 digital pins.The module is based around ATMEGA168
processor.
Types of Arduino Board
Arduino Micro:
Arduino micro is the smallest board of the family,used for interactive computing.
The Micro comes with a built-in USB which makes connection with a computer.
Arduino Nano:
The Nano was the first mini breadboard-compatible board to have onboard USB.
This microcontroller distinguishes itself from the others by having the USB to serial chip and
connector on board.
Types of Arduino Board
Arduino Mega:
It has more digital input/output pins,analog inputs ,a USB connection,a power jack,and a reset
button.
The large no.of pins make this board very handy for projects that require a bunch of digital inputs or
outputs.
Powering Arduino UNO
USB power:
USB port is used to connect the board to your PC for programming and powering up the Arduino
board.
The USB connection is important as it will be through this port where you will upload your code onto
DC Power Jack:
The DC power jack allows your Arduino board to be powered from a wall adapter so that you can
Arduino Integrated Development Environment(IDE) is an open ended software that is mainly used to
It is easily available for operating system like MAC,Windows,Linux and runs on Java platform.
The project file or sketches for a project are saved with the file extension.ino.
The most basic part of the skeleton will have two fucntions:Void setup() and void loop().
Installing Arduino IDE
Click on the download button for the particular OS the user is using.
Once the exe file is generated click on that which will display Arduino Setup License Agreement.
The Arduino IDE is the main text editing program used for Arduino programming.
It is where the programmer has to type the codes before uploading the board.
Menu Bar
Text Editor
Output pane.
Output Pane
The bottom of the main screen is described as an Output Pane that mainly highlights the complaint
status of running code;the memory used by the code,and errors occurred in the program.
Data type-:The kind of data that the variable may hold in a programming language is referred to as
data types.
A character variable occupies one byte of space in memory in which the character constant such as
Int is another type of numerical variable & stores positive or negative numbers.For example: int
y=10;
To store a fraction,you need a floating point type of data variable,called data type float. Float
x=3.333;
Signed variables can have both positive and negative value,so you can store negative numbers.
Keyword Void
It indicates that the function is expected to return no information to the function from which it was
called.
void loop()
Void setup()
Boolean val=false;
Unsigned char:An unsigned char is an unsigned data type that occupies one byte of memory.The
byte m=25;
Different types of variables
Int counter=32;
Word w=1000;
Long: The long variables are extended size variables for number storage and store 32 bits.It ranges
Long velocity=102346;
Different types of variables
short val=15;
double mnum=45.352;
Character strings:Character are written in single quotes whereas strings are written in double
quotes.
Array: An array is a collection of variables that are accessed with an index number.
Size_t is a data type cable of representing the size of any object in bytes.
Variable Scope
The scope of a variable refers to the extent to which different parts of a program have access to the
Local Variables:
Void setup()
void loop()
{ int x,y;
x=0;y=0;z=10;
}
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.
The variables declared prior to the void setup function is called global variables.
Void setup(){ }
Void loop{ }
PREPROCESSOR DIRECTIVE
A preprocessor directive in Embedded C is an indication to the compiler that it must look in to this
In Embedded C programming,we usually use the preprocessor directive to indicate a header file
specific to the microcontroller ,which contains all the SFR?s and bits in those SFR?s.
For example:#include<LiquidCrystal.h>
#include<Keypad.h>
#define directive
The #define directive determine the identifier & sequence of characters that is substituted for the
There are two required functions in an Arduino sketch or a program i.e. setup() and loop().Other
2.User-defined function.
Digital I/0:digitalRead() reads the value from a digital pin.Accepts a pin number as a parameter,and
digitalWrite() writes a HIGH or LOW value to a digital output pin.You pass the pin number and HIGH
or LOW as parameters.
Analog I/O:analogRead()-reads the value from an analog pin.The name of the analog input pin to
analogReference()-configures the value used for the top input range in the analog input,by default
5Vor 3.3V
Standard library of C function in Arduino IDE
analogReadResolution() -lets you change the analog bits resolution for analogRead() by default
10bits.
analogWriteResolution() -lets you change the analog bits resolution for analogWrite() by default
10bits.
Standard library of C function in Arduino IDE
Time functions-:
Math functions:
Communication
Serial.begin()- Everything begins with the serial.begin function.It accepts the parameter inside the
parenthesis as baud rate.It is always written in the setup function and executed only once.
Advanced I/o
shiftIn()-shifts in a byte of data one bit at a time.Starts from either the most or least significant bit.
shiftOut()-shifts out a data one bit at a time.Starts from either the most or least significant bit.
String functions
The function that is defined to perform a set of particular operation is called user-defined function.
These types are based on the formal arguments or parameters passed to the functions and usage
of return statement.
A function is invoked or called without passing any formal argument from the calling portion of a
program and also the function does not return any value to the calling function.
User-defined function
A function is invoked by the calling program and formal arguments are passed from the calling
program but the program does not return any values to the calling program.
A function is invoked with formal arguments from the calling portion of a program nand the function
Whenever we are using an analog sensor,we have to read this type of sensor,we need a different
type of pin.
In the lower- right part of Arduino board,we will see six pins marked ?Analog In?.
These special pins not only tell whether there is voltage applied to them,but also its value.
By using the analogRead() function,we can read the voltage applied to one of the pins.
analogRead() function
By using the analogRead() function,you can read the voltage applied to one of the pins.
Syntax-analogRead(pin);
int analogPin=3;
int val=0;
void setup()
{ Serial.begin(9600);
void loop()
{ val=analogRead(analogPin);
Serial.println(val);
}
Pulse Width Modulation(PWM)
Pulse width modulation or PWM is a common technique used to vary width of the pulses in a pulse
train.
PWM has many applications such as controlling servos and speed controllers,limiting the effective
Duty-Cycle:It is represented as the percentage of time signal that remains on during the period of
PWM signal.
Light Dependent Resistor(Photoresistor)
passive component that decreases resistance with respect to receiving luminosity (light) on the
The resistance of a photoresistor decreases with increase in incident l intensity; in other words, it
exhibits photoconductivity.
Light Dependent Resistor(Photoresistor)
In the dark, a photoresistor can have a resistance as high as several megaohms (M?), while in the
semiconductor give bound electrons enough energy to jump into the conduction band.
Connection of LDR with Arduino
OPERATOR
For instance ,the arithmetic operator(+) &(-) cause us to add or subtract two numbers effectively.
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Pointer operators
Special operators
Arithmetic operators
,subtraction etc.
The data on which these operations are carried out may be a variable or constant.
Sum=a+b;
Arithmetic operators
Subtraction:The subtraction operator subtracts one number from another using minus sign(-).
For example
int x=7,y=2,sub=x-y;
Int y=2;
Int multi;
Multi=x*y;
Serial.print(multi);
Arithmetic operators
Division: The division operator(/) is used to perform division in the Arduino.For example:
Int div;
div=x/y;
float x=7.0;
Float y=2.0;
Float divi;
The remainder operator (or modulo operator) is used to find the remainder after the division of two
numbers.
For example:
Int x=7;
Int y=2;
Int remain;
Remain =x%y;
Let x=2;
x=2;
An expression is a combination of operators,numbers and names that work together to carry out the
computation.
||-Bitwise OR
^-Bitwise XOR
>>-Right shift
<<-Left shift.
Constant & Literals
Constant is a value,written into a program instruction,that does not change during the execution of a
program.
A Literal constant is a value that is typed directly into a source code,whenever it is needed.
String constant
Numeric constant
Character constant
String Constant
marks.
Const.int minimum=-100;
Hexadecimal numbers are integer numbers with a base 16.(0 to 9 and A to F).
Character constant
Character constant is either a single alphabet or a single digit,or a single special symbol enclosed
The const keyword stands for constant.It is a variable qualifier that modifies the behavior of
This means the variable can be used just as many other variable of its type,but its value cannot be
changed.
Conditional statements and loops
Control statements allow you to change the sequence of instructions for execution.
Conditional branching,a program is to decide whether or not to execute next statements based on
If statement:
if (statement)
{statement(s);}
Conditional statements and loops
if (expression)
{ statement1}
else
{statement2}
If the expression within the paranthesis is true, then thye statement will be executed otherwise the
Variable=expression1?expression_2:expression_3;
Nested if ?else statement: Specifying the several if condition and choosing one of them.
If (condition1)
statement1;
Else if (condition2)
statement2;
else if (condition3)
statement3;