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

Arduino UNO and ESP32 Based Multi-Sensor Monitoring System

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ESP32 Based Multi-Sensor Monitoring System

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with multiple sensors including an HC-SR04 Ultrasonic Sensor, an IR sensor, a Humidity YL-69 sensor, an MQ-5 gas sensor, and an ESP32 microcontroller for additional processing and connectivity options. The circuit is powered by a 9V battery and includes serial communication between the Arduino UNO and the ESP32. The Arduino UNO is programmed to read data from the sensors, process the information, and communicate the sensor data to the ESP32.

Component List

Arduino UNO

Humidity YL-69

IR Sensor

MQ-5 Gas Sensor

ESP32 (30 pin)

HC-SR04 Ultrasonic Sensor (x2)

9V Battery

Wiring Details

Arduino UNO

Humidity YL-69

IR Sensor

MQ-5 Gas Sensor

ESP32 (30 pin)

HC-SR04 Ultrasonic Sensor

9V Battery

Documented Code

// Define pins for sensors
const int trigPin = 9;
const int echoPin = 8;
const int irPin = 7;
const int moisturePin = A0;
const int gasPin = A1;

// Setup
void setup() {
  // Start serial communication
  Serial.begin(9600);

  // Ultrasonic sensor pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  // IR sensor pin
  pinMode(irPin, INPUT);

  // ESP32 communication (if needed, you can use SoftwareSerial for ESP32)
  // ESP32 communication on Serial1
  Serial1.begin(115200);
}

// Function to read Ultrasonic sensor
long readUltrasonicDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  long duration = pulseIn(echoPin, HIGH);
  long distance = duration * 0.034 / 2; // distance in cm
  return distance;
}

void loop() {
  // Read ultrasonic sensor
  long distance = readUltrasonicDistance();
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Read IR sensor
  int irValue = digitalRead(irPin);
  if (irValue == LOW) {
    Serial.println("Obstacle detected by IR sensor");
  }

  // Read Soil Moisture sensor
  int moistureValue = analogRead(moisturePin);
  Serial.print("Soil Moisture: ");
  Serial.println(moistureValue);

  // Read Chemical/Gas sensor
  int gasValue = analogRead(gasPin);
  Serial.print("Gas sensor value: ");
  Serial.println(gasValue);

  // Communicate data with ESP32 (optional)
  Serial1.println("Sending sensor data to ESP32");
  Serial1.print("Distance: ");
  Serial1.println(distance);
  Serial1.print("Soil Moisture: ");
  Serial1.println(moistureValue);
  Serial1.print("Gas sensor: ");
  Serial1.println(gasValue);

  delay(1000);
}

This code is designed to run on the Arduino UNO and handles the initialization and reading of the connected sensors. It also includes serial communication with the ESP32 for potential data transmission.