Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino and ESP32-Based Smart Environmental Monitoring System with Wi-Fi Connectivity

Image of Arduino and ESP32-Based Smart Environmental Monitoring System with Wi-Fi Connectivity

Circuit Documentation

Summary

This circuit integrates multiple sensors and actuators with an Arduino UNO and an ESP32 microcontroller. The system collects environmental data using various sensors, processes the data, and sends it to a Firebase database. The sensors include a BME280 for temperature, humidity, and pressure, an MQ135 for air quality, a GP2Y1010AU0F for particulate matter, and an ultrasonic sensor for distance measurement. Additionally, a servo motor is controlled for actuation purposes.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0

Resistor

  • Description: A passive electrical component that implements electrical resistance.
  • Pins: pin1, pin2
  • Properties:
    • Resistance: 200 Ohms

GP2Y1010AU0F

  • Description: An optical air quality sensor.
  • Pins: VCC, Vout, S-GND, LED, LED-GND, V-LED

ESP32 (30 pin)

  • Description: A low-cost, low-power system on a chip microcontroller with integrated Wi-Fi and dual-mode Bluetooth.
  • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3

MQ135

  • Description: A gas sensor for air quality monitoring.
  • Pins: VCC, GND, A0, D0

Electrolytic Capacitor

  • Description: A type of capacitor that uses an electrolyte to achieve a larger capacitance.
  • Pins: -, +
  • Properties:
    • Capacitance: 0.000001 Farads

Ultrasonic Sensor

  • Description: A sensor that measures distance by using ultrasonic waves.
  • Pins: +VCC, Trigger, Echo, GND

Servo Motor 9G

  • Description: A small servo motor used for precise control of angular position.
  • Pins: VCC 5V, PMW, GND

OV7725

  • Description: A camera module for capturing images.
  • Pins: 3V3, GND, SIOC, SIOD, VSYNC, HREF, PCLK, XCLK, D9, D8, D7, D6, D5, D4, D3, D2, RESET, D1, D0, PWDN

BMP280

  • Description: A barometric pressure sensor.
  • Pins: SDO, CSB, SDA, SCL, GND, VCC

Wiring Details

Arduino UNO

  • 3.3V connected to +VCC of Ultrasonic Sensor and VCC of MQ135.
  • 5V connected to pin1 of Resistor.
  • GND connected to GND of Ultrasonic Sensor and GND of MQ135.
  • A0 connected to Vout of GP2Y1010AU0F.
  • D1 connected to RX2 of ESP32.
  • D0 connected to TX2 of ESP32.

Resistor

  • pin1 connected to 5V of Arduino UNO.
  • pin2 connected to + of Electrolytic Capacitor and V-LED of GP2Y1010AU0F.

GP2Y1010AU0F

  • VCC connected to VCC 5V of Servo Motor 9G.
  • Vout connected to A0 of Arduino UNO.
  • S-GND connected to - of Electrolytic Capacitor.
  • LED connected to D35 of ESP32.
  • LED-GND connected to - of Electrolytic Capacitor.
  • V-LED connected to + of Electrolytic Capacitor.

ESP32 (30 pin)

  • 3V3 connected to VCC 5V of Servo Motor 9G.
  • GND connected to GND of Arduino UNO and GND of Servo Motor 9G.
  • RX2 connected to D1 of Arduino UNO.
  • TX2 connected to D0 of Arduino UNO.
  • D34 connected to A0 of MQ135.
  • D35 connected to LED of GP2Y1010AU0F.
  • D32 connected to PCLK of OV7725.
  • D33 connected to D7 of OV7725.
  • D19 connected to Echo of Ultrasonic Sensor.
  • D4 connected to PMW of Servo Motor 9G.
  • D2 connected to Trigger of Ultrasonic Sensor.

MQ135

  • VCC connected to +VCC of Ultrasonic Sensor.
  • GND connected to GND of Ultrasonic Sensor.
  • A0 connected to D34 of ESP32.

Electrolytic Capacitor

  • - connected to S-GND and LED-GND of GP2Y1010AU0F.
  • + connected to pin2 of Resistor and V-LED of GP2Y1010AU0F.

Ultrasonic Sensor

  • +VCC connected to 3.3V of Arduino UNO.
  • GND connected to GND of Arduino UNO.
  • Trigger connected to D2 of ESP32.
  • Echo connected to D19 of ESP32.

Servo Motor 9G

  • VCC 5V connected to pin1 of Resistor.
  • PMW connected to D4 of ESP32.
  • GND connected to GND of ESP32.

OV7725

  • PCLK connected to D32 of ESP32.
  • D7 connected to D33 of ESP32.

BMP280

  • Not connected in the provided net list.

Documented Code

#include <WiFi.h>
#include <FirebaseESP32.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include "addons/TokenHelper.h"
#include "addons/RTDBHelper.h"
#include <time.h>  // Include time library

// Wi-Fi credentials
const char* ssid = "TP-Link_0F5C";  // Replace with your SSID
const char* password = "Swapnil5517";  // Replace with your password

// Firebase credentials
FirebaseData firebaseData;
FirebaseConfig config;
FirebaseAuth auth;

// Firebase project details
const char* FIREBASE_HOST = "https://weatheresp32-f08e9-default-rtdb.asia-southeast1.firebasedatabase.app/";  // Your Firebase database URL
const char* FIREBASE_API_KEY = "AIzaSyCTKVdb2um91NV67yqtTvx-WiRjFruep0w";  // Your Firebase Web API key

// BME280 sensor setup
Adafruit_BME280 bme;  // I2C
const int MQ135Pin = 34;   // Use GPIO34 for MQ-135 sensor
const int GP2Y10Pin = 35;  // Use GPIO35 for GP2Y10 sensor

unsigned long sendDataPrevMillis = 0;
bool signupOK = false;

// Function to calculate heat index
float calculateHeatIndex(float temperature, float humidity) {
    return temperature + humidity * 0.1;  // Simple heat index formula
}

// Function to calculate dew point
float calculateDewPoint(float temperature, float humidity) {
    double a = 17.27;
    double b = 237.7;
    double alpha = ((a * temperature) / (b + temperature)) + log(humidity / 100.0);
    return (b * alpha) / (a - alpha);
}

// Function to calculate oxygen concentration
float calculateOxygenConcentration(float pressure) {
    float seaLevelPressure = 1013.25;  // hPa
    return 20.9 * (pressure / seaLevelPressure);  // Oxygen concentration proportional to pressure
}

// Function to get current date and time in IST
String getCurrentDateTime() {
    struct tm timeinfo;
    if (!getLocalTime(&timeinfo)) {
        Serial.println("Failed to obtain time");
        return "";
    }

    // Format date and time
    char buffer[30];