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

ESP32-Based Battery-Powered Wi-Fi Temperature Monitoring System with MLX90614 and I2C LCD

View and Edit Project In Cirkit DesignerImage of ESP32-Based Battery-Powered Wi-Fi Temperature Monitoring System with MLX90614 and I2C LCD

Circuit Documentation

Summary

This circuit is designed to measure temperature using an MLX90614 infrared temperature sensor and display the readings on a 16x2 I2C LCD. The system is powered by a 18650 Li-Ion battery, which is charged using a TP4056 module. An ESP32 microcontroller is used to read the temperature data, send it to a server via Wi-Fi, and manage power consumption. A pushbutton is included to change the mode of temperature measurement, and a buzzer alerts when the battery voltage is low.

Component List

  1. ESP32

    • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, BOOT
  2. MLX90614

    • Description: Infrared temperature sensor for non-contact temperature measurements.
    • Pins: SDA, SCL, GND, VIN
  3. 16x2 I2C LCD

    • Description: A 16x2 character LCD with I2C interface for easy communication.
    • Pins: GND, VCC, SDA, SCL
  4. TP4056

    • Description: Lithium battery charger module with overcharge protection.
    • Pins: OUT-, B-, B+, OUT+, IN-, IN+
  5. Pushbutton

    • Description: A simple pushbutton for user input.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  6. 18650 Li-Ion

    • Description: Rechargeable lithium-ion battery.
    • Pins: Positive, Negative
  7. Resistor

    • Description: A resistor with a resistance of 10k Ohms.
    • Pins: pin1, pin2
  8. Buzzer

    • Description: A piezoelectric buzzer for audio alerts.
    • Pins: PIN, GND
  9. Diode

    • Description: A diode for current direction control.
    • Pins: cathode, anode
  10. USB Plug

    • Description: A USB plug for power input.
    • Pins: GND, D+, D-, 5V+, Out

Wiring Details

ESP32

MLX90614

16x2 I2C LCD

TP4056

Pushbutton

18650 Li-Ion

Resistor

Buzzer

Diode

USB Plug

Code Documentation

#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <WiFi.h>
#include <HTTPClient.h>

// MLX90614 sensor setup
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

// Wi-Fi credentials
const char* ssid = "your-SSID";
const char* password = "your-PASSWORD";

// Server URL
const char* serverURL = "http://your-server-url.com/temperature";

// GPIO Pins
#define BUTTON_PIN 15
#define BUZZER_PIN 4
#define BATTERY_PIN 34  // Analog pin to monitor battery voltage
#define MODE_COUNT 3

// Global Variables
int mode = 0;  // 0: Ambient, 1: Human, 2: Surface

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Initialize peripherals
  Wire.begin();
  mlx.begin();
  
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);

  // Configure battery pin as an analog input
  analogReadResolution(12);

  // Wake-up source: Button or Timer
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_15, 0);  // Button press (LOW signal)
  esp_sleep_enable_timer_wakeup(60000000);      // Wake up every 1 minute

  // Wi-Fi setup
  connectToWiFi();

  Serial.println("Setup complete.");
}

void loop() {
  // Check battery voltage
  float batteryVoltage = readBatteryVoltage();
  if (batteryVoltage < 3.5) {
    alertLowBattery();
  }

  // Read temperature
  float temperature = readTemperature();

  // Send data to server
  sendTemperatureData(temperature);

  // Enter deep sleep
  Serial.println("Entering deep sleep...");
  delay(100);
  esp_deep_sleep_start();
}

float readBatteryVoltage() {
  int rawValue = analogRead(BATTERY_PIN);
  float voltage = (rawValue / 4095.0) * 3.3 * 2;  // Adjust for divider circuit
  Serial.print("Battery Voltage: ");
  Serial.println(voltage);
  return voltage;
}

void alertLowBattery() {
  Serial.println("Low battery! Alerting...");
  digitalWrite(BUZZER_PIN, HIGH);
  delay(500);
  digitalWrite(BUZZER_PIN, LOW);
}

float readTemperature() {
  float temperature = 0.0;

  switch (mode) {
    case 0:
      temperature = mlx.readAmbientTempC();
      Serial.print("Ambient Temperature: ");
      break;
    case 1:
      temperature = mlx.readObjectTempC();
      Serial.print("Human Temperature: ");
      break;
    case 2:
      temperature = mlx.readObjectTempC();
      Serial.print("Surface Temperature: ");
      break;
  }

  Serial.println(temperature);
  return temperature;
}

void sendTemperatureData(float temperature) {
  if (WiFi.status() != WL_CONNECTED) {
    connectToWiFi();
  }

  HTTPClient http;
  http.begin(serverURL);

  String postData = "mode=" + String(mode) + "&temperature=" + String(temperature);
  http.addHeader("Content