Practical 10

Multi-Sensor Environmental Monitoring System

Temperature, light and air quality in one unit

Aim

To combine several sensors (temperature, light and gas/air quality) into a single system that collects, displays and evaluates the environment continuously.

Overview

Three analog sensor modules feed three ADC channels of the Arduino: an NTC temperature sensor, an LDR light sensor and an MQ-series gas sensor. The Arduino samples all channels, converts them into engineering units (Celsius, lux, gas level), shows them on a 16x2 LCD cycling between screens, and raises an alarm (red LED + buzzer) when any value crosses its safety threshold.

Components Required

  • Arduino Uno
  • NTC temperature sensor module
  • LDR / photoresistor sensor module
  • MQ-2 gas / smoke sensor module
  • 16x2 LCD (I2C backpack recommended)
  • Red LED (alarm), buzzer
  • Breadboard and jumper wires

Circuit Connections

FromToNote
Temp sensor AOArduino A0-
LDR sensor AOArduino A1-
Gas sensor AOArduino A2-
All sensor VCC / GNDArduino 5V / GND-
I2C LCD SDA / SCLArduino A4 / A5-
Red LED (via 220R)Arduino D8-
Buzzer +Arduino D9-

Interactive Circuit Diagram

Simulate the circuit: adjust the sensor inputs below and watch the outputs react according to the control logic.

Loading Wokwi components...

Working

  1. All three analog channels are sampled and averaged in one loop pass.
  2. Readings are converted: ADC to Celsius for the NTC, ADC to approximate lux for the LDR, ADC to gas level for the MQ sensor.
  3. The LCD alternates every 2.5 seconds between the T/H-style environmental screen and the light/air screen.
  4. If temperature > 45 C, gas > threshold or light is abnormal for the use case, the alarm LED and buzzer activate.
  5. Alarm state clears automatically once all readings return to normal.

Control Logic

ALARM = (T > T_MAX) OR (gas > GAS_MAX). Each sensor is validated independently so a single faulty channel does not mask the others. Multi-sensor fusion here is a simple OR of per-sensor violations - the same pattern scales up to more complex systems.

Arduino Code

1// Practical 10: Multi-Sensor Environmental Monitoring System
2#include <LiquidCrystal_I2C.h>
3
4LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16x2
5
6const int TEMP_PIN = A0;
7const int LDR_PIN = A1;
8const int GAS_PIN = A2;
9const int ALARM_LED = 8;
10const int BUZZER = 9;
11
12const float TEMP_MAX = 45.0; // Alarm thresholds
13const int GAS_MAX = 300; // ADC counts from the MQ-2
14
15int readAverage(int pin) {
16 long sum = 0;
17 for (int i = 0; i < 10; i++) {
18 sum += analogRead(pin);
19 delay(2);
20 }
21 return sum / 10;
22}
23
24void setup() {
25 lcd.init();
26 lcd.backlight();
27 pinMode(ALARM_LED, OUTPUT);
28 pinMode(BUZZER, OUTPUT);
29 Serial.begin(9600);
30}
31
32void loop() {
33 int tADC = readAverage(TEMP_PIN);
34 int lADC = readAverage(LDR_PIN);
35 int gADC = readAverage(GAS_PIN);
36
37 float tempC = tADC * 5.0 / 1023.0 * 100.0; // LM35-style conversion
38 long lux = map(lADC, 60, 950, 1, 1000); // Calibrated mapping
39 lux = constrain(lux, 1, 1000);
40
41 // Screen 1: temperature + light
42 lcd.clear();
43 lcd.setCursor(0, 0);
44 lcd.print("Temp: ");
45 lcd.print(tempC, 1);
46 lcd.print("C");
47 lcd.setCursor(0, 1);
48 lcd.print("Light: ");
49 lcd.print(lux);
50 lcd.print(" lx");
51 delay(2500);
52
53 // Screen 2: air quality + alarm state
54 bool alarm = (tempC > TEMP_MAX) || (gADC > GAS_MAX);
55 lcd.clear();
56 lcd.setCursor(0, 0);
57 lcd.print("Gas level: ");
58 lcd.print(gADC);
59 lcd.setCursor(0, 1);
60 lcd.print(alarm ? "ALERT! Check env" : "Environment OK");
61 delay(2500);
62
63 digitalWrite(ALARM_LED, alarm ? HIGH : LOW);
64 digitalWrite(BUZZER, alarm ? HIGH : LOW);
65
66 Serial.print("T:");
67 Serial.print(tempC);
68 Serial.print(" L:");
69 Serial.print(lux);
70 Serial.print(" G:");
71 Serial.println(gADC);
72}