#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <WiFi.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const int pirPin = 13; // PIR sensor input pin
const int mq135Pin = 34; // MQ-135 sensor analog output pin
Adafruit_BME280 bme;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(mq135Pin, INPUT);
pinMode(2, OUTPUT); // LED output for motion detection
pinMode(4, OUTPUT);// BUZZER output for gas detection
// Connect to Wi-Fi
WiFi.begin("Wokwi-GUEST","",6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
int pirValue = digitalRead(pirPin);
int mq135Value = analogRead(mq135Pin);
float temperature = bme.readTemperature();
Serial.print("PIR Sensor: ");
Serial.println(pirValue);
Serial.print("MQ-135 Sensor: ");
Serial.println(mq135Value);
Serial.print("Temperature: ");
Serial.println(temperature);
// Check PIR sensor for motion
if (pirValue == HIGH) {
Serial.println("Motion detected!");
digitalWrite(2, HIGH); // Turn on an LED or perform another action
} else {
digitalWrite(2, LOW);
}
// You can add your own logic to check the MQ-135 sensor data and take action based on air quality.
if (mq135Value ==HIGH) {
Serial.println("Gas detected");
digitalWrite(4, HIGH);// Turn on an buzzer or perform another action
}else {
digitalWrite(4, LOW);
}
delay(100); // Adjust the delay as needed
}