0% found this document useful (0 votes)
17 views3 pages

Arduino CO2 Detector with Buzzer

Uploaded by

Rosedi Che Rose
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)
17 views3 pages

Arduino CO2 Detector with Buzzer

Uploaded by

Rosedi Che Rose
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

CO2 DETECTOR WITH BUZZER WARNING

HARDWARE SET UP

1. Arduino Uno:

 The microcontroller that reads the sensor data, drives the display, and controls the
buzzer.

2. MQ135 Sensor:

 VCC (Power): Connect to the 5V pin on the Arduino.


 GND: Connect to the GND pin on the Arduino.
 AO (Analog Output): Connect to the A0 analog input pin on the Arduino.

3. OLED 128x64 Display (SSD1306):

 VCC: Connect to the 5V pin on the Arduino.


 GND: Connect to the GND pin on the Arduino.
 SCL (Serial Clock): Connect to the A5 pin (SCL) on the Arduino.
 SDA (Serial Data): Connect to the A4 pin (SDA) on the Arduino.

4. Buzzer:

 Positive Pin (+): Connect to the Digital Pin 7 on the Arduino.


 Negative Pin (-): Connect to GND on the Arduino.

Summary of Connections:

 MQ135 Sensor:
o VCC → Arduino 5V
o GND → Arduino GND
o AO → Arduino A0
 OLED Display:
o VCC → Arduino 5V
o GND → Arduino GND
o SCL → Arduino A5
o SDA → Arduino A4
 Buzzer:
o Positive (+) → Arduino Digital Pin 7
o Negative (-) → Arduino GND
CODES

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Pin Definitions
#define MQ135_PIN A0 // MQ135 sensor connected to analog pin A0
#define BUZZER_PIN 7 // Buzzer connected to digital pin 7

// OLED display configuration


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire,
OLED_RESET);

// Calibration and CO2 threshold


#define CO2_THRESHOLD 1200 // CO2 level threshold for buzzer trigger
(set warning level value)
#define SENSOR_BASELINE 400 // Baseline CO2 level in closed area
(adjust as necessary)

void setup() {
pinMode(MQ135_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW); // Ensure the buzzer is off initially

// Initialize the OLED display


if (![Link](SSD1306_SWITCHCAPVCC, 0x3C)) {
[Link](F("SSD1306 allocation failed"));
for (;;);
}

[Link]();
[Link](2);
[Link](SSD1306_WHITE);
[Link](0, 20);
[Link](F(" Salam & Good day")); //greeting start up text
[Link]();

delay(2000); // Wait for 2 seconds before continuing

[Link]();
}

void loop() {
// Read the analog value from the MQ135 sensor
int sensorValue = analogRead(MQ135_PIN);

// Convert the analog value to a CO2 concentration in ppm


int co2PPM = map(sensorValue, 0, 1023, 0, 5000); // Adjust based on
calibration

// Display the CO2 level on the OLED


[Link]();
[Link](0, 20);
[Link](F("CO2 Level; "));
[Link](co2PPM);
[Link](F(" ppm"));
[Link]();

// Check if the CO2 level exceeds the threshold


if (co2PPM > CO2_THRESHOLD) {
digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer
} else {
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
}

delay(1000); // Update every second


}

You might also like