ARDUINO
(INTERNET OF THINGS)
ARDUINO
•Arduino is a prototype platform (open-source) based on an
easy-to-use hardware and software.
•It consists of a circuit board, which can be programed (referred to
as a microcontroller) and a ready-made software called Arduino
IDE (Integrated Development Environment), which is used to
write and upload the computer code to the physical board.
KEY FEATURES…
• Arduino boards are able to read analog or digital input signals from different
sensors and turn it into an output such as activating a motor, turning LED on/off,
connect to the cloud and many other actions.
• You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).
• Additionally, the Arduino IDE uses a simplified version of C++, making it easier to
learn to program.
Arduino Board
Arduino IDE
Analog Reference Digital Pins
Arduino Reset
TX and RX
LEDs
Power Power LED
USB indicator
Crystal Oscillator ICSP pin
Voltage Regulator
Main
microcontroller
Power (Barrel
Jack)
Arduino Reset
Analog pins
Pins (Power Supply)
ARDUINO BOARD
• Power USB: Arduino board can be powered by using the USB cable from
your computer. All you need to do is connect the USB cable to the USB
connection.
• Power (Barrel Jack): Arduino boards can be powered directly from the AC
mains power supply by connecting it to the Barrel Jack.
• Voltage Regulator: The function of the voltage regulator is to control the
voltage given to the Arduino board and stabilize the DC voltages used by the
processor and other elements.
CONTI….
• Crystal Oscillator: The crystal oscillator helps Arduino in dealing with time
issues. How does Arduino calculate time? The answer is, by using the crystal
oscillator.
• Arduino Reset: You can reset your Arduino board, i.e., start your program
from the beginning. You can reset the UNO board in two ways. First, by
using the reset button (17) on the board. Second, you can connect an external
reset button to the Arduino pin labelled RESET (5).
CONTI….
• Pins (3.3, 5, GND, Vin)
1. 3.3V (6) − Supply 3.3 output volt
2. 5V (7) − Supply 5 output volt
3. Most of the components used with Arduino board works fine with 3.3 volt and 5 volt.
4. GND (8)(Ground) − There are several GND pins on the Arduino, any of which can be
used to ground your circuit.
5. Vin (9) − This pin also can be used to power the Arduino board from an external
power source, like AC mains power supply.
CONTI….
• Analog pins: The Arduino UNO board has six analog input pins A0 through
A5. These pins can read the signal from an analog sensor like the humidity
sensor or temperature sensor and convert it into a digital value that can be
read by the microprocessor.
• Main microcontroller: Each Arduino board has its own microcontroller.
You can assume it as the brain of your board. The main IC (integrated circuit)
on the Arduino is slightly different from board to board.
CONTI….
• Power LED indicator: This LED should light up when you plug your Arduino into
a power source to indicate that your board is powered up correctly. If this light does
not turn on, then there is something wrong with the connection.
• TX and RX LEDs: On your board, you will find two labels: TX (transmit) and RX
(receive). They appear in two places on the Arduino UNO board. First, at the digital
pins 0 and 1, to indicate the pins responsible for serial communication. Second, the
TX and RX led . The TX led flashes with different speed while sending the serial
data. The speed of flashing depends on the baud rate used by the board. RX flashes
during the receiving process.
CONTI….
• Digital I/O: The Arduino UNO board has 14 digital I/O pins (of which 6
provide PWM (Pulse Width Modulation) output. These pins can be
configured to work as input digital pins to read logic values (0 or 1) or as
digital output pins to drive different modules like LEDs, relays, etc. The pins
labeled ~ can be used to generate PWM.
• AREF: AREF stands for Analog Reference. It is sometimes, used to set an
external reference voltage (between 0 and 5 Volts) as the upper limit for the
analog input pins.
ARDUINO - PROGRAM STRUCTURE
Sketch − The first new terminology is the Arduino program called sketch.
Structure
• Arduino programs can be divided in three main parts:
• Structure,
• Values (variables and constants),
• Functions
STRUCTURE
Software structure consist of two main functions −
• Setup( ) function
• Loop( ) function
Void setup ( )
{
The setup() function is called when a sketch starts. Use it to initialize
the variables, pin modes, start using libraries, etc. The setup function
}
will only run once, after each power up or reset of the Arduino board.
Void Loop ( ) After creating a setup() function, which initializes and sets the initial
{ values, the loop() function does precisely what its name suggests, and
loops consecutively, allowing your program to change and respond.
} Use it to actively control the Arduino board.
DATA TYPES
Unsigned
void Boolean char byte int
char
Unsigned
long short float double array
long
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.
Example
Void Loop ( ) {
// rest of the code
}
WHAT IS VARIABLE SCOPE?
• 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.
• 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.
OPERATORS
An operator is a symbol that tells the compiler to perform specific mathematical or
logical functions.
• Arithmetic Operators
• Comparison Operators
• Boolean Operators
• Bitwise Operators
• Compound Operators
CONTROL STATEMENTS
Decision making structures require that the programmer specify one or more
conditions to be evaluated or tested by the program.
[Link]. Control Statement & Description
If statement
It takes an expression in parenthesis and a statement or block of statements. If the expression is
1
true then the statement or block of statements gets executed otherwise these statements are
skipped.
If else statement
2 An if statement can be followed by an optional else statement, which executes when the
expression is false.
Ifelse if else statement
3 The if statement can be followed by an optional else if...else statement, which is very useful to
test various conditions using single if...else if statement.
switch case statement
4 Similar to the if statements, switch...case controls the flow of programs by allowing the
programmers to specify different codes that should be executed in various conditions.
Conditional Operator ? :
5
LOOPS
A loop statement allows us to execute a statement or group of statements
multiple times
[Link]
Loop & Description
.
while loop
while loops will loop continuously, and infinitely, until the expression inside the
1
parenthesis, () becomes false. Something must change the tested variable, or the
while loop will never exit.
dowhile loop
The dowhile loop is similar to the while loop. In the while loop, the
2
loop-continuation condition is tested at the beginning of the loop before performed
the body of the loop.
for loop
A for loop executes statements a predetermined number of times. The control
3
expression for the loop is initialized, tested and manipulated entirely within the for
loop parentheses.
FUNCTIONS
• Functions allow structuring the programs in segments of code to perform individual
tasks.
• 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.
ARDUINO - I/O FUNCTIONS
• pinMode() Function: The pinMode() function is used to configure a specific pin to
behave either as an input or an output.
pinMode() Function Syntax
Void setup () {
pinMode (pin , mode);
}
• pin − the number of the pin whose mode you wish to set
• mode − INPUT, OUTPUT
CONTI….
• digitalWrite() Function:
The digitalWrite() function is used to write a HIGH or a LOW value to a
digital pin.
If the pin has been configured as an OUTPUT with pinMode(), its voltage will
be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V
(ground) for LOW.
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or
disable (LOW)
CONTI….
digitalWrite() Function Syntax
Void loop() {
digitalWrite (pin ,value);
}
pin − the number of the pin who
CONTI….
• analogRead( ) function
Six pins marked Analog In. These special pins not only tell whether there is a voltage applied to
them, but also its value. By using the analogRead() function, we can read the voltage applied to
one of the pins.
This function returns a number between 0 and 1023, which represents voltages between 0 and 5
volts. For example, if there is a voltage of 2.5 V applied to pin number 0, analogRead(0) returns
512.
analogRead() function Syntax
analogRead(pin);
pin − the number of the analog input pin to read from (0 to 5 )