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

Embed system and iot

This document provides an overview of IoT (Internet of Things) devices, their features, architecture, and applications, along with a detailed introduction to Arduino programming. It explains the components of an IoT system, including sensors, microcontrollers, connectivity modules, and security measures, while also highlighting the differences between IoT devices and traditional computers. Additionally, it covers the configuration process for IoT devices and the basics of Arduino programming, including pin functions and example applications.

Uploaded by

learner22032000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Embed system and iot

This document provides an overview of IoT (Internet of Things) devices, their features, architecture, and applications, along with a detailed introduction to Arduino programming. It explains the components of an IoT system, including sensors, microcontrollers, connectivity modules, and security measures, while also highlighting the differences between IoT devices and traditional computers. Additionally, it covers the configuration process for IoT devices and the basics of Arduino programming, including pin functions and example applications.

Uploaded by

learner22032000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

UNIT-III IOT AND ARDUINO PROGRAMMING

Introduction to the Concept of IoT Devices

What is IoT?

IoT (Internet of Things) refers to a network of interconnected physical devices that can
collect, exchange, and act on data using embedded sensors, software, and other
technologies—all connected via the Internet or local networks.

These devices range from everyday household items like smart lights and thermostats to
complex industrial tools.

Key Features of IoT Devices

1. Connectivity: Devices are connected to the internet or local networks to share data.
2. Sensing: They gather data from their environment using sensors (e.g., temperature,
motion, humidity).
3. Data Processing: IoT devices may process collected data locally or send it to cloud
servers.
4. Actuation: They can perform actions like turning on a fan or locking a door
automatically.
5. Automation: IoT enables automated decision-making and responses based on data
patterns.

Common Examples of IoT Devices

Device Function
Smart Thermostat Adjusts room temperature automatically
Fitness Tracker Monitors heart rate, steps, sleep
Smart Refrigerator Tracks food items and their expiration dates
Security Cameras Detects motion and sends alerts
Industrial Sensors Monitor machinery status in real-time
Smart Irrigation System Waters crops based on soil moisture levels
IoT Architecture (Simplified)

1. Sensing Layer – Sensors/actuators to collect real-world data.


2. Network Layer – Transfers data over Wi-Fi, Bluetooth, LTE, etc.
3. Processing Layer – Edge or cloud computing to process and analyze data.
4. Application Layer – End-user services (e.g., mobile apps, dashboards).

Technologies Behind IoT

• Sensors & Actuators (e.g., DHT11, PIR, MQ-135)


• Microcontrollers (e.g., Arduino, ESP32, Raspberry Pi)
• Communication Protocols (e.g., MQTT, HTTP, Zigbee, LoRa)
• Cloud Platforms (e.g., AWS IoT, Google Cloud IoT, Blynk)

Challenges in IoT

• Security & Privacy: Risk of hacking and data leaks.


• Interoperability: Different devices using different standards.
• Scalability: Managing large numbers of devices.
• Power Consumption: Many devices are battery-operated.

Applications of IoT

• Smart Homes (e.g., lighting, voice assistants)


• Smart Cities (e.g., waste management, traffic control)
• Healthcare (e.g., remote patient monitoring)
• Agriculture (e.g., soil sensors, weather stations)
• Industry 4.0 (e.g., predictive maintenance)

Building Blocks of an IoT System


An IoT (Internet of Things) system connects physical devices to the internet, allowing them
to collect, send, and act on data. It consists of multiple layers working together to enable
intelligent automation and remote monitoring.

1. Devices/Sensors (Perception Layer)

• Function: Sense or interact with the environment.


• Examples:
o Temperature sensor (DHT11)
o Motion detector (PIR)
o Camera, GPS, RFID tags
• Types:
o Sensors: Measure data (e.g., temperature, humidity).
o Actuators: Perform actions (e.g., motors, relays, LEDs).

2. Connectivity (Network Layer)

• Function: Transmit data from devices to the cloud/server.


• Common Technologies:
o Wi-Fi
o Bluetooth/BLE
o Zigbee/Z-Wave
o Cellular (2G/3G/4G/5G)
o LoRaWAN, NB-IoT
• Protocols:
o MQTT, HTTP, CoAP

3. Cloud/Edge Computing (Data Processing Layer)

• Function: Store, process, and analyze data.


• Cloud Platforms:
o AWS IoT, Google Cloud IoT, Microsoft Azure IoT
• Edge Computing:
o Local processing before sending to cloud
o Reduces latency and bandwidth

4. Data Management & Analytics (Application Layer)

• Function: Interpret data and extract insights.


• Tools:
o Big data platforms
o Machine learning models
o Real-time dashboards (e.g., Grafana, Power BI)

5. User Interface / Application

• Function: Allow users to monitor or control the system.


• Interfaces:
o Mobile apps
o Web dashboards
o Voice interfaces (e.g., Alexa)
• Use Cases:
o Turning on smart lights
o Viewing water usage statistics
o Receiving alerts

6. Security Layer

• Function: Ensure data integrity, privacy, and secure communication.


• Key Aspects:
o Encryption (SSL/TLS)
o Authentication and Authorization
o Secure firmware updates
o Firewalls and threat detection

Complete Flow of an IoT System


[Sensor/Device] → [Gateway/Network] → [Cloud/Edge] → [Data Processing] →
[User Interface]
↑ ↓
[Security Mechanisms & Protocols]

Summary Table

Building Block Description


Sensors & Actuators Interact with the physical world
Connectivity Connect devices to the network
Cloud/Edge Store and compute data
Data Analytics Analyze and gain insights from data
User Interface Enable human interaction
Security Protect the system from cyber threats
IoT Device vs Computer
Let’s break down the key differences between an IoT device and a computer in terms of
purpose, hardware, power, and more.

Feature IoT Device Computer (PC/Laptop)


Specific task (e.g., sense temperature, General-purpose computing
Purpose
track location) (browsing, coding, gaming)
Microcontroller/microprocessor, limited Powerful CPU, large
Hardware
RAM/storage RAM/storage
Operating Often runs embedded firmware or Full-featured OS (Windows,
System lightweight OS Linux, macOS)
Uses wireless protocols (Wi-Fi,
Connectivity Ethernet, Wi-Fi, Bluetooth
Bluetooth, Zigbee)
Power High power; needs continuous
Low power; can run on batteries
Consumption power supply
Cost Inexpensive ($2–$50) Expensive ($200+)
Size Compact and small (often fits in a hand) Larger, desktop or portable
User Interface Usually no display or keyboard Has monitor, keyboard, mouse
Processes and stores data
Data Handling Sends data to the cloud or another device
locally
Example Arduino, Raspberry Pi, Smart bulbs,
Desktop PCs, Laptops, Servers
Devices Fitbits

Summary

• IoT Device: Designed for one or a few specific tasks, small, efficient, and connected.
• Computer: General-purpose, powerful, and used for a wide range of computing
activities.

IoT Configuration: Overview and Steps

IoT Configuration refers to the process of setting up an IoT device so it can collect data,
connect to a network, communicate with other systems (e.g., cloud servers), and perform
desired functions. Configuration can be manual, automated, or remote (OTA – Over-the-Air).

Main Components Involved in IoT Configuration


1. Device Configuration
2. Network Configuration
3. Security Configuration
4. Cloud/Platform Integration
5. Application Setup

1. Device Configuration

• Load firmware or embedded software onto the microcontroller.


• Define device parameters like:
o Device ID / name
o Sensor types and pin mappings
o Operation modes (active/sleep)
• Example (Arduino):
• const char* deviceID = "SensorNode01";

2. Network Configuration

• Establish connection to the internet or local network using:


o Wi-Fi
o Ethernet
o Cellular (GSM/4G/5G)
• Configure:
o SSID and password
o Static or dynamic IP
o MQTT broker or HTTP endpoint
• Example (ESP8266/ESP32 Wi-Fi):
• WiFi.begin("YourSSID", "YourPassword");

3. Security Configuration

• Set up:
o Device authentication
o Data encryption (e.g., TLS/SSL)
o API keys or certificates
• Secure communication protocols:
o HTTPS
o MQTT with TLS
o JWT (JSON Web Tokens) for cloud access

4. Cloud or Server Integration

• Configure connection with cloud platforms:


o AWS IoT Core, Google IoT Core, Blynk, ThingSpeak
• Send/receive data using:
o MQTT topics
o REST API endpoints
• Provide:
o Device credentials (access token, secret key)
o Topic names or database paths

5. Application/User Interface Configuration

• Connect devices to dashboards or apps for visualization and control.


• Configure user preferences:
o Alert settings (SMS, email, push notifications)
o Graph display intervals
o Access control and user roles

Example: IoT Configuration Workflow for a Smart Thermometer

Step Task Tools Used


1 Flash firmware to device Arduino IDE
2 Connect to Wi-Fi ESP8266 Wi-Fi library
3 Send data to cloud MQTT protocol with Adafruit IO
4 Secure data TLS encryption
5 Monitor via mobile app Blynk or custom dashboard

Advanced: Remote Configuration

• Over-the-Air (OTA) updates


• Remote device provisioning
• Dynamic reconfiguration via cloud command

Basic Components of an IoT System


An IoT system is made up of several key components that work together to collect, transmit,
process, and act on data from the physical world.

1. Sensors and Actuators

• Sensors: Detect changes in the environment (e.g., temperature, motion, light,


humidity).
• Actuators: Perform actions based on commands (e.g., turning on a fan, opening a
valve).

Examples:

• DHT11 (temperature/humidity)
• PIR (motion sensor)
• Relay module (actuator)

2. Microcontroller/Microprocessor

• The brain of the IoT device.


• Processes data from sensors and sends/receives information.

Examples:

• Arduino (Uno, Nano)


• ESP32/ESP8266 (with built-in Wi-Fi)
• Raspberry Pi (mini computer)

3. Connectivity Module

• Enables communication between the device and the internet/cloud.

Common Technologies:

• Wi-Fi (ESP8266)
• Bluetooth (HC-05)
• Zigbee, LoRa, GSM (SIM800L)

4. Power Supply

• Provides the energy to run the IoT device.

Options:

• USB power
• Batteries (AA, Li-ion)
• Solar panels
5. Cloud/Server

• Stores and analyzes the data.


• Manages device communication and user interfaces.

Examples:

• Google Cloud IoT, AWS IoT, Microsoft Azure


• ThingSpeak, Blynk, Firebase

6. User Interface (UI)

• Allows users to interact with the IoT system.


• Can be:
o Web dashboard
o Mobile app
o Voice interface (e.g., Alexa)

7. Security Layer

• Ensures data privacy and integrity.


• Includes:
o Data encryption (SSL/TLS)
o Device authentication
o Secure firmware updates

Summary Table

Component Role
Sensor Collects real-world data
Actuator Acts on instructions (e.g., motor)
Microcontroller Controls and processes data
Connectivity Connects to the internet/network
Power Source Powers the IoT device
Cloud/Server Stores and analyzes data
User Interface Allows user to view/control device
Security Protects data and device integrity

Introduction to Arduino
Arduino is an open-source electronics platform based on easy-to-use hardware and
software. It allows users — from beginners to professionals — to create devices that can
sense, control, and interact with the physical world.

What is Arduino?

At its core, Arduino is:

• A microcontroller board (hardware)


• With a development environment called the Arduino IDE (software)

It bridges the gap between electronics and programming by letting users write code to control
sensors, lights, motors, and other components.

Key Features of Arduino:

• Microcontroller-based (e.g., ATmega328 on Arduino Uno)


• Open-source (hardware and software)
• Simple USB interface for programming
• 14 digital I/O pins and 6 analog input pins (Uno)
• Operates at 5V with a 16 MHz clock speed

Common Arduino Boards:

Board Microcontroller Use Case


Arduino Uno ATmega328 Most popular, beginner-friendly
Arduino Nano ATmega328 Compact projects
Arduino Mega ATmega2560 Projects needing more I/O pins
Arduino Leonardo ATmega32u4 Acts as a USB device like keyboard/mouse

Arduino IDE (Integrated Development Environment)

• Free software to write and upload code.


• Language is based on C/C++.
• Comes with libraries and examples.
• Upload code via USB.

Basic Arduino Programming Structure:


void setup() {
// runs once when the board is powered on or reset
}

void loop() {
// runs continuously after setup
}

Simple Example: Blink LED


void setup() {
pinMode(13, OUTPUT); // Set pin 13 as output
}

void loop() {
digitalWrite(13, HIGH); // Turn on LED
delay(1000); // Wait 1 second
digitalWrite(13, LOW); // Turn off LED
delay(1000); // Wait 1 second
}

Applications of Arduino:

• Home automation
• Smart agriculture
• Robotics
• IoT systems
• Wearable devices

Why Learn Arduino?

• Beginner-friendly
• Large community support
• Endless project possibilities
• Helps understand embedded systems and electronics

Pins in Arduino
In Arduino (especially the popular Arduino Uno), pins are the main connection points to the
outside world — used to read data from sensors, control actuators, or communicate with
other devices.

1. Digital Pins (0–13)


• Used for digital input or output (only HIGH/LOW).
• Example uses:
o Read a button press
o Turn on/off an LED or buzzer

Syntax:

pinMode(13, OUTPUT); // Set pin 13 as output


digitalWrite(13, HIGH); // Set pin 13 to HIGH (5V)
int val = digitalRead(2); // Read input from pin 2

2. Analog Input Pins (A0–A5)

• Used for analog input (values from 0 to 1023).


• Reads voltage levels (0 to 5V on Uno).
• Great for sensors like temperature, light, etc.

Syntax:

int sensorValue = analogRead(A0); // Read analog value from pin A0

3. PWM (Pulse Width Modulation) Pins (~3, ~5, ~6, ~9, ~10, ~11)

• Digital pins with PWM output (simulate analog output).


• Used to dim LEDs, control motor speed, etc.

Syntax:

analogWrite(9, 128); // Write 50% duty cycle PWM to pin 9

4. Power Pins

Pin Function
5V Provides 5V output to external parts
3.3V Provides 3.3V output
GND Ground
VIN Voltage input when using external power (7–12V)

5. Special Function Pins


Pin Function
A4 (SDA) I2C Data line for communication with I2C devices
A5 (SCL) I2C Clock line
0 (RX) Serial Receive (used for Serial Monitor)
1 (TX) Serial Transmit
Reset Resets the Arduino

Pin Layout of Arduino Uno (Text Summary)


Digital Pins: 0–13
PWM Pins: ~3, ~5, ~6, ~9, ~10, ~11
Analog Pins: A0–A5
Power Pins: 5V, 3.3V, GND, VIN
Special: A4/A5 for I2C, 0/1 for Serial

Summary Table

Pin Type Range Purpose


Digital I/O D0–D13 Read/write HIGH/LOW
PWM Output ~3, 5, 6, 9, 10, 11 Simulate analog output
Analog Input A0–A5 Read varying voltages (0–5V)
Power 5V, 3.3V, GND, VIN Power input/output
Communication RX/TX, SDA/SCL Serial and I2C communication

Types of Arduino Boards


Arduino offers a range of boards tailored for different applications — from simple LED
blinking to advanced IoT projects and robotics. Below is a detailed list of commonly used
Arduino boards:

1. Arduino Uno

• Most popular and beginner-friendly.


• Microcontroller: ATmega328P
• 14 Digital I/O (6 PWM), 6 Analog Inputs
• USB Type B connector
• Clock speed: 16 MHz
• Best for: Beginners, basic electronics projects

2. Arduino Nano
• Miniature version of Uno
• Microcontroller: ATmega328P
• 22 I/O pins (14 digital, 8 analog)
• Micro USB or Mini USB
• Compact size, fits on breadboard
• Best for: Space-constrained projects

3. Arduino Mega 2560

• Designed for complex projects needing many I/O pins


• Microcontroller: ATmega2560
• 54 Digital I/O (15 PWM), 16 Analog Inputs
• 4 Serial ports
• Best for: Robotics, automation, and big data projects

4. Arduino Leonardo

• Microcontroller: ATmega32u4
• 20 Digital I/O (7 PWM), 12 Analog Inputs
• Can act as a keyboard or mouse via USB
• Best for: Human-Computer Interface (HID) projects

5. Arduino Nano 33 IoT

• Built-in Wi-Fi and Bluetooth


• Microcontroller: SAMD21 Cortex-M0+
• Great for IoT applications
• Best for: Smart home, wearable IoT, wireless projects

6. Arduino MKR Series

Designed specifically for IoT and industrial applications.

Model Feature
MKR1000 Wi-Fi
MKR GSM 1400 GSM/3G
MKR WAN 1300 LoRa communication
MKR NB 1500 Narrowband IoT (NB-IoT)

• Compact and low power


• Li-Po battery charging support

7. Arduino Due

• Microcontroller: 32-bit ARM Cortex-M3 (SAM3X8E)


• 54 digital I/O (12 PWM), 12 analog inputs
• Faster (84 MHz), more memory
• Operates at 3.3V
• Best for: High-performance applications

8. Arduino Pro Mini

• Lightweight, low-power
• No USB port (requires FTDI programmer)
• Best for: Embedded systems, battery-powered devices

Comparison Table

Analog
Board MCU Digital I/O Comm Specialty
In
14 (6
Uno ATmega328P 6 USB General-purpose
PWM)
Compact, breadboard-
Nano ATmega328P 22 8 USB
friendly
54 (15
Mega 2560 ATmega2560 16 USB Large projects, robotics
PWM)
20 (7 Acts as HID
Leonardo ATmega32u4 12 USB
PWM) (keyboard/mouse)
Nano 33 SAMD21 + Wi-Fi,
14 8 IoT applications
IoT NINA BLE
MKR1000 SAMD21 8 7 Wi-Fi IoT with Wi-Fi
SAM3X8E (32- High performance (3.3V
Due 54 12 USB
bit) logic)
Pro Mini ATmega328P 14 8 Serial Low power, small size

Arduino Toolchain: What It Is and How It Works


The Arduino toolchain is the set of software tools and processes that take your Arduino code
(called a sketch) and turn it into a program that runs on the Arduino board’s microcontroller.
Components of the Arduino Toolchain

1. Arduino IDE (Integrated Development Environment)


o Where you write, edit, compile, and upload your code.
o Provides a user-friendly interface with built-in examples and libraries.
2. Preprocessor
o Handles directives like #include to bring in libraries.
o Converts Arduino sketch (.ino) files to standard C++ code.
3. Compiler
o AVR-GCC (for most Arduino boards like Uno) compiles the C/C++ code into
machine code (binary).
4. Linker
o Combines compiled code and libraries into a single executable file ( .hex).
5. Uploader (Flasher)
o Transfers the binary code to the Arduino board via USB.
o Uses AVRDUDE tool for programming AVR-based boards.
6. Bootloader
o A small program pre-installed on Arduino boards.
o Receives the uploaded program and writes it to the microcontroller’s flash
memory.
o Enables programming without an external programmer.

Arduino Compilation and Upload Process

Step Description
1. Code Write Write Arduino sketch in IDE
2. Preprocessing Convert .ino to .cpp and add includes
3. Compilation Compile C++ code to machine code using GCC
4. Linking Link compiled code with Arduino libraries
5. Uploading Upload .hex binary to the board using AVRDUDE
6. Execution Arduino runs uploaded program

Additional Tools

• Serial Monitor: Debugging tool to communicate with Arduino over USB.


• Library Manager: Install/update Arduino libraries easily.
• Board Manager: Add support for different Arduino and third-party boards.

Toolchain Summary
Tool Role
Arduino IDE Code editor, build, upload interface
AVR-GCC Compiler for AVR microcontrollers
AVRDUDE Uploads compiled code to Arduino board
Bootloader Runs on board to receive uploaded programs

Visualizing the Toolchain


Your Code (.ino)

Arduino IDE (Preprocessor)

C++ Code (.cpp)

Compiler (AVR-GCC)

Machine Code (.hex)

Uploader (AVRDUDE)

Arduino Board (Bootloader)

Program runs on Microcontroller

Arduino Programming Structure: Basics


An Arduino program is called a sketch and follows a simple structure with two main
functions:

1. setup()

• Runs once when the Arduino powers up or resets.


• Used to initialize variables, pins, and start libraries (e.g., serial communication).
• Example:
• void setup() {
• pinMode(13, OUTPUT); // Set pin 13 as output
• Serial.begin(9600); // Start serial communication at 9600
baud
• }

2. loop()

• Runs repeatedly after setup() finishes.


• Contains the main logic of the program, like reading sensors or controlling actuators.
• Runs continuously until the Arduino is turned off.
• Example:
• void loop() {
• digitalWrite(13, HIGH); // Turn LED on
• delay(1000); // Wait for 1 second
• digitalWrite(13, LOW); // Turn LED off
• delay(1000); // Wait for 1 second
• }

Complete Basic Arduino Sketch


void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // LED ON
delay(1000); // Wait 1 sec
digitalWrite(13, LOW); // LED OFF
delay(1000); // Wait 1 sec
}

Other Important Elements

• Functions: Define reusable code blocks you can call in loop() or setup().
• Variables: Store data like sensor readings or states.
• Libraries: Pre-written code for sensors, displays, communication, etc.
• Comments: Use // for single line or /* ... */ for multi-line comments.

Program Flow
Start

setup() — run once

loop() — repeat forever

(loop continues)

Arduino Sketches: What They Are


A sketch is the name Arduino gives to your program/code. It’s basically a text file containing
Arduino code, usually with the .ino extension.
Key Points About Sketches:

• Basic unit of Arduino programming — your entire program is a sketch.


• Written in a simplified version of C/C++.
• Must have at least two functions:
o setup() — runs once when the board starts.
o loop() — runs repeatedly after setup.
• Stored as .ino files and edited inside the Arduino IDE or any text editor.
• You can organize code into multiple tabs/sketch files within the IDE for better
structure.

Example of a Simple Sketch (Blink LED)


void setup() {
pinMode(13, OUTPUT); // Set digital pin 13 as output
}

void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000); // Wait 1 second
digitalWrite(13, LOW); // Turn LED off
delay(1000); // Wait 1 second
}

How Sketches Work in Arduino IDE:

• The IDE preprocesses the sketch, adding necessary headers and function prototypes.
• It compiles the sketch to machine code.
• It uploads the code to the Arduino board.
• The sketch runs on the microcontroller continuously until power off or reset.

Sketch File Organization:

Type Description
.ino Main sketch file
.h and .cpp files For libraries or custom code modules
Multiple tabs Split sketches into multiple files in IDE

Tips for Writing Sketches:

• Keep your setup() for initializations.


• Keep your main code and repeated tasks in loop().
• Use functions to organize code.
• Use comments for clarity.

Using Arduino Pins in Sketches: Input and Output


When writing Arduino sketches, you use pins to read inputs (like buttons or sensors) or send
outputs (like lighting an LED or controlling a motor).

1. Configuring Pins in Sketches


Use pinMode() inside the setup() function to set a pin as either:

• INPUT — to read signals (button presses, sensor data)


• OUTPUT — to send signals (turn LED on/off)

void setup() {
pinMode(2, INPUT); // Set pin 2 as input (e.g., button)
pinMode(13, OUTPUT); // Set pin 13 as output (e.g., LED)
}

2. Reading Input from Pins


Use digitalRead(pin) or analogRead(pin) inside loop() or functions to get data from
the pin.

• digitalRead() returns HIGH or LOW.


• analogRead() returns a value between 0 and 1023 for analog pins.

Example: Reading a button press

void loop() {
int buttonState = digitalRead(2); // Read digital pin 2
if (buttonState == HIGH) {
// Button is pressed
} else {
// Button not pressed
}
}

3. Writing Output to Pins


Use digitalWrite(pin, value) or analogWrite(pin, value) to control outputs:

• digitalWrite() sends HIGH or LOW (5V or 0V).


• analogWrite() sends PWM signals (0-255) to simulate analog voltage.

Example: Blinking an LED

void loop() {
digitalWrite(13, HIGH); // Turn LED on
delay(1000); // Wait 1 second
digitalWrite(13, LOW); // Turn LED off
delay(1000); // Wait 1 second
}

4. Complete Example: Button Controls LED


const int buttonPin = 2; // Button connected to pin 2
const int ledPin = 13; // LED connected to pin 13

void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
int buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED on if button pressed
} else {
digitalWrite(ledPin, LOW); // Turn LED off otherwise
}
}

Summary:

Function Usage Purpose


pinMode(pin, mode) Set pin as INPUT or OUTPUT Configure pin direction
Read digital signal
digitalRead(pin) Get input from digital pins
(HIGH/LOW)
analogRead(pin) Read analog signal (0-1023) Get input from analog pins
digitalWrite(pin,
value) Write HIGH or LOW to pin Control digital output
Control analog-like output
analogWrite(pin, value) Write PWM signal (0-255)
(PWM)

Introduction to Arduino Shields


An Arduino Shield is an add-on board that plugs directly into an Arduino to extend its
functionality without complicated wiring.

What are Arduino Shields?

• Modular expansion boards designed to stack on top of an Arduino board.


• They have standard pin layouts matching Arduino headers, so they connect easily.
• Provide ready-made hardware features such as:
o Motor control
o Wireless communication (Wi-Fi, Bluetooth)
o Sensor interfaces
o Displays
o GPS, Ethernet, GSM, etc.

Why Use Arduino Shields?

• Simplify building complex projects.


• Save time on wiring and circuit design.
• Make prototyping faster and less error-prone.
• Easily stack multiple shields for combined features.

Common Types of Arduino Shields

Shield Type Purpose


Motor Shield Control DC motors, stepper motors, servos
Ethernet Shield Connect Arduino to the internet via Ethernet
Wi-Fi Shield Add Wi-Fi connectivity
Bluetooth Shield Enable wireless communication over Bluetooth
GPS Shield Add GPS positioning
Sensor Shield Easier connection to multiple sensors
LCD/Display Shield Add graphical or character LCD displays
Relay Shield Control high-power devices with relays

How Shields Work

• Shields plug into the Arduino headers with pins aligned.


• They share the Arduino's power supply and communicate via:
o Digital pins
o Analog pins
o Communication buses like I2C, SPI, UART
Example: Using a Motor Shield

• Controls motors with dedicated circuitry.


• Simplifies power handling and direction control.
• Can control multiple motors at once.

Summary

Feature Description
Plug and play Stackable, easy connection
Extend Arduino Add new hardware features
Standard pin layout Fits Arduino Uno, Mega, Leonardo, etc.
Simplify wiring No need for manual breadboard wiring

Introduction to Sensors in IoT


Sensors are devices that detect and measure physical properties from the environment and
convert them into signals readable by microcontrollers or computers.

1. What is a Sensor?
• A device that measures a physical quantity (like temperature, light, motion).
• Converts the measurement into an electrical signal.
• Used extensively in IoT for monitoring and automation.

2. Common Sensor Specifications


Specification Description
Range The span of values the sensor can measure (e.g., 0-100°C)
Accuracy How close the sensor reading is to the true value (e.g., ±0.5°C)
Resolution The smallest change the sensor can detect (e.g., 0.1°C)
Response Time Time the sensor takes to respond to a change (milliseconds to seconds)
Power How much power the sensor uses (important for battery-powered IoT
Consumption devices)
Output Type Analog, digital, PWM, I2C, SPI, etc.
3. Components of a Sensor System
Component Role
The part that detects the physical phenomenon (e.g.,
Sensing Element
thermistor, photodiode)
Signal Conditioning Amplifies, filters, or converts signals into a usable form
Analog-to-Digital Converter Converts analog sensor signals to digital for
(ADC) microcontrollers
Communication Interface Protocols used to send data (I2C, SPI, UART, etc.)
Power Supply Provides energy to operate the sensor

4. Types of Sensors
By Physical Quantity Measured:

Type Measures Example Sensors


Temperature Heat level LM35, DHT11, DS18B20
LDR (Light Dependent Resistor),
Light Intensity of light
TSL2561
Proximity Presence or absence of an object IR sensor, Ultrasonic sensor
Motion Movement detection PIR sensor, Accelerometer
Pressure Force applied per unit area BMP180, MPX5700
Humidity Moisture in air DHT11, DHT22
Presence of gases (CO2, methane,
Gas MQ-2, MQ-7
etc.)
Sound Sound levels Microphone sensors
Magnetic Magnetic fields Hall effect sensor

By Output Type:

Type Description
Analog Outputs continuous voltage signal
Digital Outputs binary signals (HIGH/LOW)
I2C/SPI Uses serial communication protocols for data exchange
PWM Outputs pulses with variable width to encode info

Actuators: Introduction
An actuator is a device that converts electrical signals into physical movement or action.
It acts on the environment based on commands from a controller like an Arduino.
What Are Actuators?

• Devices that perform actions such as moving, turning, pushing, or controlling


physical systems.
• Used in IoT and robotics to interact with the real world.
• Receive input signals (usually electrical) and output mechanical motion or force.

Types of Actuators

Type Description Examples


Use electrical energy to produce DC motors, servo motors,
Electric Actuators
motion stepper motors
Hydraulic Use fluid pressure to create
Hydraulic cylinders
Actuators movement
Pneumatic Use compressed air to produce
Pneumatic cylinders
Actuators motion
Use heat to generate mechanical
Thermal Actuators Shape memory alloys
movement
Mechanical Use mechanical components to
Gears, cams, levers
Actuators produce action

Common Actuators in Arduino/IoT Projects

• DC Motor: Rotates continuously, used for wheels, fans, pumps.


• Servo Motor: Rotates within a limited angle (usually 0-180°), used for precise
control like robotic arms.
• Stepper Motor: Rotates in discrete steps, good for precise positioning.
• Solenoid: Creates linear motion (push/pull) by electromagnetic force.
• Relays: Electrically operated switches to control high-power devices.
• LEDs: Light up based on electrical input (actuator for visual signals).

How Actuators Work in IoT Systems

1. Controller sends signal (e.g., Arduino digital output).


2. Signal activates actuator (e.g., motor starts spinning).
3. Actuator performs physical action (e.g., opens valve, moves arm).
4. Feedback sensors (optional) report back status.

Example: Controlling a Servo Motor with Arduino


#include <Servo.h>

Servo myServo; // Create servo object

void setup() {
myServo.attach(9); // Attach servo signal to pin 9
}

void loop() {
myServo.write(90); // Move servo to 90 degrees
delay(1000);
myServo.write(0); // Move servo back to 0 degrees
delay(1000);
}

Summary:

Aspect Details
Actuators convert electrical signals to motion or force
Types include electric, hydraulic, pneumatic, thermal
Widely used actuators: motors, servos, solenoids, relays
Actuators enable IoT devices to interact with the physical world

Integration of Sensors and Actuators with Arduino


Arduino acts as the brain in an IoT or embedded system, reading data from sensors and
controlling actuators based on that data or logic.

1. Basic Concept
• Sensors → Arduino reads signals (input).
• Arduino processes data → runs your program/logic.
• Actuators → Arduino outputs signals to control devices (output).

2. Connecting Sensors to Arduino


• Connect sensor output pin to an Arduino input pin (digital or analog).
• Provide sensor power and ground from Arduino.
• Use pinMode() to set input pins and analogRead() or digitalRead() to get sensor
values.
3. Connecting Actuators to Arduino
• Connect actuator control input to an Arduino output pin.
• Provide external power if actuator needs more current than Arduino can supply.
• Use pinMode() to set output pins and digitalWrite(), analogWrite(), or libraries
(e.g., Servo library) to control actuators.

4. Example: Controlling an LED (Actuator) Based on a


Light Sensor
Components:

• Photoresistor (LDR) as sensor.


• LED as actuator.

Circuit Connections:

Component Arduino Pin


LDR sensor One end to 5V, other end to A0 and a resistor to GND (voltage divider)
LED Digital pin 13 (+ resistor) and GND

Sketch Example:
const int sensorPin = A0; // Analog input pin for LDR
const int ledPin = 13; // Digital output pin for LED
int sensorValue = 0;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // For debugging
}

void loop() {
sensorValue = analogRead(sensorPin); // Read light intensity
Serial.println(sensorValue);

if (sensorValue < 300) { // If it’s dark


digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
delay(200);
}
5. Tips for Integration
• Use external power sources for high-power actuators (motors, solenoids).
• Use transistors or motor drivers to interface actuators safely.
• Use libraries for complex actuators (servos, stepper motors).
• Add debouncing for mechanical sensors like buttons.
• Use interrupts for time-critical sensor readings.

Summary
Step Description
Connect sensors To Arduino input pins (analog/digital)
Read sensors Use analogRead() or digitalRead()
Process data Use logic in loop() to decide outputs
Connect actuators To Arduino output pins (digital/PWM)
Control actuators Use digitalWrite(), analogWrite(), or specialized libraries

You might also like