#include <Arduino.h>
const int ME3_C2H4_PIN = 34; // Chân cảm biến Ethylene (Analog)
const int MQ3_PIN = 35; // Chân cảm biến MQ-3 (Analog)
const int LED_STATUS = 2; // LED trạng thái (xanh)
const int LED_ALERT = 4; // LED cảnh báo (đỏ)
int threshold_eth = 300; // Ngưỡng Ethylene
int threshold_alc = 400; // Ngưỡng cồn
void setup() {
Serial.begin(115200);
pinMode(LED_STATUS, OUTPUT);
pinMode(LED_ALERT, OUTPUT);
digitalWrite(LED_STATUS, HIGH); // Bật LED trạng thái khi khởi động
}
void loop() {
int ethylene_value = analogRead(ME3_C2H4_PIN); // Đọc cảm biến ME3-C2H4
int alcohol_value = analogRead(MQ3_PIN); // Đọc cảm biến MQ-3
Serial.print("Ethylene: ");
Serial.print(ethylene_value);
Serial.print(" | Alcohol: ");
Serial.println(alcohol_value);
// Gửi dữ liệu đến Wokwi Gauge
Serial.print("G:");
Serial.println(ethylene_value);
// Kiểm tra ngưỡng và bật/tắt LED cảnh báo
if (ethylene_value > threshold_eth || alcohol_value > threshold_alc) {
digitalWrite(LED_ALERT, HIGH); // Bật LED cảnh báo
} else {
digitalWrite(LED_ALERT, LOW); // Tắt LED cảnh báo
}
delay(1000);
}