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

ESP32-Based Smart Environment Monitoring System with GPS Tracking and OLED Display

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Environment Monitoring System with GPS Tracking and OLED Display

Circuit Documentation

Summary

This circuit is designed to control the temperature of a system, monitor driver behavior using a camera module, control a relay module to avoid high currents, display results on an OLED display, and find the location of the vehicle using a GPS module. The central processing unit of the circuit is an ESP32 microcontroller, which interfaces with a DHT11 temperature and humidity sensor, a relay module, an OLED display, a GPS module, and an ESP32 CAM module. The ESP32 also manages power distribution to the components and communicates with the GPS module via serial communication.

Component List

ESP32 (30 pin)

DHT11

ESP32 CAM

Relay module 5v-30v

GPS NEO 6M

3.7v LiPo

OLED Display 128x32

Wiring Details

ESP32 (30 pin)

DHT11

ESP32 CAM

Relay module 5v-30v

GPS NEO 6M

3.7v LiPo

OLED Display 128x32

Documented Code

/*
 * This Arduino Sketch is designed to control the temperature of a system, monitor
 * driver behavior using a camera module, control a relay module to avoid high
 * currents, display results on an OLED display, and find the location of the
 * vehicle using a GPS module.
 */
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DHTPIN 12          // Define the pin connected to the DHT11 data pin
#define DHTTYPE DHT11      // Define the type of DHT sensor
#define RELAY_PIN 13       // Define the pin connected to the Relay module trigger
#define OLED_RESET -1      // Define the reset pin for the OLED display (not used)
#define SCREEN_WIDTH 128   // Define the width of the OLED display
#define SCREEN_HEIGHT 32   // Define the height of the OLED display
#define OLED_I2C_ADDRESS 0x3C // Define the I2C address for the OLED display

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Initialize the OLED display

void setup() {
  Serial.begin(115200); // Start the serial communication
  Serial1.begin(9600);  // Use Serial1 for GPS communication
  dht.begin();          // Start the DHT sensor
  pinMode(RELAY_PIN, OUTPUT); // Set the relay pin as an output
  digitalWrite(RELAY_PIN, LOW); // Ensure the relay is off
  // Initialize the OLED display
  if(!display.begin(SSD1306_I2C_ADDRESS, OLED_I2C_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Infinite loop if the display cannot be initialized
  }
  display.display(); // Show the initial display buffer
  delay(2000);       // Wait for 2 seconds
  display.clearDisplay(); // Clear the display buffer
}

void loop() {
  float temp = dht.readTemperature(); // Read the temperature from the DHT sensor
  if (isnan(temp)) { // Check if the reading failed
    Serial.println(F("Failed to read from DHT sensor!"));
    return; // Skip the rest of the loop if the reading failed
  }
  // Control the relay based on the temperature
  if (temp > 15) {
    digitalWrite(RELAY_PIN, HIGH); // Turn on the relay if the temperature is above 15 degrees Celsius
  } else {
    digitalWrite(RELAY_PIN, LOW);  // Turn off the relay otherwise
  }
  // Display the temperature on the OLED display
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print(F("Temp: "));
  display.print(temp);
  display.print(F(" C"));
  display.display();
  // Read data from the GPS module and output it to the serial monitor
  while (Serial1.available() > 0) {
    char c = Serial1.read();
    Serial.write(c);
  }
  delay(2000); // Wait for 2 seconds before repeating the loop
}

This code is responsible for initializing the components connected to the ESP32, reading temperature data from the DHT11 sensor, controlling the relay module based on the temperature, displaying the temperature on the OLED display, and reading data from the GPS module. The ESP32 uses two serial interfaces: the default Serial for debugging and Serial1 for GPS communication.