0% found this document useful (0 votes)
50 views13 pages

Lab 4 (1) Iot

This document provides information about various sensors that can be used with an Arduino board, including analogue and digital sensors. It describes sensors for sound, flame, smoke, humidity and temperature. Code examples are provided to interface sensors like a sound sensor, flame sensor, smoke sensor and humidity sensor with an Arduino and read sensor values. The document aims to help users learn about integrating different sensors into Arduino projects.

Uploaded by

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

Lab 4 (1) Iot

This document provides information about various sensors that can be used with an Arduino board, including analogue and digital sensors. It describes sensors for sound, flame, smoke, humidity and temperature. Code examples are provided to interface sensors like a sound sensor, flame sensor, smoke sensor and humidity sensor with an Arduino and read sensor values. The document aims to help users learn about integrating different sensors into Arduino projects.

Uploaded by

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

Analogue and Digital Sensors Lab 3

Connecting Analogue and Digital Sensors with Arduino


Learn about Arduino and the Arduino UNO and how you can integrate this board into your makerspace and coding program. Make interactive makerspace projects while learning to code and problem solve.

Arduino Sensors
If you want your Arduino to sense the world around it, you will need to add a sensor. There are a wide
range of sensors to choose from and they each have a specific purpose. Below you will find some of the
commonly used sensors in projects.
 Distance Ranging Sensor
 PIR Motion Sensor
 Light Sensor
 Degree of Flex Sensor
 Pressure Sensor
 Proximity Sensor
 Sound Detecting Sensor
 RGB and Gesture Sensor
 Humidity and Temperature Sensor

Examples of Arduino Sensors

1.Sound sensor
Once you have uploaded the code to your Arduino board, if assembled correctly, a red LED should come on
from the sound sensor. When you clap or make a noise the LED should come on. If this does not work, you
can use a flat head screwdriver to adjust the sensitivity on top of the blue box on the sound sensor.Once this
is done and you clap or make noise, the LED should light up.

1
Analogue and Digital Sensors Lab 3
Circuit Diagram

1. Example 1
//Mic on off led
int led=13;
int buzz=12;
int soundpin=A5;
int threshold=200; // sets threshold for sound sensor
int i=0;
void setup() {
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(buzz,OUTPUT);
pinMode(soundpin,INPUT);
}
void loop() {

2
Analogue and Digital Sensors Lab 3
int soundsens=analogRead(soundpin); // read analog data from sensor
Serial.println(soundsens);
if (soundsens>=threshold) {
if(i==0){
digitalWrite(led, HIGH); // turn led on
digitalWrite(buzz, HIGH);
i=1;
delay(200);
}
else if(i==1){
digitalWrite(led, LOW);
digitalWrite(buzz, LOW);
i=0;
delay(200);
}}
}
2.Flame Sensor
Fire Alarm Systems are very common in commercial building and factories, these devices usual contain a
cluster of sensors that constantly monitors for any flame, gas or fire in the building and triggers an alarm if it
detects any of these. One of the simplest way to detect fire is by using an IR Flame sensor, these sensors
have an IR photodiode which is sensitive to IR light. Now, in the event of a fire, the fire will not only
produce heat but will also emit IR rays, yes every burning flame will emit some level of IR light, this light is
not visible to human eyes but our flame sensor can detect it and alert a microcontroller like Arduino that a
fire has been detected. 
A flame detector is a sensor designed to detect and respond to the presence of a flame or fire. Responses to a detected
flame depend on the installation but can include sounding an alarm, deactivating a fuel line (such as a propane or a
natural gas line), and activating a fire suppression system. The IR Flame sensor used in this project is shown below,
these sensors are also called Fire sensor module or flame detector sensor sometimes. 

Pin Configuration

Components Arduino pins


Buzzer 11
Led 13
D0 6

2. Example 2
int buzzer = 11;
3
Analogue and Digital Sensors Lab 3
int LED = 13;

int fire_sensor = 6;

int fire_detected;

void setup()

Serial.begin(9600);

pinMode(buzzer, OUTPUT);

pinMode(LED, OUTPUT);

pinMode(fire_sensor, INPUT);

void loop()

fire_detected = digitalRead(fire_sensor);

Serial.println(fire_detected);

if (fire_detected == 0) // Note: some sensor detect a fire to give zero value and others give
1 so check the data sheet.

Serial.println("fire detected...! take action immediately.");

digitalWrite(buzzer, HIGH);

digitalWrite(LED, HIGH);

delay(200);

digitalWrite(LED, LOW);

delay(200);

else

4
Analogue and Digital Sensors Lab 3
Serial.println("No fire detected. stay cool");

digitalWrite(buzzer, LOW);

digitalWrite(LED, LOW);

delay(1000);

3.Smoke sensor
In this example, you will read the sensor analog output voltage and when the smoke reaches a certain level,
it will make sound a buzzer and a red LED will turn on.
When the output voltage is below that level, a green LED will be on.
What is an MQ-2 Smoke Sensor?
The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:
 LPG
 Butane
 Propane
 Methane
 Alcohol
 Hydrogen
The resistance of the sensor is different depending on the type of the gas.
The smoke sensor has a built-in potentiometer that allows you to adjust the sensor sensitivity according to
how accurate you want to detect gas.

5
Analogue and Digital Sensors Lab 3

6
Analogue and Digital Sensors Lab 3
Circuit Diagram

3. Example 3

7
Analogue and Digital Sensors Lab 3

int redLed = 12;


int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 200;

void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");


Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}

4.Humidity sensor

8
Analogue and Digital Sensors Lab 3
We will see the circuit design of DHT11 interfacing with Arduino. The DHT11 Humidity and Temperature
sensor comes in two variants: just the sensor or a module.
The main difference is that the module consists of the pull – up resistor and may also include a power on
LED. We have used a module in this project and if you wish to use the sensor itself, you need to connect a
10K Ω pull – up resistor additionally.

What is a Pull-up Resistor


Let's say you have an MCU with one pin configured as an input. If there is nothing connected to the pin and
your program reads the state of the pin, will it be high (pulled to VCC) or low (pulled to ground)? It is
difficult to tell. This phenomena is referred to as floating. To prevent this unknown state, a pull-up or pull-
down resistor will ensure that the pin is in either a high or low state, while also using a low amount of
current.

With a pull-up resistor, the input pin will read a high state when the button is not pressed. In other words, a
small amount of current is flowing between VCC and the input pin (not to ground), thus the input pin reads
close to VCC. When the button is pressed, it connects the input pin directly to ground. The current flows
through the resistor to ground, thus the input pin reads a low state.
DHT11 Temperature and Humidity Sensor

9
Analogue and Digital Sensors Lab 3

Circuit Diagram

4. Example

10
Analogue and Digital Sensors Lab 3
// Example testing sketch for various DHT humidity/temperature sensors

#include "DHT.h"
#define DHTPIN 7 // what digital pin we're connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}

void loop() {
delay(2000); // Wait a few seconds between measurements
float h = dht.readHumidity();
// Reading temperature or humidity takes about 250 milliseconds!
float t = dht.readTemperature();
// Read temperature as Celsius (the default)
float f = dht.readTemperature(true);
// Read temperature as Fahrenheit (isFahrenheit = true)
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index in Fahrenheit (the default)


float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print ("Humidity: ");
11
Analogue and Digital Sensors Lab 3

Lab Tasks
1. Connect fire and flame sensor together and show the results on serial
monitor.
 // lowest and highest sensor readings:
 const int sensorMin = 0; // sensor minimum
 const int sensorMax = 1024; // sensor maximum

 void setup() {
 // initialize serial communication @ 9600 baud:
 Serial.begin(9600);
 }
 void loop() {
 // read the sensor on analog A0:
 int sensorReading = analogRead(A0);
 // map the sensor range (four options):
 // ex: 'long int map(long int, long int, long int, long int, long
int)'
 int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

 // range value:
 switch (range) {
 case 0: // A fire closer than 1.5 feet away.
 Serial.println("** Close Fire **");
 break;
 case 1: // A fire between 1-3 feet away.
 Serial.println("** Distant Fire **");
 break;
 case 2: // No fire detected.
 Serial.println("No Fire");
 break;
 }
 delay(1); // delay between reads
 }

12
Analogue and Digital Sensors Lab 3

Observations:

In this lab we learned to connect various sensors with ardunio for various

applications. Intially we started with the use of sound sensors by using analogue

input ,this sensor provided us output whenever the sound surpasses the threshod

volume .futhermore we used the flame sensor , that has IR photodiode which

helps detect a fire as IR rays are emitted from fire. We also learned to use smoke

sensor MQ-2. This kind of sensor detect smoke as well as various types of other

gases. Senstivity of smoke sensor can be adjusted using the potentiometer as this

sensitivity will allow to detect smoke/gases a different levels. At last we learned

to use a humidty sensor.

13

You might also like