Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Monitoring System with Wi-Fi and Ethernet Connectivity

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Monitoring System with Wi-Fi and Ethernet Connectivity

Circuit Documentation

Summary

This circuit is designed to create a smart monitoring system using an ESP32 microcontroller. The system integrates various sensors including a PIR motion sensor, a gas sensor (MQ-2), a temperature and humidity sensor (SHT31), and a voltage sensor (ZMPT101B). Additionally, it includes an Ethernet module (W5500) for network connectivity. The ESP32 collects data from these sensors and serves it via a web server.

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with built-in WiFi and Bluetooth capabilities.
    • 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
  2. HC-SR501 PIR motion sensor

    • Description: A motion sensor that detects movement using passive infrared technology.
    • Pins: Output, Ground, Power Supply
  3. SHT31

    • Description: A temperature and humidity sensor.
    • Pins: VCC, GND, SDA, SCL
  4. MQ-2

    • Description: A gas sensor that detects various gases including LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.
    • Pins: GND, VCC, ANALOG, Digital
  5. ZMPT101B

    • Description: A voltage sensor module used for measuring AC voltage.
    • Pins: OUT, GND, VCC, NEUTRO, FASE
  6. Module Ethernet W5500

    • Description: An Ethernet module based on the W5500 chip, used for network connectivity.
    • Pins: NC, INT, RST, GND, 5V, SCK, SS, MOSI, MISO, 3.3V

Wiring Details

ESP32 (30 pin)

HC-SR501 PIR motion sensor

SHT31

MQ-2

ZMPT101B

Module Ethernet W5500

Documented Code

#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_SHT31.h>
#include <SPI.h>
#include <Ethernet.h>

// اطلاعات شبکه WiFi خود را وارد کنید
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// پین‌های متصل به سنسورها
const int mq2Pin = 34;  // سنسور MQ2 به پین GPIO34 متصل شده است
const int motionPin = 13;  // سنسور حرکت HC-SR501 به پین GPIO13 متصل است

// تعریف سنسور SHT31
Adafruit_SHT31 sht31 = Adafruit_SHT31();

// ایجاد شیء وب سرور (پورت 80)
AsyncWebServer server(80);

EthernetClient client;
IPAddress ip(192, 168, 1, 100); // آدرس IP برای اتصال با اترنت

void setup() {
  // شروع ارتباط سریال برای مانیتورینگ
  Serial.begin(115200);

  // اتصال به شبکه WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi!");
  Serial.println(WiFi.localIP());

  // راه‌اندازی سنسور SHT31
  if (!sht31.begin()) {
    Serial.println("Couldn't find SHT31 sensor");
    while (1);
  }

  // راه‌اندازی پین‌های سنسورهای دیجیتال
  pinMode(motionPin, INPUT);

  // راه‌اندازی وب سرور
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    int mq2Value = analogRead(mq2Pin);  // خواندن مقدار آنالوگ از سنسور MQ2
    float temperature = sht31.readTemperature();  // خواندن دما از سنسور SHT31
    float humidity = sht31.readHumidity();  // خواندن رطوبت از سنسور SHT31
    int motionDetected = digitalRead(motionPin);  // خواندن وضعیت سنسور حرکت

    // ساخت HTML برای نمایش داده‌ها
    String html = "<html><body><h1>Smart Monitoring System</h1>";
    html += "<p>MQ2 Sensor Value: " + String(mq2Value) + "</p>";
    html += "<p>Temperature: " + String(temperature) + " °C</p>";
    html += "<p>Humidity: " + String(humidity) + " %</p>";
    html += "<p>Motion Detected: " + String(motionDetected) + "</p>";
    html += "</body></html>";

    request->send(200, "text/html", html);  // ارسال HTML به مرورگر
  });

  // شروع وب سرور
  server.begin();
}

void loop() {
  // در اینجا نیازی به کد خاصی نیست چون سرور به طور مداوم در حال اجراست
}

This code initializes the ESP32, connects it to a WiFi network, sets up the sensors, and starts a web server that serves sensor data in an HTML format. The web server runs continuously, and no additional code is needed in the loop() function.