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

ESP32-Based Temperature Monitoring System with I2C LCD and Bluetooth Connectivity

View and Edit Project In Cirkit DesignerImage of ESP32-Based Temperature Monitoring System with I2C LCD and Bluetooth Connectivity

Circuit Documentation

Summary

This circuit is designed to monitor temperature using an MLX90614 infrared temperature sensor and display the readings on a 20x4 I2C LCD panel. The system is powered by a 9V battery and controlled by an ESP32 microcontroller. The circuit also includes two LEDs to indicate system status and temperature anomalies, and a push switch for power control. The ESP32 connects to WiFi and Bluetooth for remote monitoring and control.

Component List

ESP32 (30 pin)

Resistor (220 Ohms)

LED: Two Pin (red)

LED: Two Pin (green)

2Pin Push Switch

20x4 I2C LCD Panel

9V Battery

MLX90614

Wiring Details

ESP32 (30 pin)

Resistor (220 Ohms)

Resistor (220 Ohms)

LED: Two Pin (red)

LED: Two Pin (green)

2Pin Push Switch

20x4 I2C LCD Panel

9V Battery

MLX90614

Code Documentation

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <BluetoothSerial.h>

// Define the components
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); // GY-906 DCI sensor
LiquidCrystal_I2C lcd(0x27, 20, 4);          // LCD (20x4)
BluetoothSerial SerialBT;                    // Bluetooth
#define LED1_PIN 2                           // LED 1 for system ON
#define LED2_PIN 4                           // LED 2 for alarm
#define BATTERY_PIN 35                       // Battery monitoring pin

// Variables
float tempThreshold = 140.0; // Default threshold
String material = "FR4 (4.2-4.8)";
float batteryVoltage = 0.0;

// WiFi credentials
const char *ssid = "YOUR_WIFI_SSID";
const char *password = "YOUR_WIFI_PASSWORD";

// Function to initialize WiFi
void setupWiFi() {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

// Function to set material properties via Bluetooth or Serial Monitor
void setMaterial(String selectedMaterial) {
  if (selectedMaterial == "FR4 (4.2-4.8)") {
    tempThreshold = 140.0;
  } else if (selectedMaterial == "FR4 (4.5-4.8)") {
    tempThreshold = 170.0;
  } else if (selectedMaterial == "FR4 (3.4-3.8)") {
    tempThreshold = 220.0;
  } else if (selectedMaterial == "PTFE") {
    tempThreshold = 160.0;
  } else if (selectedMaterial == "POLYIMIDE") {
    tempThreshold = 300.0;
  }
  material = selectedMaterial;
}

// Setup function
void setup() {
  Serial.begin(115200);
  SerialBT.begin("TempMonitor"); // Bluetooth device name
  Wire.begin();
  mlx.begin();
  lcd.begin(20, 4); // Initialize the LCD with 20 columns and 4 rows
  lcd.backlight();

  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);
  pinMode(BATTERY_PIN, INPUT);

  digitalWrite(LED1_PIN, HIGH); // Turn on system status LED
  setupWiFi();                 // Initialize WiFi
  setMaterial("FR4 (4.2-4.8)"); // Default material
}

// Function to read battery voltage
float readBatteryVoltage() {
  int raw = analogRead(BATTERY_PIN);
  return raw * (3.3 / 4095.0) * 2; // Voltage divider factor
}

// Main loop
void loop() {
  float objectTemp = mlx.readObjectTempC();
  batteryVoltage = readBatteryVoltage();

  // Display on LCD
  lcd.setCursor(0, 0);
  lcd.print("Material: ");
  lcd.print(material);
  lcd.setCursor(0, 1);
  lcd.print("Temp: ");
  lcd.print(objectTemp, 1);
  lcd.print(" C");
  lcd.setCursor(0, 2);
  lcd.print("Threshold: ");
  lcd.print(tempThreshold, 1);
  lcd.print(" C");
  lcd.setCursor(0, 3);
  lcd.print("Battery: ");
  lcd.print(batteryVoltage, 2);
  lcd.print(" V");

  // Check for temperature anomaly
  if (objectTemp > tempThreshold) {
    digitalWrite(LED2_PIN, HIGH); // Turn on alarm LED
    SerialBT.println("ALERT: Temperature Anomaly Detected!");
  } else {
    digitalWrite(LED2_PIN, LOW);
  }

  // Check for material selection command via Bluetooth
  if (SerialBT.available()) {
    String command = SerialBT.readString();
    command.trim();
    setMaterial(command);
    SerialBT.println("Material set to: " + material);
  }

  delay(1000); // Delay for stability
}

This code initializes the ESP32, connects to WiFi, and sets up the MLX90614 sensor and LCD display. It continuously reads the temperature and battery voltage, displays the information on the LCD, and checks for temperature anomalies. If an anomaly is detected, it turns on an alarm LED and sends an alert via Bluetooth. The material properties can be set via Bluetooth commands.