Professional Documents
Culture Documents
1
Machine to Machine Communications
2
Introduction to Arduino Programming
2 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
3 / 73
Introduction
4 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
5 / 73
M2M
6 / 73
I. The M2M area network comprises work.
of machines or M2M nodes which • While the M2M area networks use
have embedded hardware modules for either proprietary or non-IP-based
sensing, actuation and communica- communication protocols the com-
tion. munication network uses IP based
• Various communication protocols network
can be used for M2M local area • This network can use either wired
networks such as Zigbee, Blue- or wireless networks
tooth, 6LoWPAN, IEEE 802.15.4, • To enable the communication be-
Etc. tween remote non-IP based M2M
• These communication protocols area networks, M2M gateways are
provide connectivity between M2M used
nodes within an M2M area net-
7 / 73
II. The communication between the • With an M2M Gateway, each node
M2M nodes and the M2M Gateway in an M2M area Netwerk appears
is based on the communication pro- as a virtualized node for external
tocols which are native to the M2M M2M area networks
area network
• M2M gateway performs protocol
translations to enable IP connec-
tivity for M2M area networks.
• M2M gateway acts as a proxy for
performing translations from/to
native protocols to/from the Inter-
net protocol (IP)
8 / 73
III. The M2M data is gathered into some home automation, industrial au-
point solutions, such as enterprise tomation, smart grid, etc.
applications, service management, • M2M solution designs, such as
applications, or remote monitoring data connection and storage archi-
applications. tectures and applications are spe-
• M2M has various application do- cific to the M2M application do-
mains such as smart metering, main.
9 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
10 / 73
DIfference between IoT and M2M
Though both M2M and IoT involve networking of machines or devices, they differ in
the underlying technologies, systems architectures and types of applications
14 / 73
Current Challenges in IoT
15 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
16 / 73
What is Interoperability ?
17 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
18 / 73
Why Interoperability is Important in Context of IoT ?
I. To fulfill the IoT objectives tion protocols such as ZigBee
• Physical objects can interact with (IEEE 802.15.4), Bluetooth (IEEE
any other physical objects and can 802.15.1), GPRS, 6LowPAN, and
share their information Wi-Fi (IEEE 802.11)
• Any device can communicate with • Different wired communication
other devices anytime from any- protocols like Ethernet (IEEE
where 802.3) and Higher Layer LAN Pro-
• Machine to Machine communi- tocols (IEEE 802.1)
cation(M2M), Device to Device • Different programming languages
Communication (D2D), Device to used in computing systems and
Machine Communication (D2M) websites such as JavaScript, JAVA,
• Seamless device integration with C, C++, Visual Basic, PHP, and
IoT network Python
II. Heterogeneity • Different hardware platforms such
• Different wireless communica- as Crossbow, NI, etc.
19 / 73
III. Different operating systems IV. Different databases: DB2,
• As an example for sensor node: MySQL, Oracle, PostgreSQL,
TinyOS, SOS, Mantis OS, RE- SQLite, SQL Server, and Sybase
TOS, and mostly vendor specific V. Different data representations
OS VI. Different control models
• As an example for personal com- VII. Syntactic or semantic interpreta-
puter: Windows, Mac, Unix, and tions
Ubuntu
20 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
21 / 73
Different Types of Interoperability
22 / 73
Example:
• Using IoT, both A and B provide a real- × User U can’t understand the service
time security service provided by A and B
• A is placed at Delhi, India, while B is × Similarly, A and B do not mutually
placed at Tokyo, Japan understand each other
• A, B, U use Hindi, Japanese, and English
language, respectively
• User U wants real-time service of CCTV
camera from the device A and B
• Problems are listed below
× user does not know the devices A and
B
× Devices A and B are different in
terms of syntactic and semantic no-
tions
× Therefore, it is difficult to find CCTV
device
23 / 73
User Interoperability
26 / 73
Device Interoperability
28 / 73
Arduino Board
Board Details:
i. Power Supply: USB or power barrel
jack
ii. Voltage Regulator
iii. LED Power Indicator
iv. Tx-Rx LED Indicator
v. Output power, Ground 30 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
31 / 73
Setup
• Arduino IDE is an open source software • TOOLS -> PORT -> select your port
that is used to program the Arduino con-
troller board
• Based on variations of the C and C++
programming language
• It can be downloaded from Arduino’s of-
ficial website and installed into PC
• Power the board by connecting it to a
PC via USB cable
• Launch the Arduino IDE
• Set the board type and the port for the
board
• TOOLS -> BOARD -> select your
board
32 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
33 / 73
Arduino IDE
34 / 73
The list of actions that can be performed
with the sketches are:
• Verify: Checks the code for compilation
errors
• Upload: Uploads the final code to the
controller board
• New: Creates a new blank sketch with
basic structure
• Open: Opens an existing sketch
• Save: Saves the current sketch
35 / 73
• Serial Monitor: Opens the serial con-
sole
• All the data printed to the console are
displayed here
36 / 73
Structure of a Sketch
i. A sketch can be divided into two parts: void setup(){
I. setup() Serial.begin(9600);
II. loop() }
ii. The function setup() is the point
where the code starts, just like the void loop(){
main() function in C and C++ Serial.println("Hello World !");
iii. I/O Variables, pin modes are initial- }
ized in the setup() function
iv. loop() function, as the name sug-
gests, iterates the specified task in the
program
37 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
38 / 73
Supported Datatypes
39 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
40 / 73
Function Libraries
Input/Output Functions: • digitalRead(pin) : Reads a
• The arduino pins can be config- HIGH or LOW value from a digi-
ured to act as input or output pins tal pin
using the pinMode(pin, mode) • analogWrite(pin, HIGH) :
function Writes a value between 0 and 255
I. pin - pin number on the Ar- value to a digital PWM (pulse
duino board width modulation) pin
II. mode- INPUT/OUTPUT • analogRead(pin) : Reads from
• digitalWrite(pin, HIGH) : the analog input pin i.e., voltage
Writes a HIGH or LOW value to applied across the pin
a digital pin
41 / 73
• Character functions such as • delay() function is one of the
i. isdigit(), most common time manipulation
ii. isalpha(), function used to provide a delay
iii. isalnum(), of specified time. It accepts inte-
iv. isxdigit(), ger value (time in miliseconds)
v. islower(),
vi. isupper(),
vii. isspace()
viii. return 1 (true) or 0 (false)
42 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
43 / 73
Operators
• Arithmetic Operators:
=, +, -, *, /, %
• Comparison Operator:
==, !=, <, >, <=, >=
• Boolean Operator:
&&, ||, !
• Bitwise Operator:
&, |, ^, ~, <<, >>,
• Compound Operator:
++, --, +=, -=, *=, /=, %=, |=, &=
44 / 73
Control Statement
I. If statement
if(condition){
statements if the condition is true;
}
II. If-Else statement
if(condition){
statements if the condition is true;
}else{
statements if the condition is false;
}
45 / 73
III. If-Elseif-Else statement
if(condition1){
statements if the condition1 is true;
}else if(condition2){
statements if the condition1 is false and condition2 is true;
}else{
statements if both the conditions are false;
}
IV. Switch-Case statement
switch(choice){
case opt1: statement_1;break;
case opt2: statement_2;break;
.
case default: statement_default;break;
}
V. Conditional Operator
val=(condition)?(statement1):(statement2)
46 / 73
Loops
I. For loop:
for(initialization; condition; increment){
Statement till the condition is true;
}
II. While loop:
while(condition){
Statement till the condition is true;
}
III. Do-While loop:
do{
Statement till the condition is true;
}while(condition);
IV. Nested loop: Calling a loop inside another loop
V. Infinite loop: Condition of the loop is always true, the loop will never terminate
47 / 73
Arrays
• Collection of elements having homogenous datatype that are stored in adjacent
memory location.
• The conventional starting index is 0.
• Declaration of array:
<Datatype> array_name[size];
int values[5];
• Alternative Declaration:
int values[] = {0,1,2,3,4};
int values[5] = {0,1,2};
• Multi-dimentional array Declaration:
<Datatype> array_name[n1][n2][n3]... ;
int values[row][col][height];
int values[5];
48 / 73
String
• Array of characters with NULL as termination is termed as a String.
• Declaration using array:
char str[] = "ABCD";
char str[4];
str[0] = 'A';
str[1] = 'B';
str[2] = 'C';
str[3] = 'D';
• Declaration using String Object:
String str = "ABCD";
• Functions of String Object:
◦ str.ToUpperCase(): change all the characters of str to upper case
◦ str.replace(str1,str2): is str1 is the sub string of str then it will be
replaced by str2
◦ str.length(): returns the length of the string without considering null
49 / 73
Math Library
• To apply the math functions and mathematical constants, “MATH.h”
header files is needed to be included.
• Functions:
◦ cos(double radian);
◦ sin(double radian);
◦ tan(double radian);
◦ fabs(double val);
◦ fmod(double val1, double val2);
◦ exp(double val);
◦ log(double val);
◦ log10(double val);
◦ square(double val);
◦ pow(double base, double power); 50 / 73
Random Number
51 / 73
Interrupts
• An external signal for which system blocks the current running process
to process that signal
• Types:
I. Hardware interrupt
II. Software interrupt
• digitalPinToInterrupt(pin): Change actual digital pin to the
specific interrupt number.
• attachInterrupt(digitalPinToInterrupt(pin), ISR,
mode);
◦ ISR: a interrupt service routine have to be defined
52 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
53 / 73
1. Write a program to blink the built-in LED of Arduino
void setup() {
pinMode(LED_BUILTIN , OUTPUT);
}
void loop(){
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
54 / 73
2. Write a program to implement a traffic signal that operates
continuously as follows: red - 2 secs, orange - 1 secs and green -
2 secs
const int LED_RED = 2;
const int LED_ORANGE = 3;
const int LED_GREEN = 4;
void setup() {
pinMode(LED_RED , OUTPUT);
pinMode(LED_ORANGE , OUTPUT);
pinMode(LED_GREEN , OUTPUT);
digitalWrite(LED_RED, LOW);
digitalWrite(LED_ORANGE, LOW);
digitalWrite(LED_GREEN, LOW);
}
void loop(){
digitalWrite(LED_RED, HIGH);
delay(2000);
digitalWrite(LED_RED, LOW);
digitalWrite(LED_ORANGE, HIGH);
delay(1000);
digitalWrite(LED_ORANGE, LOW);
digitalWrite(LED_GREEN, HIGH);
delay(2000);
digitalWrite(LED_GREEN, LOW);
} 55 / 73
3. Write an Arduino program to gradually increase and decrease the
brightness of an LED connected to an PWM pin.
const int LED = 3;
int step ;
void setup(){
pinMode(LED, OUTPUT);
}
void loop(){
for(step=0; step<=255; step++){
analogWrite(LED, step);
delay(20);
}
for(step=255; step>=0; step--){
analogWrite(LED, step);
delay(20);
}
}
56 / 73
4. Write an Arduino program to randomly change the colours of an
RGB LED every second and print the RGB values used to the serial
monitor.
const int myPINS[] = {6,9,11};
int i, value;
void setup(){
for(i=0; i<3; i++){
pinMode(myPINS[i],OUTPUT);
}
Serial.begin(9600);
}
void loop(){
for(i=0; i<3; i++){
value = random(0, 255);
analogWrite(myPINS[i], value);
Serial.print(i);
Serial.print(":");
Serial.println(value);
}
Serial.println();
delay(500);
}
57 / 73
5. Write a sketch to turn-on an LED when a push button is pressed
and turn-off when button is released.
const int BUTTON = 2;
const int LED = 13;
int buttonState = 0;
void setup(){
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
}
void loop(){
buttonState = digitalRead(BUTTON);
if(buttonState == HIGH){
digitalWrite(LED, HIGH);
}else{
digitalWrite(LED, LOW);
}
delay(20);
} 58 / 73
6. Write a sketch to control the rate of blinking of an LED using
a potentiometer.
const int DIM = A0;
const int LED = 13;
int value = 0;
void setup(){
pinMode(DIM, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop(){
value = analogRead(DIM);
Serial.println(value);
digitalWrite(LED, HIGH);
delay(value);
digitalWrite(LED, LOW);
delay(value);
} 59 / 73
7. Write a sketch to gradually rotate a Servo motor in steps of 1
degree upto 180 degree position and back repeatedly.
#include <Servo.h>
int pos = 0;
Servo servoDemo;
void setup(){
servoDemo.attach(9);
}
void loop(){
for (pos = 0; pos <= 180; pos += 1) {
servoDemo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
servoDemo.write(pos);
delay(15);
}
} 60 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
61 / 73
Sensors
62 / 73
Sensor integration with Arduino
63 / 73
DHT Sensor Library Sketch
i. Arduino supports a special library for i. Write the sketch (code) in an Arduino
the DHT11 and DHT22 sensors IDE in a PC
ii. Provides function to read the tempera- ii. Connect the board to the PC
ture and humidity values from the data iii. Set the port and board type to the ap-
pin propriate values in Arduino IDE
• dht.readHumidity() iv. Verify and upload the code
• dht.readTemperature() Output
Connection i. The readings are printed at a delay of
i. Connect pin 1 of the DHT to the 3.3 2 seconds as specified by the delay()
V supply pin in the board function
ii. Data pin (pin 2) can be connected to
any digital pin, here 12 Humidity: 65.80%, Temp: 26.00 Celsius
iii. Connect pin 4 to the ground (GND) Humidity: 65.80%, Temp: 26.00 Celsius
pin of the board ....
64 / 73
#include <DHT.h> ;
DHT dht(8, DHT22);
float humidity;
float temperature;
void setup(){
Serial.begin(9600);
dht.begin();
}
void loop(){
humidity = dht.readHumidity();
temperature= dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%, Temp: ");
Serial.print(temperature);
Serial.println(" Celsius");
delay(2000);
} 65 / 73
Where are we ?
1. Machine-to-Machine Communications 4.4 Supported Datatypes
1.1 Introduction 4.5 Function Libraries
1.2 M2M 4.6 Arduino Programming
4.6.1 Operators in Arduino
2. Difference between IoT and M2M 4.6.2 Control Statement
2.1 DIfference between IoT and M2M 4.6.3 Loops
3. Interoperability in IoT 4.6.4 Arrays
3.1 Current Challenges in IoT 4.6.5 String
3.2 What is Interoperability ? 4.6.6 Math Library
3.3 Why Interoperability is Important in Context of IoT ? 4.6.7 Random Number
3.4 Different Types of Interoperability 4.6.8 Interrupts
3.4.1 User Interoperability 4.7 Example Programs
3.4.2 Device Interoperability 5. Integration of Sensors and Actuators with Arduino
4. Introduction to Arduino Programming 5.1 Sensors
4.1 Arduino Board 5.1.1 Sensor integration with Arduino
4.2 Setup 5.2 Actuators
4.3 Arduino IDE 5.2.1 Servo Motor integration with Arduino
66 / 73
Actuators
68 / 73
Servo Library on Arduino: the 5V pin of the board.
• Arduino provides different library- • Connect the signal wire to any
SERVO to operate the servo mo- digital output pin (we have used
tor pin 8).
• Create an instance of servo to use Sketch:
it in the sketch • Create an instance of Servo
Servo myservo: • The instance must be attached to
Connection: the pin before being used in the
• Connect the Ground of the servo code
to the ground of the Arduino • write() function takes the de-
board. gree value and rotates the motor
• Connect the power supply wire to accordingly
69 / 73
#include <Servo.h>
const int PIN = 12;
Servo myservo;
void setup(){
myservo.attach(PIN);
}
void loop(){
myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
} 70 / 73
Board Setup: Other functions in Servo
• Connect the board to the PC library:
• Set the port and board type • knob()
• Verify and upload the code • sweep()
Output: • write()
• The motor turns 0◦ , 90◦ and 180◦ • writeMicroseconds()
with a delay of 1 second each • read()
• attach()
• detach()
71 / 73
Text Books
[1] P. S. Misra, “Nptel: Introduction to internet of things,” 2019.
https://www.youtube.com/@introductiontointernetofth4217/featured
[Accessed: Feb 2023].
[4] OpenAI.com, “chatgpt - an openai based language models for dialogue,” 2023.
https://openai.com/blog/chatgpt/ [Accessed: Feb 2023].
72 / 73
Thank you
73 / 73