Want to create interactive content? It’s easy in Genially!

Get started free

PREVENT IoT Practical Session (UCLan)

citizensinpower

Created on January 20, 2025

Start designing with a free template

Discover more than 1500 professional designs like these:

Transcript

Chapters Template - PREVENT Project

IoT Practical Session

Start

Index

Objectives
Fire Detection
Flood Detection
Earthquake Detection

Objectives

  • The main goal of this practical session is to offer a "hands-on" experience on IoT and how this technology can be used to solve problems related to natural disasters.
  • The session includes 3 practical experiments:
    • Integration and Testing of MQ2 Sensor for Fire Detection
    • Integration and Testing of Water Sensor for Flood Detection
    • Integration and Testing of MPU6050 Sensor for Earthquake Detection
Have Fun!!!

01

Integration and Testing of MQ2 Sensor for Fire Detection

Objective

The goal of this experiment is to integrate the MQ2 gas sensor with an Arduino Uno microcontroller and display real-time sensor data on an LCD screen. The MQ2 sensor will detect smoke, propane, and other gases that can indicate the presence of fire, and this data will be used to assess the potential fire hazard.

Background Information

  • MQ2 Sensor: The MQ2 sensor is capable of detecting various gases, including smoke, methane, propane, and carbon monoxide. It works by measuring the concentration of gases in the air and outputting an analog voltage that corresponds to the gas concentration.
  • Applications:
  • o Gas Leak Detection – Used in homes, kitchens, and industrial settings to detect LPG, methane, and propane leaks.
    • Smoke Detection – Can be integrated into fire alarm systems to detect smoke and flammable gases.
    • o Indoor Air Quality Monitoring – Helps in measuring air pollution levels by detecting hazardous gases like CO.
    • Breathalyzer Devices – Used to detect alcohol levels in breath tests.
    • Smart Home Automation – Can trigger ventilation systems or alarms in case of high gas concentrations.
    • Industrial Safety – Deployed in factories and chemical plants to detect gas leaks and prevent explosions.
    • Automotive Applications – Used in vehicles to detect fuel leaks or exhaust gas levels.
    • IoT & Smart Cities – Integrated with IoT devices to monitor environmental pollution levels in urban areas.
  • Arduino Uno: The Arduino Uno is a popular microcontroller board that will be used to interface with the MQ2 sensor and an LCD display. It will process the sensor data and control the LCD to show real-time information.
  • LCD Screen: The LCD screen will be used to display real-time readings from the MQ2 sensor, indicating whether there is a potential fire risk based on the presence of gases.

Safety Precautions

  • Since this experiment involves detecting gases (potentially flammable), include a brief note on ensuring proper ventilation when testing the sensor with gases or smoke. Remind students to always work in a safe environment.

Equipment Needed

  • Hardware:
    • Arduino Uno board
    • MQ2 gas sensor
    • 16x2 LCD screen (I2C or parallel connection)
    • Jumper wires
    • Breadboard (optional)
    • Power supply for Arduino
  • Software:
    • Arduino IDE (for programming the microcontroller)
  • Library Dependencies
    • LiquidCrystal_I2C
    • Wire

Arduino IDE Installation

  • Install the library dependencies according to the project as shown below:
  • Download Arduino IDE for your platform:
    • Windows
    • MacOS - Apple Silicon/Intel
    • Linux
  • Follow the installation instructions and open the application
  • Connect the Arduino UNO board to any of the USB ports on the PC
  • Select the board from the list as shown below:
  • Paste the code for each project found in the GitHub Repository
  • G. Upload the sketch to the Arduino UNO by selecting the button

Circuit Diagram

  • Connections for MQ2 sensor:
    • VCC of MQ2 to 5V on the Arduino
    • GND of MQ2 to GND on Arduino
    • Analog output (A0) of MQ2 to an analog pin on the Arduino (e.g., A0)
  • Connections for LCD Screen:
    • VCC of LCD to 5V on Arduino
    • GND of LCD to GND on Arduino
    • SDA to A4 (on Arduino Uno) for I2C communication
    • SCL to A5 (on Arduino Uno) for I2C communication
  • Connect the MQ2 sensor to the Arduino Uno as shown in the circuit diagram.
  • Connect the LCD screen to the Arduino Uno via I2C or parallel connection as per the specifications.

Programming the Arduino

  • Open Arduino IDE and write the code to initialize the MQ2 sensor and LCD.
  • Include necessary libraries such as LiquidCrystal_I2C (for LCD) and other sensor-related libraries if applicable.
  • Write the program to read data from the MQ2 sensor and display the values on the LCD.
  • Implement logic to assess whether the sensor reading indicates the presence of gas levels related to a potential fire.

void loop() { sum = readMQ2(); for(int i = 0; i < repetitions; i++) { sum += readMQ2(); } avg = sum / repetitions; lcd.clear(); lcd.print("Value: "); lcd.print(String(avg)); lcd.setCursor(0, 1); Serial.print("Value: "); if (avg > 100) { lcd.print("Smoke/Gas Found!"); Serial.println("Smoke/Gas Found!"); } else { lcd.print("No Smoke/Gas"); Serial.println("No Smoke/Gas found"); } delay(300); } // Function to retrieve the Analog MQ2 Reading int readMQ2() { unsigned int sensorValue = analogRead(MQ2_AO); // Map the resolution of the sensor from 10bit to 8bit for quicker detection unsigned int outputValue = map(sensorValue, 0, 1023, 0, 255); return outputValue; }

Sample Code

#include <LiquidCrystal_I2C.h> #include <Wire.h> #define LCD_ADD 0x27 // I2C Address of LCD Display #define LCD_COLS 16 // Number of columns of LCD Display #define LCD_ROWS 2 // Number of rows of LCD Display // Pin Definition #define MQ2_AO A0 // Variable Declaration int sum = 0; int avg = 0; int repetitions = 100; LiquidCrystal_I2C lcd(LCD_ADD, LCD_COLS, LCD_ROWS); void setup() { Serial.begin(115200); // Initialize LCD and turn on Backlight LED lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Smoke/Gas"); lcd.setCursor(0, 1); lcd.print("Detector."); Serial.println("Smoke/Gas Detector."); delay(1000); }

Testing and Calibration

  • Upload the code to the Arduino and open the serial monitor (on Mac and/or Windows) to verify sensor readings.
  • Test the sensor by exposing it to various levels of smoke or gases (safely) and observe the LCD display.
  • Adjust the threshold value in the code to define the gas concentration level at which a potential fire is detected.

Observations

  • Record the sensor readings at different gas concentrations.
  • Observe the LCD display to check if the system correctly identifies the presence of gases related to fire.

Results and Analysis

  • Expected Results: The LCD screen should display the gas level readings in real-time. When the gas concentration exceeds a certain threshold, the message “Potential Fire!” should appear on the LCD.
  • Analysis: Compare the sensor data with expected thresholds for smoke or fire detection. Discuss how the MQ2 sensor can be used in real-world fire detection systems.

Discussion

  • Discuss the effectiveness of the MQ2 sensor in detecting the presence of smoke or other gases associated with fire.
  • Evaluate the overall performance of the integration between the Arduino, MQ2 sensor, and LCD screen.

Critical Thinking Questions

  • How can you modify the circuit to detect other gases?
  • What other sensors could you use to improve the accuracy of fire detection?
  • What factors could cause false positives or negatives in the fire detection system?
  • How would you improve the reliability of the fire detection system in a real-world application?
  • Suggest how the system could be further enhanced.

02

Integration and Testing of Water Sensor for Flood Detection

Objective

The goal of this experiment is to integrate the Grove - precipitation / water sensor with an Arduino Uno microcontroller and display real-time sensor data on an LCD screen. The sensor will detect the presence of precipitation as well as water level, and this data will be used to assess the potential flood hazard.

Background Information

  • Precipitation / water Sensor: The Grove - Water Sensor is a simple yet effective sensor used to detect water presence, moisture levels, and even precipitation. It belongs to Seeed Studio's Grove ecosystem, which makes it easy to connect to microcontrollers like Arduino and Raspberry Pi without needing soldering or complex wiring. The Grove - precipitation / water sensor can produce voltage values for water level. For detecting floods, the resistance of the exposed copper elements changes, thus producing analog voltage values that can be used to detect the water level. Each trace has a weak 1MΩ resistance. When the sensor is submerged in water, the voltage reading from the Signal pin decreases..
  • Applications:
    • Rain & Precipitation Detection – Used in weather stations to detect rainfall and trigger alerts.
    • Leak Detection – Installed near pipes, appliances, or basements to detect water leaks and prevent damage.
    • Soil Moisture Monitoring – Helps in smart agriculture by detecting soil dryness and automating irrigation.
    • Water Level Detection – Used in tanks or reservoirs to monitor water levels.
    • Home Automation & IoT – Can be integrated with smart home systems to alert users of water leaks or flooding.
    • Industrial Applications – Helps in monitoring humidity or detecting water presence in critical environments.
  • Arduino Uno: The Arduino Uno is a popular microcontroller board that will be used to interface with the sensor and an LCD display. It will process the sensor data and control the LCD to show real-time information.
  • LCD Screen: The LCD screen will be used to display real-time readings from the sensor, indicating whether there is a potential flooding risk based on the presence of high water levels.

Safety Precautions

  • Since this experiment involves detecting precipitation and water, include a brief note on ensuring proper care when testing the sensor to avoid spilling. Remind students to always work in a safe environment.

Equipment Needed

  • Hardware:
    • Arduino Uno board
    • Water sensor
    • 16x2 LCD screen (I2C or parallel connection)
    • Jumper wires
    • Breadboard (optional)
    • Power supply for Arduino
  • Software:
    • Arduino IDE (for programming the microcontroller)
  • Library Dependencies
    • LiquidCrystal_I2C
    • Wire

Arduino IDE Installation

  • Install the library dependencies according to the project as shown below:
  • Download Arduino IDE for your platform:
    • Windows
    • MacOS - Apple Silicon/Intel
    • Linux
  • Follow the installation instructions and open the application
  • Connect the Arduino UNO board to any of the USB ports on the PC
  • Select the board from the list as shown below:
  • Paste the code for each project found in the GitHub Repository
  • G. Upload the sketch to the Arduino UNO by selecting the button

Circuit Diagram

  • Connections for MQ2 sensor:
    • VCC of Sensor to 5V on the Arduino
    • GND of Sensor to GND on Arduino
    • Analog output (A0) of Sensor to an analog pin on the Arduino (e.g., A0)
  • Connections for LCD Screen:
    • VCC of LCD to 5V on Arduino
    • GND of LCD to GND on Arduino
    • SDA to A4 (on Arduino Uno) for I2C communication
    • SCL to A5 (on Arduino Uno) for I2C communication
  • Connect the sensor to the Arduino Uno as shown in the circuit diagram.
  • Connect the LCD screen to the Arduino Uno via I2C or parallel connection as per the specifications.

Programming the Arduino

  • Open Arduino IDE and write the code to initialize the sensor and LCD.
  • Include necessary libraries such as LiquidCrystal_I2C (for LCD) and other sensor-related libraries if applicable.
  • Write the program to read data from the sensor and display the values on the LCD.
  • Implement logic to assess whether the sensor reading indicates the presence of water levels related to a potential flooding.

void loop() { // read the input pin val = analogRead(WATER_SENSOR); // Serial.println(val); if (val < 150) intensity = "High"; else if (val >= 150 && val <= 160) intensity = "Moderate"; else if (val > 160 && val <= 250) intensity = "Low"; else intensity = "None"; lcd.clear(); lcd.print("Water Level:"); lcd.setCursor(0,1); lcd.print(intensity); Serial.print("Water Level: "); Serial.println(intensity); Serial.print("Value: "); Serial.println(val); delay(500); }

Sample Code

#include <LiquidCrystal_I2C.h> #include <Wire.h> #define WATER_SENSOR A0 #define LCD_ADD 0x27 // I2C Address of LCD Display #define LCD_COLS 16 // Number of columns of LCD Display #define LCD_ROWS 2 // Number of rows of LCD Display LiquidCrystal_I2C lcd(LCD_ADD, LCD_COLS, LCD_ROWS); int val = 0; String intensity; void setup() { Serial.begin(115200); // Initialize LCD and turn on Backlight LED lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Flood Detector."); lcd.setCursor(0, 1); Serial.println("Flood Detector."); }

Testing and Calibration

  • Upload the code to the Arduino and open the serial monitor (on Mac and/or Windows) to verify sensor readings.
  • Test the sensor by exposing it to various levels of water level and observe the LCD display.
  • Adjust the threshold value in the code to define the water level at which a potential flood is detected.

Observations

  • Record the sensor readings at different gas concentrations.
  • Observe the LCD display to check if the system correctly identifies the level of water related to flood.

Results and Analysis

  • Expected Results: The LCD screen should display the water level readings in real-time. When the water level exceeds a certain threshold, the message “Water Level High” should appear on the LCD.
  • Analysis: Compare the sensor data with expected thresholds for flood detection. Discuss how the water sensor can be used in real-world flood detection systems.

Discussion

  • Discuss the effectiveness of the water sensor in detecting the presence of water, moisture levels, and even precipitation associated with potential flooding.
  • Evaluate the overall performance of the integration between the Arduino, water sensor, and LCD screen.

Critical Thinking Questions

  • What other sensors could you use to improve the accuracy of flood detection?
  • What factors could cause false positives or negatives in the flood detection system?
  • How would you improve the reliability of the flood detection system in a real-world application?
  • Suggest how the system could be further enhanced.

03

Integration and Testing of MPU6050 Sensor for Earthquake Detection

Objective

The goal of this experiment is to integrate the mpu6050 sensor with an Arduino Uno microcontroller and display real-time sensor data on an LCD screen. The MPU6050 Inertial Measurement Unit can produce values for acceleration and gyroscope. For detecting earthquakes, the Z axis acceleration, given that the MPU6050 is fixed right-side-up on a level surface, is converted from [m/s2] to [g] by dividing the acceleration value with the earth’s gravitational force (~9.81 m/s2). This g value is then categorized according to the Modified Mercalli scale, and this data will be used to assess the potential earthquake hazard.

Background Information

  • MPU6050 Sensor: The MPU6050 is a 6-axis motion tracking sensor that combines, 3-axis gyroscope (measuring angular velocity) and 3-axis accelerometer (measuring acceleration). It is widely used in motion tracking, orientation sensing, and gesture recognition. It also includes an embedded Digital Motion Processor (DMP), which can process sensor data before sending it to a microcontroller, reducing computational load.
  • Applications:
    • Motion Tracking & Gesture Control – Used in gaming controllers, robotics, and human motion capture systems.
    • Drone & UAV Stabilization – Helps in keeping drones stable by tracking their orientation.
    • Robotics & Self-Balancing Systems – Essential for robotic applications like self-balancing robots and robotic arms.
    • Wearable Devices & Fitness Trackers – Used in step counting, activity recognition, and fitness monitoring.
    • Virtual Reality (VR) & Augmented Reality (AR) – Helps in head tracking for immersive experiences.
    • Smartphones & Tablets – Used for auto screen rotation, shake detection, and gaming controls.
    • Automotive Applications – Helps in vehicle stability control, crash detection, and motion sensing.
    • Industrial Equipment Monitoring – Used in predictive maintenance and vibration analysis..
  • Arduino Uno: The Arduino Uno is a popular microcontroller board that will be used to interface with the mpu6050 sensor and an LCD display. It will process the sensor data and control the LCD to show real-time information.
  • LCD Screen: The LCD screen will be used to display real-time readings from the mpu6050 sensor, indicating whether there is a potential Earthquake risk based on the presence of vibration and g-forces.

Safety Precautions

  • Since this experiment involves detecting vibration and g-forces, include a brief note on ensuring proper handling when testing the sensor. Remind students to always work in a safe environment.

Equipment Needed

  • Hardware:
    • Arduino Uno board
    • MPU6050 sensor
    • 16x2 LCD screen (I2C or parallel connection)
    • Jumper wires
    • Breadboard (optional)
    • Power supply for Arduino
  • Software:
    • Arduino IDE (for programming the microcontroller)
  • Library Dependencies
    • Adafruit MPU6050
    • Adafruit Sensor
    • LiquidCrystal_I2C
    • Wire

Arduino IDE Installation

  • Install the library dependencies according to the project as shown below:
  • Download Arduino IDE for your platform:
    • Windows
    • MacOS - Apple Silicon/Intel
    • Linux
  • Follow the installation instructions and open the application
  • Connect the Arduino UNO board to any of the USB ports on the PC
  • Select the board from the list as shown below:
  • Paste the code for each project found in the GitHub Repository
  • G. Upload the sketch to the Arduino UNO by selecting the button

Circuit Diagram

  • Connections for MQ2 sensor:
    • VCC of mpu6050 to 3.3V on the Arduino
    • GND of mpu6050 to GND on Arduino
    • SCL of mpu6050 to SCL on Arduino
    • SDA of mpu6050 to SDA on Arduino
  • Connections for LCD Screen:
    • VCC of LCD to 5V on Arduino
    • GND of LCD to GND on Arduino
    • SDA to A4 (on Arduino Uno) for I2C communication
    • SCL to A5 (on Arduino Uno) for I2C communication
  • Connect the mpu6050 sensor to the Arduino Uno as shown in the circuit diagram.
  • Connect the LCD screen to the Arduino Uno via I2C or parallel connection as per the specifications.

Programming the Arduino

  • Open Arduino IDE and write the code to initialize the mpu6050 sensor and LCD.
  • Include necessary libraries such as LiquidCrystal_I2C (for LCD) and other sensor-related libraries if applicable.
  • Write the program to read data from the mpu6050 sensor and display the values on the LCD.
  • Implement logic to assess whether the sensor reading indicates the presence of vibration levels related to a potential earthquake.
Sample Code

void loop() { sumAccel = 0.0; // Average Accelerometer Z axis for 300 readings and convert them from m/s^2 to g // to reduce sensor error for(int i = 0; i < 300; i++) { mpu.getAccelerometerSensor()->getEvent(&event); sumAccel = abs(event.acceleration.z / 9.81); } avgAccel = sumAccel / 300; // Calculate the difference of the previous and current reading to determine shifts in g value diff = abs(avgAccel - prevAccel); // Identify the category of the earthqake by comparing the difference of the readings if (diff >= 0.0276 && diff <= 0.115) intensity = "Category V"; else if (diff > 0.115 && diff <= 0.215) intensity = "Category VI"; else if (diff > 0.215 && diff <= 0.401) intensity = "Category VII"; else if (diff > 0.401 && diff <= 0.747) intensity = "Category VIII"; else if (diff > 0.747 && diff <= 1.39) intensity = "Category IX"; else if (diff > 1.39) intensity = "Category X"; else intensity = "None"; lcd.clear(); lcd.print(diff); lcd.print(" g"); lcd.setCursor(0, 1); lcd.print(intensity); // Assign the current reading to the previous to repeat the comparison prevAccel = avgAccel; delay(50); }

#include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <LiquidCrystal_I2C.h> #include <Wire.h> #define LCD_ADD 0x27 // I2C Address of LCD Display #define LCD_COLS 16 // Number of columns of LCD Display #define LCD_ROWS 2 // Number of rows of LCD Display // Peripheral Definition Adafruit_MPU6050 mpu; LiquidCrystal_I2C lcd(LCD_ADD, LCD_COLS, LCD_ROWS); // Variables Declaration float sumAccel = 0.0; float avgAccel; float prevAccel = 0.0; float diff = 0.0; String intensity; void setup(void) { Serial.begin(115200); // Initialize LCD and turn on Backlight LED lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Quake Detector."); lcd.setCursor(0, 1); // Check MPU6050 Connectivity while (!mpu.begin()) { Serial.println("MPU6050 not connected!"); delay(1000); } lcd.print("MPU6050 ready."); delay(1000); } sensors_event_t event;

Testing and Calibration

  • Upload the code to the Arduino and open the serial monitor (on Mac and/or Windows) to verify sensor readings.
  • Test the sensor by exposing it to various levels of vibration and observe the LCD display.

Observations

  • Record the sensor readings at different gas concentrations.
  • Observe the LCD display to check if the system correctly identifies the presence of vibration related to earthquake.

Results and Analysis

  • Expected Results: The LCD screen should display the vibration level readings in real-time. When the vibration g-force exceeds a certain threshold, the message “Category V” should appear on the LCD.
  • Analysis: Compare the sensor data with expected thresholds for earthquake detection. Discuss how the mpu6050 sensor can be used in real-world fire detection systems.

Discussion

  • Discuss the effectiveness of the mpu6050 sensor in detecting the presence of vibration and g-forces associated with earthquake.
  • Evaluate the overall performance of the integration between the Arduino, mpu6050 sensor, and LCD screen.

Critical Thinking Questions

  • How can you modify the circuit to detect additional data such as azimuth?
  • What other sensors could you use to improve the accuracy of earthquake detection?
  • What factors could cause false positives or negatives in the earthquake detection system?
  • How would you improve the reliability of the earthquake detection system in a real-world application?
  • Suggest how the system could be further enhanced.