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

Module -2 Ppt Smart Iot (1)

Uploaded by

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

Module -2 Ppt Smart Iot (1)

Uploaded by

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

MODULE -2

SENSORS AND ACTUATORS, INTERFACING


1 2 3
Sensor and actuators On the same note, while actuators are
are basic elements in sensors are tasked tasked with the
numerous electrical with the responsibility responsibility of
and mechanical of identifying changes performing certain
structures. within an environment actions in response to
these detections.
• Sensor

• Sensor is a device used for the


conversion of physical events or
characteristics into the electrical
signals. This is a hardware device that
takes the input from environment and
gives to the system by converting it.
For example, a thermometer takes
the temperature as physical
characteristic and then converts it
into electrical signals for the system.
Transducer :
•A transducer converts a signal from one physical
structure to another.
•It converts one type of energy into another type.
Sensor working
Sensor is a module or
chip that observes
the changes
happening in the
physical world and
sends the feedback
to the
microcontroller or
microprocessor.
Excitation (Power
supply) and
Grounding must be
provided to the
sensor for the proper
working.
Classification of Sensors
Microcontroller accepts two types of inputs depending
up on the type of sensor i.e. analog or digital.

Analog sensor senses the external parameters (wind


speed, solar radiation, light intensity etc.) and gives
analog voltage as an output.
The output voltage may be in the range of 0 to
5V. Logic High is treated as “1” (3.5 to 5V) and Logic
Low is indicated by “0” (0 to 3.5 V).
Analog sensors have several advantages

•High resolution: Analog sensors can capture subtle changes and


provide a high resolution.
•Continuous range of values: Analog sensors can provide a
continuous range of values, which allows for more precise
measurements.
•Simplicity and cost-effectiveness: Analog sensors are simple and
cost-effective.
•Disadvantages
•Susceptible to noise and interference: Analog sensors are more susceptible to
noise and interference from outside sources like electric motors, radio waves,
or lightning strikes.
•Limited flexibility: Analog sensors are not very flexible.
•Inefficient at storing large amounts of data: Analog sensors are not very
efficient at storing large amounts of data because each value has to be stored
separately.
•May require additional components: Analog sensors may require additional
components, such as amplifiers, filters, or converters, to improve their
accuracy and compatibility.
Digital Sensor produce discrete values (0 and 1’s). Discrete values
often called digital (binary) signals in digital communication.
Digital sensors are an important part of the Internet of Things (IoT), and
they can offer many benefits, including:

•Real-time data: Digital sensors can monitor processes in real-time, allowing


companies to address issues immediately.

•Improved efficiency: Sensors can help improve efficiency and productivity in


day-to-day operations.

•Cost savings: Sensors can help reduce costs through automation.

•Enhanced safety and compliance: Sensors can help ensure safety and
compliance in many industries.
disadvantages of Digital Sensor
It is complex compare to analog sensor as it requires data
conversion

➨It cannot provide continuous output for every change in


input parameters which can be addressed by analog sensor.

➨The cost is more than analog sensor due to use of


microprocessor and data storage capabilities.
Feature Analog sensor Digital sensor
Outputs continuous voltage or
current signals representing the Outputs discrete digital signals,
Data output
analog value of the physical usually in binary form.
quantity.
Depends on the quality of the
sensor and circuit design, may be High accuracy, less affected by
Accuracy
affected by noise and noise and interference.
interference.
Limited by the sensor and ADC High resolution, typically 12-bit,
Resolution
resolution, usually lower. 16-bit, or higher.
Can be transmitted over long
Limited transmission distance,
distances via serial interfaces (such
Transmission distance susceptible to electromagnetic
as I2C, SPI, UART), strong anti-
interference.
interference ability.

Simple interface, typically reads Complex interface, requires


Interface complexity signals through voltage or current protocols and standards to read
changes. and transmit data.

May be higher due to more


Usually low, depending on specific
Power consumption integrated circuits and processing
circuit design.
functions.

Generally more expensive, but has


Generally cheaper, suitable for
Cost advantages in accuracy and
simple and low-cost applications.
reliability.
May require Lower calibration
frequent calibration frequency, usually
Calibration
to maintain calibrated at the
accuracy. factory.
Short response Response time
Response time, suitable for may be longer due
time measuring rapidly to data processing
changing signals. and conversion.
Types of Sensors
•Temperature Sensors: Take temperatures.
•Light Sensors: Light intensity sensors: It has the
function of detecting the intensity of the light.
•Pressure Sensors: To use it to measure pressure in
gases or liquids.
•Motion Sensors: Recognize motion in an
established region.
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 of the system. Sensors in
the device sense the environment, then control
signals are generated for the actuators according
to the actions needed to perform.
Advantages of Actuators
•Assist in providing a fine level of control of mechanical installations.

•They should enable automation and therefore minimize the need for intervention of
human participants.

•Available in a range of variations and suitability in multiple operations ranging from


everyday uses to industrial use.

Disadvantages of Actuators
•May consume much power in its operation particularly when used in places that involve
much power such as in large industries.

•May be large and costly to both install and maintain.

•As a disadvantage there is a circumstance that, with time the component is liable to
mechanical wear and tear.
SENSOR ACTUATOR

It converts electrical signals into physical


It converts physical characteristics into electrical signals.
characteristics.

It takes input from output conditioning unit of


It takes input from environment.
system.

It gives output to input conditioning unit of system. It gives output to environment.

Sensor generated electrical signals. Actuator generates heat or motion.

It is placed at input port of the system. It is placed at output port of the system.

It is used to measure the continuous and discrete


It is used to measure the physical quantity.
process parameters.

It gives information to the system about environment. It accepts command to perform a function.

Example: Photo-voltaic cell which converts light energy into Example: Stepper motor where electrical energy
electrical energy. drives the motor.
INTERFACING OF SENSORS AND
ACTUATORS
Arduino Coding Basics
void setup ( )
{
Coding statement 1;
Coding statement 2;
.
.
.
Coding statement n;
}
void loop ( )
{
Coding statement 1;
Coding statement 2;
.
.
.
Coding statement n;
}
Serial.begin ( )
The serial.begin( ) sets the baud rate for.

The baud rate signifies the data rate in bits per second. serial data
communication
void setup ( )
{
Serial.begin(4800);
}
void loop ( )
{
}
Arduino Serial.print ( )
void setup ( )
{
Serial.begin ( 4800);
}
void loop ( )
{
Serial.print(" Hello");
delay(1000);
Serial.println("Arduino"); // It will print Arduino followed by a new line.

delay ( 1500); // delay of 1.5 seconds between each printed line.


}
PROGRAM FOR INTERFACING LED
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin
as an output
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
void setup ()
{
pinMode ( 13, OUTPUT); // to set the OUTPUT mode of pin number 13.

pinMode ( 7, OUTPUT); // to set the OUTPUT mode of pin number 7.


}
void loop ()
{
digitalWrite (13, HIGH);
digitalWrite (7, LOW);
delay(1500); // 1.5 second = 1.5 x 1000 milliseconds
digitalWrite (13, LOW);
digitalWrite (7, HIGH);
delay(1000); // 1 second = 1 x 1000 milliseconds
}
This program blinks LED connection to the pin number
13, 8, and 4

void setup()
{
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
// the first LED is made to blink one time
digitalWrite(13, HIGH);
delay(1000); // delay time in milliseconds
digitalWrite(13, LOW);
delay(1000);
// the second LED will blink two times
digitalWrite(8, HIGH);
delay(500); // the duration is 0.5 seconds
digitalWrite(8, LOW);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
// the third LED will blink three times
for( int i = 0; i < 3; i = i +1 )
{
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(500);
// We can adjust the delay time accordingly
}
}
const int pinOFswitch = 3; void loop( )
{
const int LED = 8; int ValueOFswitch;
void setup( ) { ValueOFswitch = digitalRead(pinOFswitch)
;
pinMode(pinOFswitch, IN if (ValueOFswitch == HIGH)
PUT); {
pinMode(LED, OUTPUT); digitalWrite(LED, HIGH);
} delay(500);
}

else
{
digitalWrite(LED, LOW);
delay(500);
}
}
const int LEDpin = 12;
const int photoPIN = A0;

void setup()
{
// initializing the serial communication
Serial.begin(9600);
pinMode(photoPIN, INPUT);
pinMode(LEDpin, OUTPUT);
}
void loop() {
// read the sensor:
int sensorStatus = analogRead(photoPIN);
// now, it will check the reading or status of the sensor is < 200
// if it is, LED will be HIGH
if (sensorStatus <200)
{
digitalWrite(LEDpin, HIGH); // LED is ON
Serial.println(" LED is ON, status of sensor is DARK");
}
else
{
digitalWrite(LEDpin, LOW);
Serial.println(" ***************");
}
}
Interfacing DHT11 sensor
Humidity is the measure of water vapour present in the air.
The level of humidity in air affects various physical, chemical
and biological processes.

In industrial applications, humidity can affect the business


cost of the products, health and safety of the employees.

Humidity measurement determines the amount of moisture


present in the gas that can be a mixture of water vapour,
nitrogen, argon or pure gas etc…
DHT11 is a low-cost digital sensor for sensing temperature and
humidity. This sensor can be easily interfaced with any micro-controller
such as Arduino, Raspberry Pi etc… to measure humidity and
temperature instantaneously.
DHT11 Pinout Configuration

No Pin name Description


1 Vcc Power supply 3.5V to 5.5V

2 Data Outputs both Temperature and


Humidity through serial Data

3 NC No Connection and hence not used

4 Ground Connected to the ground of the circuit


Program for interfacing DHT 11 (Digital Humidity Temperature
Sensor

#include "DHT.h"

#define DHTPIN 4 // Digital pin connected to the DHT sensor

#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);


void setup()
{
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
}
void loop()
{
// Wait a few seconds between measurements.
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % Temperature: ");
Serial.println(t);
}
Interfacing of PIR (Passive Infrared ) Motion
All objects (having temperature higher than absolute
zero) emit radiations from the generated heat. These
radiations cannot be detected by a human eye. Hence,
electronic devices such as motion sensors, etc. are used
for the detection of these radiations.
The Passive Infra-Red sensors or PIR sensors detect
motion or movement of an object that detect infrared
radiations, such as the human body. Hence, the use of
sensors is very common.

The advantages of using a PIR sensor are listed below:

•Inexpensive
•Adjustable module
•Efficient
•Small in size
•Less power consumption
•It can detect motion in the dark as well as light.
The PIR sensor has three
terminals, which are listed below:

•VCC
•Digital Output
•GND (Ground)
int LEDpin = 13; // LED pin
int PIRpin = 8; // The pin of Arduino connected to the PIR output
int PIRvalue = 0; // It specifies the status of PIR sensor

void setup()
{
pinMode(LEDpin, OUTPUT);
pinMode(PIRpin, INPUT); // the output from the sensor is considered as
input for Arduino
Serial.begin(9600);
}
void loop()
{
PIRvalue = digitalRead(PIRpin);
if (PIRvalue == HIGH)
{
digitalWrite(LEDpin, HIGH);
// turn ON LED if the motion is detected
Serial.println("hello, I found you...heyyy..");
}
else
{
digitalWrite(LEDpin, LOW);
// LED will turn OFF if we have no motion
Serial.println("I cannot find you");
delay(1000);
}
}
Smoke Detector using Gas Sensor
•VCC provides power to the sensor comparator board and needs to be
connected to the 5V of the Arduino

•GND is the ground pin and needs to be connected to the GND pin of the
Arduino.

•D0 is the digital output pin, which shows the digital representation of
the detected gas.

•A0 is the analog output pin from which we can detect the gas type by
analyzing analog values.
int red_LED_PIN = 11;
int green_LED_PIN = 9;
int blue_LED_PIN = 10;
int buzzer = 6;
int smoke_detector = A0;
int safety_lim = 60; //Sets smoke density safe limit

void setup()
{
pinMode(red_LED_PIN, OUTPUT);
pinMode(green_LED_PIN, OUTPUT);
pinMode(blue_LED_PIN, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smoke_detector, INPUT);
Serial.begin(9600); //baud rate
}
void loop() {
int sensor_read = analogRead(smoke_detector); //reads and stores
Serial.print("Smoke Density: ");
Serial.println(sensor_read);

if (sensor_read > safety_lim) // Checks if reading is beyond safety limit


{
analogWrite(red_LED_PIN,255);
analogWrite(green_LED_PIN, 0);
tone(buzzer,500, 100); //piezo rings
}
else
{
analogWrite(green_LED_PIN, 255);
analogWrite(red_LED_PIN,0);
noTone(buzzer); //peizo wont ring
}
delay(50);
}
Interfacing ultrasonic sensor with Arduino
•Ultrasonic Module HC-SR04
works on the principle of
SONAR and RADAR system. It
can be used to determine the
distance of an object in the
range of 2 cm – 400 cm.
•The module has only 4 pins,
1.VCC
2.GND
3.Trig
4.Echo
const int trigPin = 4;
const int echoPin = 5;

void setup()
{
Serial.begin(9600); // Initialize serial communication for debugging
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop()
{
// Trigger the ultrasonic sensor by sending a 10us pulse
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the time it takes for the echo to return
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
int distance = duration * 0.0343 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000); // Delay for readability (adjust as needed)
}
Actuator interfacing
Interfacing Servo Motor with Arduino Uno
Servo Motor is an electrical linear or rotary actuator which
enables precise control of linear or angular position,
acceleration or velocity.

Usually servo motor is a simple motor controlled by a


servo mechanism, which consists of a positional sensor
and a control circuit.
Servo motor is commonly used in applications like

➢ Robotics
➢ Testing automation
➢ Manufacturing automation
➢ CNC machine etc.

The main characteristics of


servo motor are

low speed, medium torque, and accurate position


#include <Servo.h>
Servo servo;
int angle = 10;
// now rotate back from 180 to 0
void setup() degrees
{ for(angle = 180; angle > 10; angle--)
servo.attach(3);
{
servo.write(angle); servo.write(angle);
}
delay(15);
void loop() }
{ // rotate from 0 to 180 degrees }
for(angle = 10; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
Interfacing DC Motor with Arduino Uno
The following table shows which direction the motor will turn
based on the digital values of IN1 and IN2.
IN1 IN2 MOTOR
0 0 BRAKE
1 0 FORWARD
0 1 BACKWARD
1 1 BRAKE

IN1 pin of the L298 IC is connected to pin 8 of the Arduino while IN2 is connected to pin 9. These two digital pins of
Arduino control the direction of the motor.
The EN A pin of IC is connected to the PWM pin 2 of Arduino. This will control the speed of the motor.
const int pwm = 2 ; //initializing pin 2 as pwm
const int in_1 = 8 ;
const int in_2 = 9 ;

//For providing logic to L298 IC to choose the direction of the DC motor

void setup()
{
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
pinMode(in_2,OUTPUT) ;
}
void loop()
{ //For Anti Clock-wise motion -
//For Clock wise motion , in_1 = IN_1 = LOW , IN_2 = HIGH
High , in_2 = Low digitalWrite(in_1,LOW) ;
digitalWrite(in_1,HIGH) ; digitalWrite(in_2,HIGH) ;
digitalWrite(in_2,LOW) ; delay(3000) ;
analogWrite(pwm,255) ;
//Clockwise for 3 secs //For brake
delay(3000) ; digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
//For brake delay(1000) ;
digitalWrite(in_1,HIGH) ; }
digitalWrite(in_2,HIGH) ;
delay(1000) ;
Interfacing Stepper Motor with Arduino Uno
#include <Stepper.h>
const int stepsPerRevolution = 90;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup()
{
// set the speed at 60 rpm:
myStepper.setSpeed(5);

Serial.begin(9600);
}
void loop()
{
// step one revolution in one direction:

Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);

// step one revolution in the other direction:


Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}

You might also like