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

UNIT 5_IOT and Ard

This is about IOT AND ARDUINO PROGRAMMING

Uploaded by

ayushkumar32388
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)
4 views

UNIT 5_IOT and Ard

This is about IOT AND ARDUINO PROGRAMMING

Uploaded by

ayushkumar32388
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/ 14

UNIT 5

IOT and its Sensors

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.

The key features are −


• 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).
• Unlike most previous programmable circuit boards, Arduino does not
need an extra piece of hardware (called a programmer) in order to
load a new code onto the board. You can simply use a USB cable.
• Additionally, the Arduino IDE uses a simplified version of C++,
making it easier to learn to program.
• Finally, Arduino provides a standard form factor that breaks the
functions of the micro-controller into a more accessible package.

Installation of Arduino Desktop IDE

To Download the Arduino Software (IDE) visit www.Arduino.cc. After that


following webpage will get open.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Run the file downloaded from the software page.

Follow the instructions in the installation guide. The installation may take
several minutes.

You can now use the Arduino IDE 2.0 on your Windows computer!

Pin Configuration of Arduino UNO

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


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 (2).

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.

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. The
number printed on top of the Arduino crystal is 16.000H9H. It tells us that the
frequency is 16,000,000 Hertz or 16 MHz.

Reset Button and Reset Pin


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 on the
board. Second, you can connect an external reset button to the Arduino pin
labelled RESET.

3.3V, 5V, GND and Vin


3.3V − Supply 3.3 output volt
5V − Supply 5 output volt
GND − Used to ground the circuit.
Vin − Used to power the Arduino board from an external power source, like AC
mains power supply.

Analog pins
It 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. The microcontrollers are usually of the ATMEL Company.

ICSP pin
Mostly, ICSP is an AVR, a tiny programming header for the Arduino consisting of
MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial
Peripheral Interface), which could be considered as an "expansion" of the output.
Actually, you are slaving the output device to the master of the SPI bus.

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.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


TX and RX LEDs
TX means transmit and RX means 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 (13). 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.

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.

Basics of Arduino Programming

The coding screen is divided into two blocks. The setup is considered as the
preparation block, while the loop is considered as the execution block.
The set of statements in the setup and loop blocks are enclosed with the curly
brackets. We can write multiple statements depending on the coding
requirements for a particular project.

void setup ( )
{
Coding statement 1;
Coding statement 2;
.
.
.
Coding statement n;
}
void loop ( )
{
Coding statement 1;
Coding statement 2;
.
.
.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Coding statement n;
}

Setup: It contains an initial part of the code to be executed. The pin modes,
libraries, variables, etc., are initialized in the setup section. It is executed only
once during the uploading of the program and after reset or power up of the
Arduino board.
Loop: The loop contains statements that are executed repeatedly. The section of
code inside the curly brackets is repeated depending on the value of variables.

PinMode: The specific pin number is set as the INPUT or OUTPUT in the pinMode
() function.

The Syntax is: pinMode (pin, mode)

Where,

pin: It is the pin number. We can select the pin number according to the
requirements.

Mode: We can set the mode as INPUT or OUTPUT according to the corresponding
pin number.

Let' understand the pinMode with an example.


pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin

digitalWrite:The digitalWrite ( ) function is used to set the value of a pin as HIGH


or LOW.

Where,

HIGH: It sets the value of the voltage. For the 5V board, it will set the value of 5V,
while for 3.3V, it will set the value of 3.3V.

LOW: It sets the value = 0 (GND).

If we do not set the pinMode as OUTPUT, the LED may light dim.

The syntax is: digitalWrite( pin, value HIGH/LOW)

pin: We can specify the pin number or the declared variable.

Example:
digitalWrite(13, LOW); // Makes the output voltage on pin 13 , 0V
digitalWrite(13, HIGH); // Makes the output voltage on pin 13 , 5V

digitalRead(): The digitalRead () function will read the HIGH/LOW value from the
digital pin, and the digitalWrite () function is used to set the HIGH/LOW value of
the digital pin.

int buttonState = digitalRead(2); // reads the value of pin 2 in buttonState

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


delay: The delay () function is a blocking function to pause a program from doing
a task during the specified duration in milliseconds.

For example, - delay (2000)

Where, 1 sec = 1000millisecond

Hence, it will provide a delay of 2 seconds.

Some Programs

Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 2.

CONNECTIONS

connect one end of button with one end of resistor. Connect other end of resisitor
to GND.
Connect other end of button 5v.
Connect one end of button (just oppostite to those end which is connected to
GND) to pin 2.

CODE

const int buttonPin = 2; // the number of the pushbutton pin


const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Turns on and off a light emitting diode(LED) connected to digital


pin 3, when pressing a pushbutton attached to pin 2.

CONNECTIONS

connect one end of button with one end of resistor. Connect other end of resisitor
to GND.
Connect other end of button 5v.
Connect one end of button (just opposite to those end which is connected to GND)
to pin 2.
connect long leg of LED to one end of another resistor.
Connect other end of that resistor to +5v of arduino.
Connect short leg of LED to GND.
Connect long tail of LED to digital input 2 of arduino

CODE

const int buttonPin = 2; // the number of the pushbutton pin


const int ledPin =3; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


// turn LED off:
digitalWrite(ledPin, LOW);
}

Definition of IOT

Internet of things (IOT) is a network of physical objects. The internet is not only a
network of computers, but it has evolved into a network of device of all type and
sizes , vehicles, smart phones, home appliances, toys, cameras, medical
instruments and industrial systems, animals, people, buildings, all connected ,all
communicating & sharing information based on stipulated protocols in order to
achieve smart reorganizations, positioning, tracing, safe & control & even
personal real time online monitoring , online upgrade, process control &
administration. Internet of things is an internet of three things:
(1). People to people,
(2) People to machine /things,
(3) Things /machine to things /machine, Interacting through internet

Characteristics of IOT

The fundamental characteristics of the IoT are as follows:

Interconnectivity: With regard to the IoT, anything can be interconnected with


the global information and communication infrastructure.

Things-related services: The IoT is capable of providing thing-related services


within the constraints of things, such as privacy protection and semantic
consistency between physical things and their associated virtual things. In order
to provide thing-related services within the constraints of things, both the
technologies in physical world and information world will change.

Heterogeneity: The devices in the IoT are heterogeneous as based on different


hardware platforms and networks. They can interact with other devices or service
platforms through different networks.

Dynamic changes: The state of devices change dynamically, e.g., sleeping and
waking up, connected and/or disconnected as well as the context of devices
including location and speed. Moreover, the number of devices can change
dynamically.

Enormous scale: The number of devices that need to be managed and that
communicate with each other will be at least an order of magnitude larger than
the devices connected to the current Internet. Even more critical will be the
management of the data generated and their interpretation for application
purposes. This relates to semantics of data, as well as efficient data handling.

Safety: As we gain benefits from the IoT, we must not forget about safety. As both
the creators and recipients of the IoT, we must design for safety. This includes
the safety of our personal data and the safety of our physical well-being. Securing
the endpoints, the networks, and the data moving across all of it means creating
a security paradigm that will scale.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Connectivity: Connectivity enables network accessibility and compatibility.
Accessibility is getting on a network while compatibility provides the common
ability to consume and produce data.

Sensor and its types

Sensor is an input device which provides an output (signal) with respect to a


specific physical quantity (input).

The term “input device” in the definition of a Sensor means that it is part of a
bigger system which provides input to a main control system (like a Processor or
a Microcontroller).

Another unique definition of a Sensor is as follows: It is a device that converts


signals from one energy domain to electrical domain.

Different types of Sensors

The following is a list of different types of sensors that are commonly used in
various applications. All these sensors are used for measuring one of the physical
properties like Temperature, Resistance, Capacitance, Conduction, Heat Transfer
etc.

1) Temperature Sensor: It detects the heat energy which is produced from an


object. It is used for temperature monitoring of machines / plants / soil /
water.

2) Humidity Sensor: It is used to monitor the level of humidity in the amount


of vapor of water within the air.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


3) Light Sensor: Sometimes also known as Photo Sensors, Light Sensors are
one of the important sensors. A simple Light Sensor available today is the
Light Dependent Resistor or LDR. The property of LDR is that its resistance
is inversely proportional to the intensity of the ambient light i.e., when the
intensity of light increases, its resistance decreases and vise-versa.

Ultrasonic Sensor: An Ultrasonic Sensor is a non-contact type device that can be


used to measure distance as well as velocity of an object. An Ultrasonic Sensor
works based on the properties of the sound waves with frequency greater than
that of the human audible range.

Controlling Temperature Sensor

The Temperature Sensor LM35 series are precision integrated-circuit temperature


devices with an output voltage linearly proportional to the Centigrade
temperature.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


LM35 sensor has three terminals - Vs, Vout and GND. We will connect the sensor
as follows −

• Connect the +Vs to +5v on your Arduino board.


• Connect Vout to Analog0 or A0 on Arduino board.
• Connect GND with GND on Arduino.
The Analog to Digital Converter (ADC) converts analog values into a digital
approximation based on the formula ADC Value = sample * 1024 / reference
voltage (+5v). So with a +5 volt reference, the digital approximation will be equal
to input voltage * 205.

Why 0.48828125 ?

This is (+Vcc * 1000 / 1024) / 10


Where +Vcc is the supply voltage = +5V, 1024 is 2^10, value where the analog
value can be represented by ATmega the actual voltage obtained by
VOLTAGE_GET / 1024.

1000 is used to change the unit from V to mV & 10 is a constant as each 10 mV


is directly proportional to 1 Celsius in LM35.

So (5.0 * 1000 / 1024) / 10 = 0.48828125.

Code:

float temp;
int tempPin = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp
temp = temp * 0.48828125;
// convert the analog volt to its temperature equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature value
Serial.print("*C");

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Serial.println();
delay(1000); // update sensor reading each one second
} temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp
temp = temp * 0.48828125;
// convert the analog volt to its temperature equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature value
Serial.print("*C");
Serial.println();
delay(1000); // update sensor reading each one second
}

Controlling Humidity Sensor

The pins on the humidity sensor are S, for signal, the one in the middle is
voltage, and the minus sign is ground. The signal pin goes to header A0 on the
Arduino. The middle pin goes to 5V, and the minus sign goes to GND.

First of all we have to add DHT library. For this we have to follow following
steps:
In Arduino go to sketch >> include libraries >> manage libraries
In library manager search DHT 11 then click on install.

Code:

#include <dht.h>

#define dht_apin A0 // Analog Pin sensor is connected to dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
//Start of Program

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop(

Actuators in IOT

An IoT device is made up of a Physical object (“thing”) + Controller (“brain”)


+ Sensors + Actuators + Networks (Internet). An actuator is a machine
component or system that moves or controls the mechanism or the system.
Sensors in the device sense the environment, then control signals are
generated for the actuators according to the actions needed to perform.
A servo motor is an example of an actuator. They are linear or rotator y
actuators, can move to a given specified angular or linear position. We can use
servo motors for IoT applications and make the motor rotate to 90 degrees,
180 degrees, etc., as per our need.

Types of Actuators:

1. Hydraulic Actuators –
A hydraulic actuator uses hydraulic power to perform a mechanical
operation. They are actuated by a cylinder or fluid motor. The mechanical
motion is converted to rotary, linear, or oscillatory motion, according to the
need of the IoT device. Ex- construction equipment uses hydraulic actuators
because hydraulic actuators can generate a large amount of force.
Advantages :
• Hydraulic actuators can produce a large magnitude of force and high
speed.
• Used in welding, clamping, etc.
• Used for lowering or raising the vehicles in car transport carriers.
Disadvantages :
• Hydraulic fluid leaks can cause efficiency loss and issues of cleaning.
• It is expensive.
• It requires noise reduction equipment, heat exchangers, and high
maintenance systems.

2. Pneumatic Actuators –
A pneumatic actuator uses energy formed by vacuum or compressed air at high
pressure to convert into either linear or rotary motion. Example- Used in robotics,
use sensors that work like human fingers by using compressed air.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg


Advantages :
• They are a low-cost option and are used at extreme temperatures where
using air is a safer option than chemicals.
• They need low maintenance, are durable, and have a long operational
life.
• It is very quick in starting and stopping the motion.
Disadvantages :
• Loss of pressure can make it less efficient.
• The air compressor should be running continuously.
• Air can be polluted, and it needs maintenance.

3. Electrical Actuators –
An electric actuator uses electrical energy, is usually actuated by a motor that
converts electrical energy into mechanical torque. An example of an electric
actuator is a solenoid based electric bell.
Advantages :
• It has many applications in various industries as it can automate
industrial valves.
• It produces less noise and is safe to use since there are no fluid
leakages.
• It can be re-programmed and it provides the highest control precision
positioning.
Disadvantages :
• It is expensive.
• It depends a lot on environmental conditions.

Other actuators are –


• Thermal/Magnetic Actuators –
These are actuated by thermal or mechanical energy. Shape Memory
Alloys (SMAs) or Magnetic Shape‐Memory Alloys (MSMAs) are used by
these actuators. An example of a thermal/magnetic actuator can be a
piezo motor using SMA.
• Mechanical Actuators –
A mechanical actuator executes movement by converting rotary motion
into linear motion. It involves pulleys, chains, gears, rails, and other
devices to operate. Example – A crankshaft.
• Soft Actuators
• Shape Memory Polymers
• Light Activated Polymers

With the expanding world of IoT, sensors and actuators will find more
usage in commercial and domestic applications along with the pre-existing
use in industry.

Prof. S D Mishra, Assistant Professor, Department of CSE, BIT Durg

You might also like