#include <MQ135.h>
#include <Wire.h>
#include <Arduino.h>
// Definisikan pin-pinning yang digunakan
#define LED_HIJAU_PIN 23
#define LED_KUNING_PIN 22
#define LED_MERAH_PIN 21
#define BUZZER_PIN 19
#define PPM_PIN 4
void setup() {
// Set up pin sebagai output
pinMode(LED_HIJAU_PIN, OUTPUT);
pinMode(LED_KUNING_PIN, OUTPUT);
pinMode(LED_MERAH_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(115200);
}
void loop() {
// Value after from AD convertor
int16_t ppmValue = analogRead(PPM_PIN);
// Map the correct value ad AD convertor expects max votage to be 3.3 V and we are sending 5 V
int CO2 = (ppmValue/4.095);
Serial.print("PPM: ");
// Print maapedTdsValue
Serial.println(CO2);
if (CO2 < 150) {
digitalWrite(LED_HIJAU_PIN, HIGH);
digitalWrite(LED_KUNING_PIN, LOW);
digitalWrite(LED_MERAH_PIN, LOW);
noTone(BUZZER_PIN);
} else if (CO2 >= 150 && CO2 < 186) {
digitalWrite(LED_HIJAU_PIN, LOW);
digitalWrite(LED_KUNING_PIN, HIGH);
digitalWrite(LED_MERAH_PIN, LOW);
noTone(BUZZER_PIN);
} else {
digitalWrite(LED_HIJAU_PIN, LOW);
digitalWrite(LED_KUNING_PIN, LOW);
digitalWrite(LED_MERAH_PIN, HIGH);
noTone(BUZZER_PIN);
delay(100);
tone(BUZZER_PIN, 80);
}
delay(100);
}