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

Wi-Fi Controlled Temperature Monitoring System with OLED Display

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Temperature Monitoring System with OLED Display

Circuit Documentation

Summary

This circuit is designed to monitor temperature using an LM35 temperature sensor and control a fan based on the temperature readings. The ESP32 microcontroller processes the sensor data and drives a TRIAC to control the fan's power. An OLED display is used to show the current temperature and fan speed. The circuit also includes a MOC3041 optoisolator for safe interfacing with the TRIAC, and a BT139 for controlling the AC load.


Component List

1. ESP32 (30 pin)

2. 0.96" OLED

3. 120V Outlet

4. MOC3041

5. Temperature Sensor (LM35)

6. BT139 600

7. 220 Fan

8. Resistors

9. Ceramic Capacitor

10. 5A Fuse


Wiring Details

ESP32 (30 pin)


0.96" OLED


120V Outlet


MOC3041


Temperature Sensor (LM35)


BT139 600


220 Fan


Resistors


Documented Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1  // Reset pin (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define LM35_PIN 34          // ESP32 analog input pin connected to LM35
#define TRIAC_PIN 12         // Pin controlling the TRIAC (GPIO 12)
#define ZERO_CROSS_PIN 13    // Pin connected to zero-cross detector (GPIO 13)
#define FAN_MAX_DELAY 8333   // Max delay in microseconds (100% off at 60Hz)

// Baseline temperature in °C (adjust this to your desired baseline)
float baselineTemp = 20.0;
int delayTime = 0;  // Delay for phase angle control

void IRAM_ATTR zeroCrossDetected() {
  delayMicroseconds(delayTime);
  digitalWrite(TRIAC_PIN, HIGH);  // Fire the TRIAC
  delayMicroseconds(10);          // Keep TRIAC on for a few microseconds
  digitalWrite(TRIAC_PIN, LOW);   // Turn off the TRIAC
}

void setup() {
  pinMode(TRIAC_PIN, OUTPUT);
  pinMode(ZERO_CROSS_PIN, INPUT);

  // Attach interrupt for zero-cross detection
  attachInterrupt(digitalPinToInterrupt(ZERO_CROSS_PIN), zeroCrossDetected, RISING);

  Serial.begin(115200);  // ESP32 operates faster, so use a higher baud rate
  
  // Initialize the OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {  // Address 0x3C for most OLEDs
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);  // Don't proceed, loop forever
  }
  display.clearDisplay();  // Clear the buffer
  display.setTextSize(4);  // Set text size (increase for bigger text)
  display.setTextColor(SSD1306_WHITE);  // Set text color
  
  delay(2000);  // Give display some time to initialize
}

void loop() {
  int sensorValue = analogRead(LM35_PIN);  // Read analog value from LM35
  
  // Convert the analog value to temperature in Celsius
  // LM35 outputs 10mV per degree Celsius, powered at 5V
  float voltage = sensorValue * (5.0 / 4095.0);  // Convert analog reading to voltage at 5V
  int currentTemp = (int)(voltage * 100);  // Convert voltage to temperature in Celsius as whole number

  // Display the temperature in the Serial Monitor
  Serial.print("Current Temp: ");
  Serial.println(currentTemp);

  // Display the temperature on the OLED
  display.clearDisplay();  // Clear the display each loop
  display.setCursor(0, 0);  // Start at top-left corner
  display.setTextSize(2);   // Set text size
  display.print("Temp: ");
  display.print(currentTemp); // Show only whole degrees
  display.println(" C");

  // Display fan speed (based on the delay time)
  float fanSpeed = map(delayTime, FAN_MAX_DELAY, 0, 0, 100);  // Calculate fan speed as percentage
  display.print("Fan: ");
  display.print((int)fanSpeed); // Show fan speed as whole number
  display.println(" %");

  display