Module -2 Ppt Smart Iot (1)
Module -2 Ppt Smart Iot (1)
•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
•They should enable automation and therefore minimize the need for intervention of
human participants.
Disadvantages of Actuators
•May consume much power in its operation particularly when used in places that involve
much power such as in large industries.
•As a disadvantage there is a circumstance that, with time the component is liable to
mechanical wear and tear.
SENSOR ACTUATOR
It is placed at input port of the system. It is placed at output port of the system.
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.
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.
#include "DHT.h"
•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);
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.
➢ Robotics
➢ Testing automation
➢ Manufacturing automation
➢ CNC machine etc.
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 ;
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;
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);