Created
February 6, 2025 16:32
-
-
Save sprites20/ac4cfd7d1071d9eeff5d4e274d10e485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
LiquidCrystal_I2C lcd(0x27, 16, 2); // Replace 0x27 with your I2C address | |
const int mq135Pin = A0; // MQ-135 sensor pin | |
const int buzzerPin = 8; // Buzzer connected to pin 8 | |
void setup() { | |
Serial.begin(9600); // Start serial communication | |
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output | |
lcd.init(); // Initialize LCD | |
lcd.backlight(); // Turn on backlight | |
lcd.setCursor(0, 0); // Move to first row, first column | |
lcd.print("CO2 Level"); // Print message | |
} | |
void loop() { | |
int sensorValue = analogRead(mq135Pin); // Read sensor value | |
Serial.print("MQ-135: "); | |
Serial.println(sensorValue * 2.5); | |
lcd.setCursor(0, 0); // Move to first row, first column | |
lcd.print("CO2 Level"); // Print message | |
lcd.setCursor(0, 1); // Move to second row | |
lcd.print(sensorValue * 2.5); | |
if (sensorValue * 2.5 >= 800) { | |
tone(buzzerPin, 1000); // Play 1 kHz tone | |
delay(500); // Wait 500ms | |
noTone(buzzerPin); // Stop buzzer | |
} | |
//lcd.clear(); | |
delay(100); // Wait for next reading | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment