0% found this document useful (0 votes)
2 views

Unit III Iot and Arduino Programming

Uploaded by

mygameidall001
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unit III Iot and Arduino Programming

Uploaded by

mygameidall001
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

IOT AND

ARDUINO
PROGRAMMING
Introduction to the Concept of IoT
Devices
• IoT stands for Internet of Things.
• It refers to the interconnectedness of physical devices,
such as appliances and vehicles, that are embedded with
software, sensors, and connectivity which enables these
objects to connect and exchange data.
• This technology allows for the collection and sharing of
data from a vast network of devices, creating opportunities
for more efficient and automated systems.
History of IOT
• 1982 – Vending machine: The first glimpse of IoT emerged as a vending machine at
Carnegie Mellon University was connected to the internet to report its inventory and
status, paving the way for remote monitoring.

• 1990 – Toaster: Early IoT innovation saw a toaster connected to the internet, allowing
users to control it remotely, foreshadowing the convenience of smart home devices.

• 1999 – IoT Coined (Kevin Ashton): Kevin Ashton coined the term “Internet of Things” to
describe the interconnected network of devices communicating and sharing data,
laying the foundation for a new era of connectivity.

• 2000 – LG Smart Fridge: The LG Smart Fridge marked a breakthrough, enabling users to
check and manage refrigerator contents remotely, showcasing the potential of IoT in
daily life.
• 2004 – Smart Watch: The advent of smartwatches introduced IoT to the
wearable tech realm, offering fitness tracking and notifications on-the-go.

• 2007 – Smart iPhone: Apple’s iPhone became a game-changer, integrating IoT


capabilities with apps that connected users to a myriad of services and devices,
transforming smartphones into hubs.

• 2009 – Car Testing: IoT entered the automotive industry, enhancing vehicles with
sensors for real-time diagnostics, performance monitoring, and remote testing.

• 2011 – Smart TV: The introduction of Smart TVs brought IoT to the living room,
enabling internet connectivity for streaming, app usage, and interactive content.
• 2013 – Google Lens: Google Lens showcased IoT’s potential in image
recognition, allowing smartphones to provide information about objects
in the physical world.

• 2014 – Echo: Amazon’s Echo, equipped with the virtual assistant Alexa,
demonstrated the power of voice-activated IoT, making smart homes
more intuitive and responsive.

• 2015 – Tesla Autopilot: Tesla’s Autopilot system exemplified IoT in


automobiles, introducing semi-autonomous driving capabilities through
interconnected sensors and software.
Key Components of IOT

• Low Power • Connectivity


• Device or sensor • Data processing
• Control unit • Interface
• Cloud computing
Main Components Used in IoT
• Low-power embedded systems: Less battery
consumption, high performance are the inverse factors
that play a significant role during the design of electronic
systems.

• Sensors: Sensors are the major part of any IoT


application. It is a physical device that measures and
detects certain physical quantities and converts it into
signal which can be provided as an input to processing or
control unit for analysis purpose.
• Control Units: It is a unit of small computer on a single integrated
circuit containing microprocessor or processing core, memory and
programmable input/output devices/peripherals. It is responsible for
major processing work of IoT devices and all logical operations are
carried out here.

• Cloud computing: Data collected through IoT devices is massive, and


this data has to be stored on a reliable storage server. This is where
cloud computing comes into play. The data is processed and learned,
giving more room for us to discover where things like electrical
faults/errors are within the system.
• Availability of big data: We know that IoT relies heavily on
sensors, especially in real-time. As these electronic devices spread
throughout every field, their usage is going to trigger a massive flux
of big data.

• Networking connection: In order to communicate, internet


connectivity is a must, where each physical object is represented by
an IP address. However, there are only a limited number of
addresses available according to the IP naming. Due to the growing
number of devices, this naming system will not be feasible anymore.
Working with IoT Devices
• Collect and Transmit Data : For this purpose sensors are
widely used they are used as per requirements in different
application areas.

• Actuate device based on triggers produced by


sensors or processing devices: If certain conditions are
satisfied or according to user’s requirements if certain
trigger is activated then which action to perform that is
shown by Actuator devices.
Ways of Building IOT
There are two ways of building IoT:
• Form a separate internet work including only physical
objects.

• Make the Internet ever more expansive, but this requires


hard-core technologies such as rigorous cloud computing
and rapid big data storage (expensive).
• Receive Information: From network devices, users or devices
can take certain information also for their analysis and
processing purposes.

• Communication Assistance: Communication assistance is the


phenomenon of communication between 2 networks or
communication between 2 or more IoT devices of same or
different networks. This can be achieved by different
communication protocols like: MQTT, Constrained Application
Protocol, ZigBee, FTP, HTTP etc.
Application Domains
IoT is currently found in four different popular domains:
1) Manufacturing/Industrial business - 40.2%
2) Healthcare - 30.3%
3) Security - 7.7%
4) Retail - 8.3%
IoT vs Computers
Internet of Things (IoT):
• The Internet of Things (IoT) is the network of physical objects/devices
like vehicles, buildings, cars, and other items embedded with
electronics, software, sensors, and network connectivity that enables
these objects to collect and exchange data.
• IoT devices have made human life easier.
• The IoT devices like smart homes, smart cars have made the life of
humans very comfortable. IoT devices are now being a part of our day-
to-day life.
Computers:
• A computer is a hardware device embedded with software in it.
• The computer does most of the work like calculations, gaming,
web browsers, word processors, e-mails, etc.
• The main function of a computer is to compute the functions,
to run the programs.
• It takes input from the computer and then computes/processes
it and generates the output.
IOT Devices Computers
IoT devices are special-purpose Computers are general-purpose
devices. devices.

IoT devices can do only a particular


Computers can do so many tasks.
task for which it is designed.

The hardware and software built-in in


The hardware and software built-in in
the computers are streamlined to do
the IoT devices are streamlined for
many tasks(such as calculation,
that particular task.
gaming, music player, etc. )

IoT devices can be cheaper and faster


A computer can be expensive and
at a particular task than computers, as
slower at a particular task than an IoT
IoT devices are made to do that
device.
particular task.

Examples: Music Player- iPod, Alexa, Examples: Desktop computers,


smart cars, etc. Laptops, etc.
IoT Configuration
• Configuring an IoT system involves several critical steps
and considerations to ensure that devices communicate
effectively, data is managed properly, and security is
maintained.
1. Identify Use Cases and
Requirements
• Determine the specific goals of your IoT application (e.g.,
smart home, industrial monitoring, healthcare).
• Identify the types of devices needed (sensors, actuators,
gateways).
2. Choose Communication
Protocols
Different protocols are suitable for various applications:
• MQTT: Lightweight messaging, ideal for low-bandwidth
scenarios.
• CoAP: Designed for constrained devices, supports
RESTful interactions.
• HTTP: Standard for web services; best for high-
bandwidth applications.
• XMPP: Good for real-time messaging and presence
information.
3. Select Hardware Components
• Choose sensors (e.g., temperature, humidity), actuators
(e.g., motors, lights), and gateways (to connect devices to
the internet).
• Ensure compatibility with chosen protocols.
4. Set Up the Network
• Establish a local area network (LAN) using Wi-Fi,
Ethernet, or cellular connections.
• Configure routers and gateways to allow device
communication.
5. Device Configuration
• MQTT: Install an MQTT broker (e.g., Mosquitto) and
configure devices to publish/subscribe to topics.
• CoAP: Implement a CoAP library (e.g., Californium) on
devices, setting up endpoints for resources.
• HTTP: Set up web servers (e.g., Flask, Node.js) to handle
requests and responses from devices.
• XMPP: Use an XMPP server (e.g., ejabberd) to manage
client connections and messages
6. Data Management
• Decide where data will be stored: on-device, in the cloud,
or on-premises.
• Implement data processing pipelines to handle incoming
data for analysis and visualization.
7. Security Measures
• Ensure secure communication by implementing
encryption (e.g., TLS for MQTT/HTTP).
• Use authentication mechanisms for devices to connect to
the network securely.
• Regularly update device firmware to protect against
vulnerabilities.
8. User Interface Development
• Create dashboards or applications for users to interact
with the IoT system.
• Use web technologies (HTML, CSS, JavaScript) or mobile
app frameworks (React Native, Flutter).
9. Testing and Validation
• Conduct comprehensive testing to ensure devices
communicate correctly and meet performance
requirements.
• Validate data integrity and security measures.
10. Deployment and Monitoring
• Deploy devices in the intended environment.
• Set up monitoring tools to track device performance and
data flow (e.g., Grafana, Kibana).
Basic Components of IoT
1. Smart devices and sensors –
Device connectivity
• Devices and sensors are the components of the device
connectivity layer. These smart sensors are continuously
collecting data from the environment and transmit the
information to the next layer.
• The latest techniques in semiconductor technology are
capable of producing micro smart sensors for various
applications.
Common sensors are:
• Temperature sensors and thermostats
• Pressure sensors
• Humidity / Moisture level
• Light intensity detectors
• Moisture sensors
• Proximity detection
• RFID tags
2. Gateway
• IoT Gateway manages the bidirectional data traffic between different
networks and protocols.
• Another function of the gateway is to translate different network
protocols and make sure interoperability of the connected devices and
sensors.
• Gateways can be configured to perform pre-processing of the collected
data from thousands of sensors locally before transmitting it to the next
stage.
• In some scenarios, it would be necessary due to the compatibility of the
TCP/IP protocol.
3. Cloud
• The Internet of Things creates massive data from devices, applications, and users,
which has to be managed in an efficient way.
• IoT cloud offers tools to collect, process, manage and store huge amounts of data
in real time.
• Industries and services can easily access these data remotely and make critical
decisions when necessary.
• Basically, the IoT cloud is a sophisticated, high-performance network of servers
optimized to perform high-speed data processing of billions of devices, traffic
management, and deliver accurate analytics.
• Distributed database management systems are one of the most important
components of the IoT cloud.
4. Analytics
• Analytics is the process of converting analog data from
billions of smart devices and sensors into useful insights
which can be interpreted and used for detailed analysis.
Smart analytics solutions are inevitable for IoT systems
for the management and improvement of the entire
system.
• One of the major advantages of an efficient IoT system is
real-time smart analytics which helps engineers to find out
irregularities in the collected data and act fast to prevent
an undesired scenario. Service providers can prepare for
further steps if the information is collected accurately at
5. User interface

• User interfaces are the visible, tangible


part of the IoT system which users can
access.
• It is one of the significant components of
Internet of things where user control
the system and collect information.
• Designers will have to make sure of a
well-designed user interface for
minimum effort for users and encourage
more interactions.
Introduction to Arduino
• Arduino is a versatile, open-source hardware and software
platform used for building interactive objects and
projects, including those in the Internet of Things (IoT).
• It's a small, single-board computer with a microcontroller,
allowing you to read inputs (like sensor data) and control
outputs (like LEDs or motors).
• Arduino boards are easy to program using the Arduino
Software (IDE), which provides a user-friendly
environment for writing and uploading code.
Types of Arduino Boards
Click icon to add picture

Arduino UNO
• Arduino UNO is based on an ATmega328P
microcontroller. It is easy to use compared
to other boards, such as the Arduino Mega
board, etc.
• The Arduino UNO includes 6 analog pin
inputs, 14 digital pins, a USB connector, a
power jack, and an ICSP (In-Circuit Serial
Programming) header.
• It is the most used and of standard form
from the list of all available Arduino Boards.
It is also recommended for beginners as it is
easy to use.
Click icon to add picture

Arduino Nano

• The Arduino Nano is a small Arduino board based on


ATmega328P or ATmega628 Microcontroller. The
connectivity is the same as the Arduino UNO board.
• The Nano board is defined as a sustainable, small,
consistent, and flexible microcontroller board. It is small in
size compared to the UNO board. The devices required to
start our projects using the Arduino Nano board are Arduino
IDE and mini USB.
• The Arduino Nano includes an I/O pin set of 14 digital pins
and 8 analog pins. It also includes 6 Power pins and 2 Reset
pins.
Click icon to add picture

Arduino Mega
• The Arduino Mega is based on ATmega2560
Microcontroller. The ATmega2560 is an 8-bit
microcontroller. We need a simple USB cable to
connect to the computer and the AC to DC adapter
or battery to get started with it. It has the advantage
of working with more memory space.
• The Arduino Mega includes 54 I/O digital pins and
16 Analog Input/Output (I/O), ICSP header, a reset
button, 4 UART (Universal Asynchronous
Reciever/Transmitter) ports, USB connection, and a
power jack.
Click icon to add picture

Arduino Micro

• The Arduino Micro is based on the ATmega32U4


Microcontroller. It consists of 20 sets of pins. The 7
pins from the set are PWM (Pulse Width Modulation)
pins, while 12 pins are analog input pins. The other
components on board are reset button, 16MHz crystal
oscillator, ICSP header, and a micro USB connection.
• The USB is inbuilt in the Arduino Micro board.
Click icon to add picture

Arduino Leonardo

The basic specification of the Arduino


Leonardo is the same as the Arduino
Micro. It is also based on
ATmega32U4 Microcontroller. The
components present on the board are
20 analog and digital pins, reset
button, 16MHz crystal oscillator, ICSP
header, and a micro USB connection.
Click icon to add picture

Arduino Due

The Arduino Due is based on the 32-


bit ARM core. It is the first Arduino
board that has developed based on the
ARM Microcontroller. It consists of 54
Digital Input/Output pins and 12
Analog pins. The Microcontroller
present on the board is the Atmel
SAM3X8E ARM Cortex-M3 CPU.
Arduino Lilypad Click icon to add picture

• The Arduino LilyPad was initially


created for wearable projects and e-
textiles. It is based on the ATmega168
Microcontroller. The functionality of
Lilypad is the same as other Arduino
Boards. It is a round, light-weight board
with a minimal number of components
to keep the size of board small.
• The Arduino Lilypad board was
designed by Sparkfun and Leah. It was
developed by Leah Buechley. It has 9
Arduino Tool Chain
• A tool chain is simply a set of software tools that work
together to complete a task. for example, if we were going
to hang a picture, the tool chain might include a hammer,
maybe a tape measure and some nails.
• Sketch code press upload button. The Arduino toolchain is
ran to perform the uploading of the code.
• Arduino sketches held the file in .ino extension in a folder
with same name.
• Arduino IED starts to perform the following tasks
• Arduino IDE preprocessor assembles the files on the
sketch. 1 file is found in the folder
As there are many boards with different pins layout, there is a folder
/hardware/arduino/variant folder that kept all other type of Arduino pin setup.
• Combining all the files, GCC compiler (which is open source C++ compiler)
bundled part of Arduino distribution.
• Preprocessor interprets all the #if and #define commands and determines
what actually goes into the build.
• Next, the code is compiled and linked into a single executable file for type of
proessor used by board.
• After compiler finished, another piece open source called avrdude actually
sends the executable code saved as hexadecimal binary to the board over USB
serial interface.
• There is a program called bootloader on Arduino board
runs every briefly when Arduino is reset. • When serial
communication starts, the hardware serial link forces a
reset to give the bootloader chance to check for any
incoming sketches.
• If sketch exist, Arduino programs will unpack the
hexadecimal into binary. • It stores the sketch in the flash
memory.
Arduino Programming Structure
• A sketch is the name that Arduino uses for a program. It's
the unit of code that is uploaded to and run on an Arduino
board.
• Arduino programming follows a specific structure that is
easy to understand and use, especially for beginners.
• It consists of two main parts: setup() and loop(), which
define the flow of execution.
Arduino Program Structure
• An Arduino sketch (program) is written in C/C++ and
includes two primary functions:
• a. setup():
The setup() function is used for
initialization.
This function runs once when the
Arduino is powered on or reset.
setup() function It's where you set up initial
configurations like pin modes, serial
void setup() {
communication, and other setup tasks.
pinMode(13, OUTPUT); // Set digital pin 13 as an
output (for an LED)
Purpose: Initialize variables, pins,
Serial.begin(9600); // Start serial communication
sensors, communication protocols, etc.
at 9600 baud rate

} Execution: Runs once, right after the


board is powered up or reset.
Example: Setting up the pin mode for
an LED.
• The loop() function is where the
main code runs continuously.
After the setup() function is
executed, the loop() function
keeps running over and over,
loop() repeating the program's tasks,
void loop() { checking conditions, and
digitalWrite(13, HIGH); // Turn the LED updating states.
on
delay(1000); // Wait for 1 second • Purpose: Perform the main
digitalWrite(13, LOW); // Turn the LED
off
tasks or logic repeatedly.
delay(1000); // Wait for 1 second
• Execution: Runs repeatedly
}
after setup().
• Example: Blink an LED on pin
13 repeatedly.
Additional Elements in Arduino
Programming
a. Variables
• Variables are used to store data values that can be used
and manipulated throughout the program.
Ex:
int ledPin = 13; // Variable to hold the pin number
b. Functions

• You can create custom functions to organize your code. These


functions allow you to encapsulate logic that can be reused
throughout your program.
Ex:
void blinkLED(int pin) {
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
delay(1000);
}
• In the loop() function, you could call this blinkLED()
function like this:

Ex:
void loop() {
blinkLED(13); // Call the custom function
}
Conditional Statements
• Conditional statements allow you to make decisions based on
certain conditions (e.g., if, else, switch).
Ex:
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on if button is pressed
} else {
digitalWrite(ledPin, LOW); // Turn LED off if button is not pressed
}
Loops
• Besides the loop() function, you can use for, while, and do-while loops for
repetitive tasks within the program.
Example of a for loop:
for (int i = 0; i < 5; i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
Libraries
• Arduino includes a lot of built-in libraries that provide
functionality for specific tasks, such as controlling motors,
sensors, displays, etc.
• Libraries are included at the top of the sketch using
#include.For example, to use an LCD display:
#include <LiquidCrystal.h> // Include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the LCD with pin numbers
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.print("Hello, World!");
}
void loop() {
// No need to continuously update the display in this example
}
Comments
• In Arduino programming (and C/C++ in general), you can
add comments to your code to make it more readable and
easier to understand.
There are two types of comments:
• Single-line comments: Start with //. Everything after // on
that line is a comment.
• Multi-line comments: Start with /* and end with */.
Everything in between is a comment.
Commonly Used Functions
• pinMode(pin, mode): Configures a specified pin to either INPUT or
OUTPUT.
• digitalWrite(pin, value): Writes a HIGH or LOW value to a digital pin.
• digitalRead(pin): Reads the value from a digital pin (HIGH or LOW).
• analogWrite(pin, value): Writes an analog value (PWM) to a pin.
• analogRead(pin): Reads the analog value from a specified pin (0-1023).
• delay(ms): Pauses the program for a specified number of milliseconds.
IoT Protocols
• IoT protocols are the sets of rules that govern how devices
and systems in an IoT network communicate and
exchange data. They are designed to facilitate efficient
and reliable communication, especially in environments
with limited resources, like those often found in IoT
devices. Some common IoT protocols include MQTT, CoAP,
LoRaWAN, Zigbee, and Bluetooth.
MQTT(Message Queuing Telemetry
Transport)
• MQTT is a lightweight messaging protocol designed for
devices to communicate over the internet.
• Publisher-Subscriber Model: Devices (called publishers) send messages
about specific topics. Other devices (subscribers) receive those messages if
they are interested in those topics.
• Lightweight and Efficient: It’s designed for low-bandwidth and high-latency
networks, making it great for IoT devices that may not have a lot of power or
bandwidth.
• Broker: All messages go through a central server called a broker. The broker
manages the messages and ensures they are delivered to the right
subscribers.
• Use Cases: MQTT is commonly used in applications like smart home devices,
remote sensors, and any scenario where devices need to send data efficiently.
Coap: Constrained Application
Protocol
• CoAP, or Constrained Application Protocol, is a specialized
protocol designed for use in simple, resource-constrained
devices in IoT applications.
•Lightweight:
Overview: CoAP is designed for low-power devices and
networks with limited bandwidth. It uses less overhead
than more traditional protocols like HTTP.
•Request/Response Model: Similar to HTTP, CoAP follows a
request/response model. Devices (clients) send requests to
servers, which then respond with data.
• RESTful Architecture: CoAP supports RESTful principles, meaning it uses
standard methods like GET, POST, PUT, and DELETE to interact with resources
(like sensors or actuators).
• UDP-Based: CoAP typically runs over UDP (User Datagram Protocol), which is
simpler and faster than TCP, making it suitable for scenarios where reliability
can be traded off for speed.
• Multicast Support: CoAP can send messages to multiple devices
simultaneously (multicast), which is useful for managing groups of devices.
• Use Cases: It’s commonly used in smart home applications, industrial
automation, and sensor networks where devices need to communicate
efficiently.
HTTP(Hypertext Transfer
Protocol)
• HTTP, or Hypertext Transfer Protocol, is the foundational
protocol used for transmitting data over the web.
• Client-Server Model: HTTP operates on a client-server
model, where a client (like a web browser or an IoT device)
sends requests to a server, which processes the request
and sends back a response.
• Request/Response Structure: Each interaction follows a
request/response format. The client sends a request (like
asking for a web page or data), and the server responds
with the requested information.
• Stateless Protocol: HTTP is stateless, meaning each request
from a client to a server is treated as a new, independent
transaction. The server does not keep track of previous
interactions.
• Standard Methods: Common HTTP methods include:
• GET: Retrieve data from the server.
• POST: Send data to the server (like submitting a form).
• PUT: Update existing data on the server.
• DELETE: Remove data from the server.
• Flexible Data Formats: HTTP can transfer a variety of data
formats, including HTML, JSON, XML, images, and videos,
making it versatile for different applications.

HTTP is a versatile and widely used protocol that allows


devices and applications to communicate over the web by
sending requests and receiving responses.
XMPP(Extensible Messaging and
Presence Protocol)
• XMPP, or Extensible Messaging and Presence Protocol, is
a communication protocol primarily used for instant
messaging, but it’s also applicable in various IoT
scenarios.
• Real-Time Communication: XMPP enables real-time communication
between devices and users. It supports instant messaging, presence
updates (showing whether someone is online), and group chat.
• Client-Server Model: Similar to other protocols, XMPP operates on a
client-server model. Clients connect to an XMPP server, which routes
messages between users or devices.
• Extensible: As its name suggests, XMPP is highly extensible.
Developers can add custom features through "XEPs" (XMPP Extension
Protocols), allowing for specialized functionality beyond basic
messaging.
• Presence Information: XMPP allows users to share their
availability status (online, away, do not disturb), which is
useful in collaborative environments or for managing
device states.
• Suitable for IoT: In IoT, XMPP can be used to enable
real-time messaging between devices, allowing them to
send alerts or notifications instantly. It’s also useful in
applications that require multi-user interactions.
• Security: XMPP can be secured with encryption (like
TLS), ensuring that messages are transmitted securely
between clients and servers.
• XMPP is a flexible protocol that facilitates real-time
communication and presence information, making it
suitable for both messaging and various IoT applications.

You might also like