No products in the cart.
In the era of smart devices and automation, environmental monitoring and control systems play a crucial role in maintaining optimal conditions in various settings, from homes and offices to industrial environments. This project leverages the power of the ESP32-C3 microcontroller, the BME680 sensor, an OLED display, and a 2-channel relay to create a comprehensive smart environmental monitoring and control system. The primary purpose of this project is to monitor key environmental parameters such as temperature, humidity, pressure, and air quality, and to control external devices based on these parameters.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_BME680.h>
// Define the relay pins
#define RELAY1_PIN 25
#define RELAY2_PIN 26
// 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);
// BME680 sensor configuration
Adafruit_BME680 bme;
// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Thresholds for relay control
const float TEMP_THRESHOLD = 30.0; // Temperature threshold for relay 1 (in degrees Celsius)
const float HUMIDITY_THRESHOLD = 40.0; // Humidity threshold for relay 2 (in %)
void setup() {
// Start the serial communication
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
// Initialize the BME680 sensor
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
// Set up the BME680 sensor
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
// Initialize the relay pins
pinMode(RELAY1_PIN, OUTPUT);
pinMode(RELAY2_PIN, OUTPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Perform a BME680 measurement
unsigned long endTime = bme.beginReading();
if (bme.endReading() != BME680_OK) {
Serial.println("Failed to perform reading");
return;
}
// Read data from the BME680 sensor
float temperature = bme.temperature;
float humidity = bme.humidity;
float pressure = bme.pressure / 100.0;
float gas = bme.gas_resistance / 1000.0;
// Display data on the OLED screen
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Temp: ");
display.print(temperature);
display.println(" *C");
display.print("Humidity: ");
display.print(humidity);
display.println(" %");
display.print("Pressure: ");
display.print(pressure);
display.println(" hPa");
display.print("Gas: ");
display.print(gas);
display.println(" KOhms");
display.display();
// Control the relays based on sensor data
if (temperature > TEMP_THRESHOLD) {
digitalWrite(RELAY1_PIN, HIGH); // Turn on relay 1
} else {
digitalWrite(RELAY1_PIN, LOW); // Turn off relay 1
}
if (humidity < HUMIDITY_THRESHOLD) {
digitalWrite(RELAY2_PIN, HIGH); // Turn on relay 2
} else {
digitalWrite(RELAY2_PIN, LOW); // Turn off relay 2
}
// Wait for a second before the next loop
delay(1000);
}
You can customize the thresholds for temperature and humidity in the code to suit your specific requirements. Additionally, you can expand the code to include more complex logic for controlling the relays or integrating with other sensors and actuators.
This Smart Environmental Monitoring and Control System offers a versatile solution for maintaining optimal environmental conditions. By integrating advanced sensors, real-time data display, and automated control, it provides both convenience and efficiency. Whether for home automation, office environment management, or industrial applications, this project showcases the capabilities of modern IoT technology in enhancing everyday life.
No matter how big your company is, as you expand and reach new highs you’ll want an agency to have your back. One with a process
© 2023 AI FUTURE All rights Reserved