Dawson CookReagan DavisPaul Adair
Published

MEGR 3171 IOT Project (Group 12)

Designing and construction of an air quality detector.

IntermediateFull instructions provided60
MEGR 3171 IOT Project (Group 12)

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×3
MQ-135 Harmful Gas Sensor
×1
MQ-2 Combustable Gas Sensor
×1

Software apps and online services

Particle Pi
Particle Pi
Adafruit IO

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long
Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

MQ135

MQ2

TempSensor

Code

Code For MQ2 Board

C/C++
This is the code for one of our sensors.
float ppm2 = 0; // Define ppm2 as a global variable
const float PPM_THRESHOLD = 1000; // Set your desired PPM threshold here

void triggerLEDAction(const char *event, const char *data) {
    digitalWrite(D7, HIGH); // Turn on the D7 LED
    delay(5000); // Keep the LED on for 5 seconds
    digitalWrite(D7, LOW); // Turn off the LED
}

void setup() {
    Particle.connect();
    Serial.begin(9600);
    pinMode(D7, OUTPUT);
    digitalWrite(D7, LOW);

    Particle.subscribe("thresholdExceeded", triggerLEDAction, MY_DEVICES);
}

void checkConditionAndPublish() {
    if (ppm2 > PPM_THRESHOLD) {
        Particle.publish("thresholdExceeded", "Threshold Exceeded", PRIVATE);
        delay(1000); // Delay to avoid rate limit
    }
}

void loop() {
    if (Particle.connected()) {
        int mq2Value = analogRead(A5);
        ppm2 = mq2Value; // Assign the sensor value to ppm2
        Serial.print("MQ2 PPM: ");
        Serial.println(ppm2);
        Particle.publish("MQ2_Dawson", String(ppm2), PRIVATE);

        checkConditionAndPublish(); // Check condition after getting sensor value

        delay(10000);
    }
}

MQ135 Code

C/C++
Code used on our second board. MQ135 Sensor
#include <MQ135.h>

const int LED_PIN = D7; // LED pin
const float PPM_THRESHOLD = 1000; // Set your desired PPM threshold for MQ135

MQ135 mq135_sensor(A0);

void triggerLEDAction(const char *event, const char *data) {
    digitalWrite(LED_PIN, HIGH); // Turn on the D7 LED
    delay(5000); // Keep the LED on for 5 seconds
    digitalWrite(LED_PIN, LOW); // Turn off the LED
}

void setup() {
    Particle.connect();
    Serial.begin(9600);
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);

    Particle.subscribe("thresholdExceeded", triggerLEDAction, MY_DEVICES);
}

void loop() {
    if (Particle.connected()) {
        float ppm135 = mq135_sensor.getPPM();
        Serial.print("MQ135 PPM: ");
        Serial.println(ppm135);
        Particle.publish("MQ135_Paul", String(ppm135), PRIVATE);

        // Check if the PPM exceeds the threshold and publish an event
        if (ppm135 > PPM_THRESHOLD) {
            Particle.publish("thresholdExceeded", PRIVATE);
            delay(1000); // Short delay to prevent exceeding rate limits
        }

        delay(10000); // Delay for 10 seconds before next read
    }
}

Temperature Code

C/C++
Code used for our last sensor, Analog Temperature Sensor.
const int TEMP_SENSOR_PIN = A5; // Assuming A5 is your temperature sensor pin
const int LED_PIN = D7; // LED pin
const float TEMP_THRESHOLD = 80; // Set your desired temperature threshold here

void setup() {
    Particle.subscribe("thresholdExceeded", triggerLEDAction, MY_DEVICES);
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW); // Turn off the LED
}

void loop() {
    int sensorValue = analogRead(TEMP_SENSOR_PIN);
    float temperature = sensorValue / 28.35;

    Particle.publish("Temperature", String(temperature), PRIVATE);
    delay(10000); // Delay for publishing temperature data

    // Check if the temperature exceeds the threshold and publish an event
    if (temperature > TEMP_THRESHOLD) {
        Particle.publish("thresholdExceeded", PRIVATE);
        delay(1000); // Short delay to prevent exceeding rate limits
    }
}

void triggerLEDAction(const char *event, const char *data) {
    digitalWrite(LED_PIN, HIGH); // Turn on the LED
    delay(5000); // Keep the LED on for 5 seconds
    digitalWrite(LED_PIN, LOW); // Turn off the LED
}

Credits

Dawson Cook
1 project • 1 follower
Contact
Reagan Davis
1 project • 1 follower
Mechanical Engineering Major @ UNC Charlotte
Contact
Paul Adair
1 project • 2 followers
Contact

Comments

Please log in or sign up to comment.