Multiple Sensors with Arduino

How to use multiple sensors with Arduino and LCD

Watch this detailed tutorial on “How to use multiple sensors with Arduino” first:

Components required to use Multiple sensors with Arduino:

  1. PIR SENSOR

A latent infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light transmitting from objects in its field of view. They are widely utilized in PIR-based movement locators. PIR sensors are normally utilized in security cautions and programmed lighting applications.

PIR MOTION SENSOR
PIR MOTION SENSOR

 

2. GAS SENSOR & LDR

Gas sensors (also known as gas detectors) are electronic devices that distinguish and recognize various sorts of gasses. They can identify poisonous or unstable gases and measure gas. Therefore,Gas sensors are utilized in industrial facilities and assembling offices to recognize gas spills, and to identify smoke and carbon monoxide in homes.

Photograph resistors, also known as light ward resistors (LDR) are sensitive to light. These light delicate sensors frequently detect the presence or absence of light and measure the intensity of light

GAS SENSOR
 GAS SENSOR

 

3. ULTRASONIC SENSOR

A ultrasonic sensor is an electronic gadget that measures the distance of an object by emitting ultrasonic sound waves, and converts the reflected sound into an electrical sign. Ultrasonic waves travel quicker than the speed of audible sound (for example the sound that humans can hear). Therefore, the performance of this device is really fast.

ULTRASONIC SENSOR
ULTRASONIC SENSOR

 

4. IR SENSOR

An infrared (IR) sensor is an electronic device that measures and recognizes infrared radiation around it. There are two kinds of infrared sensors: Active and Passive. Active infrared sensors both generate and detect infrared radiation. On the other hand, Passive infrared (PIR) sensors just detect infrared radiation and don’t emit it from a LED.

IR SENSOR
IR SENSOR

 

5. DHT11 HUMIDITY & TEMPERATURE SENSOR

A Humidity sensor (or hygrometer) detects, measures and reports both moisture and air temperature.

DHT11 HUMIDITY AND TEMPERATURE SENSOR
DHT11 HUMIDITY AND TEMPERATURE SENSOR

 

6. 16X2 LCD DISPLAY

A 16×2 LCD show is a basic module which generally finds its application in different devices and circuits. A 16×2 LCD implies that it can show 16 characters for each line and there are 2 such lines. Also, In 16×2 LCD each character is shown in 5×7 pixel network.

16X2 LCD DISPLAY
16X2 LCD DISPLAY

 

7.  LED X 5

LED
LEDs

 

8. 220-ohm Resistors X 5

 

CIRCUIT DIAGRAM for using Multiple sensors with Arduino:

Circuit Diagram: Multiple Sensors with Arduino
Circuit Diagram: Multiple Sensors with Arduino

 

PROGRAM for using Multiple sensors with Arduino:

/*
 *  multiple_Sensors_With_Arduino
 *  
 *  Created on: May 27, 2020
 *      Author:youtube.com/theelectronicguy      
 */


#include <SimpleDHT.h>//DHT11 library(Search : simpledht in Library Manager)
#include <LiquidCrystal.h>//LCD library
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);//lcd(RS,En,D4,D5,D6,D7)

#define PIR_SENSOR      A0//pir sensor(pins:1)
/*
   Uncomment when using GAS Sensor
*/
//#define GAS_SENSOR      A1
/*
   Uncomment when using LDR Sensor
*/
#define LDR_SENSOR      A1
//ultrasonic sensor(pins:2)
#define ULT_TRIG        A2
#define ULT_ECHO        A3
#define IR_SENSOR       A4//Ir sensor(pins:1)
#define HT_SENSOR       A5//humidity and temperature sensor(pins:1)

//leds(pins:5)
#define HT_LED          8
#define IR_LED          9
#define ULT_LED         10
#define BUZZER          11// for ultrasonic sensor
//#define GAS_LED       12
#define LDR_LED         12
#define PIR_LED         13

// create a dht11 object
SimpleDHT11 dht11(HT_SENSOR);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  // set sensor pins as inputs
  for (int i = PIR_SENSOR; i <= HT_SENSOR; i++)
    pinMode(i, INPUT);
  //set trigger pin as output
  pinMode(ULT_TRIG, OUTPUT);
  // set led pins as output
  for (int i = HT_LED; i <= PIR_LED; i++)
    pinMode(i, OUTPUT);

  // print sensor name on the LCD
  lcd.setCursor(0, 0);
  lcd.print("IS=  ");//IR Sensor data will be displayed at (3,0)
  lcd.print("US=   ");//Ultrasonic Sensor data will be displayed at(8,0)
  //lcd.print("GS=   ");//Gas Sensor data will be displayed at(14,0)
  lcd.print("LDR=  ");//LDR Sensor data will be displayed at(15,0)
  lcd.setCursor(0, 1);// Move cursor to the next line of LCD
  lcd.print("PS=  ");//PIR Sensor data will be displayed at(3,1)
  lcd.print("HS=   ,   ");//Humidity & temperature Sensor data will be displayed at(8,1) &(12,1) respectivel
}

void loop() {
  /*
     read continously from each sensor
  */
  //print digital values from Ir Sensor
  ir_Readings();
  //distance measurement using Ultrasonic Sensor
  us_Readings();
  //read values from gas sensor
  //gas_Readings();
  //read values from LDR sensor
  LDR_Readings();
  //read analog values from pir sensor
  pir_Readings();
  // read temp and humidity from ht sensor
  ht_Readings();
}

void ir_Readings() {
  int x = digitalRead(IR_SENSOR);
  lcd.setCursor(3, 0);
  lcd.print(!x);
  Serial.print("IR=");
  Serial.print(!x);
  Serial.print("\t");
  //IR Sensor input condition for Led to glow
  if (x == 0) {
    digitalWrite(IR_LED, HIGH);
  }
  else {
    digitalWrite(IR_LED, LOW);
  }

}

void us_Readings() {
  long  duration;
  int distance;
  duration = time_Measurement(duration);
  distance = (int)duration * (0.0343) / 2;

  if (distance > 99 || distance < 0)//If distance is negative or greater than 99, then always show distance =0
    distance = 0;

  display_distance(distance);
}

//uncomment when using GAS Sensor
/*void gas_Readings() {
  int x = analogRead(GAS_SENSOR);
  lcd.setCursor(14, 0);
  lcd.print(x);
  Serial.print("GS=");
  Serial.print(x);
  Serial.print("\t");

   //Gas Sensor input condition for Led to glow
  if (x >= 60)
    digitalWrite(9, HIGH);
  else
    digitalWrite(9, LOW);
  }*/

//uncomment when using LDR Sensor
void LDR_Readings() {
  int x = digitalRead(LDR_SENSOR);
  lcd.setCursor(15, 0);
  lcd.print(x);
  Serial.print("LDR=");
  Serial.print(x);
  Serial.print("\t");

  //LDR Sensor input condition for Led to glow
  if (x == 1) {
    digitalWrite(LDR_LED, HIGH);
  }
  else {
    digitalWrite(LDR_LED, LOW);
  }
}

void pir_Readings() {
  int x = digitalRead(PIR_SENSOR);
  lcd.setCursor(3, 1);
  lcd.print(x);
  Serial.print("PS=");
  Serial.print(x);
  Serial.print("\t");

  ////PIR Sensor input condition for Led to glow
  if (x == 1) {
    digitalWrite(PIR_LED, HIGH);
  }
  else {
    digitalWrite(PIR_LED, LOW);
  }
}

void ht_Readings() {
  byte temperature = 0;
  byte humidity = 0;

  dht11.read(&temperature, &humidity, NULL);// <simpledht> library function to read temperature and humidity

  lcd.setCursor(8, 1);
  lcd.print((int)temperature);
  lcd.print("*");//temperature in degree
  lcd.setCursor(12, 1);
  lcd.print((int)humidity);
  lcd.print("%");
  Serial.print("HT=");
  Serial.print(temperature);
  Serial.print("*C,");
  Serial.print(humidity);
  Serial.print("%");
  Serial.println();

  //Temperature and humidity conditions for Led to glow
  if (temperature > 38 || humidity > 37)
    digitalWrite(HT_LED, HIGH);
  else
    digitalWrite(HT_LED, LOW);

  delay(500);

}


int time_Measurement(int duration)
{

  digitalWrite(ULT_TRIG, LOW);
  delayMicroseconds(2);

  digitalWrite(ULT_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(ULT_TRIG, LOW);

  duration = pulseIn(ULT_ECHO, HIGH);
  return duration;
}

void display_distance(int distance)
{
  lcd.setCursor(8, 0);
  if (distance < 10) {
    lcd.print(0);
  }
  lcd.print(distance);
  Serial.print("US=");
  Serial.print(distance);
  Serial.print("\t");

  //distance condition for Led to glow
  if (1 <= distance && distance <= 10) {
    digitalWrite(ULT_LED, HIGH);
    tone(BUZZER, 2000);
  }
  else {
    digitalWrite(ULT_LED, LOW);
    noTone(BUZZER);
  }

  delay(10);
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *