Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO Based Temperature-Controlled Relay with LCD Display

Image of Arduino UNO Based Temperature-Controlled Relay with LCD Display

Circuit Documentation

Summary

This circuit is designed to monitor temperature using a DHT11 sensor and control an output based on the temperature readings. When the temperature reaches 36 degrees Celsius, the output is turned on, and when it drops to 34 degrees Celsius, the output is turned off. The status of the output and the current temperature are displayed on a 16x2 LCD. The circuit is powered by an Arduino UNO, which also controls the LCD and the relay module that acts as the output. The LCD's contrast is set via a voltage divider.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

16X2 LCD

  • A liquid crystal display capable of displaying 16 characters per line across 2 lines.
  • It has a backlight and can be used to display alphanumeric characters.

1 Channel 5V Relay Module

  • An electromechanical switch that can be controlled with a low voltage signal from the Arduino.
  • It has one normally open (N.O.), one normally closed (N.C.), and one common (COM) terminal.

DHT11

  • A basic, ultra-low-cost digital temperature and humidity sensor.
  • It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin.

Wiring Details

Arduino UNO

  • 3.3V to 16X2 LCD backlight anode (A).
  • 5V to 1 Channel 5V Relay Module VCC+ and DHT11 5V.
  • GND to 1 Channel 5V Relay Module VCC- (GND), DHT11 GND, and 16X2 LCD backlight cathode (K).
  • D13 to 1 Channel 5V Relay Module IN.
  • D12 to 16X2 LCD RS.
  • D11 to 16X2 LCD E.
  • D7 to DHT11 Signal (S).
  • D5 to 16X2 LCD D4.
  • D4 to 16X2 LCD D5.
  • D3 to 16X2 LCD D6.
  • D2 to 16X2 LCD D7.

16X2 LCD

  • Connected to Arduino UNO for data and control signals.
  • Backlight powered by Arduino UNO's 3.3V and GND.

1 Channel 5V Relay Module

  • VCC+ connected to Arduino UNO 5V.
  • VCC- (GND) connected to Arduino UNO GND.
  • IN controlled by Arduino UNO D13.

DHT11

  • 5V connected to Arduino UNO 5V.
  • Signal (S) connected to Arduino UNO D7.
  • GND connected to Arduino UNO GND.

Documented Code

/*
 * This Arduino Sketch turns on an output when the DHT11 sensor senses
 * a temperature of 36 degrees Celsius and turns it off when the
 * temperature drops to 34 degrees Celsius. It also displays the
 * status (ON/OFF) and the temperature on a 16:2 LCD.
 * The LCD contrast is controlled via a voltage divider.
 * The code avoids debouncing of temperature control and clears the LCD.
 */

#include <DHT.h>
#include <LiquidCrystal.h>

#define DHTPIN 7          // Define the pin connected to the DHT11 data pin
#define DHTTYPE DHT11     // Specify the type of DHT sensor
#define OUTPUT_PIN 13     // Define the pin connected to the Relay Module input

DHT dht(DHTPIN, DHTTYPE);  // Initialize the DHT sensor
// Initialize the LCD and specify the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode(OUTPUT_PIN, OUTPUT);  // Set the relay control pin as output
  lcd.begin(16, 2);             // Set up the LCD's number of columns and rows
  dht.begin();                  // Start the DHT sensor
}

void loop() {
  float temp = dht.readTemperature();  // Read temperature in Celsius
  if (isnan(temp)) {                   // Check if the reading failed
    lcd.clear();                       // Clear the LCD
    lcd.setCursor(0, 0);               // Set the cursor to the top-left position
    lcd.print("Error reading");        // Print an error message
    lcd.setCursor(0, 1);               // Move to the second line
    lcd.print("temperature");          // Continue the error message
    return;                            // Skip the rest of the loop
  }
  lcd.clear();                         // Clear the LCD for fresh data
  lcd.setCursor(0, 0);                 // Set the cursor to the top-left position
  lcd.print("Temp: ");                 // Print "Temp: "
  lcd.print(temp);                     // Print the temperature value
  lcd.print(" C");                     // Print the Celsius symbol
  if (temp >= 36) {                    // If the temperature is high enough
    digitalWrite(OUTPUT_PIN, HIGH);    // Turn on the relay
    lcd.setCursor(0, 1);               // Move to the second line
    lcd.print("Status: ON ");          // Print the status
  } else if (temp <= 34) {             // If the temperature is low enough
    digitalWrite(OUTPUT_PIN, LOW);     // Turn off the relay
    lcd.setCursor(0, 1);               // Move to the second line
    lcd.print("Status: OFF");          // Print the status
  }
  delay(2000);                         // Wait for 2 seconds before the next reading
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the DHT11 sensor and the 16x2 LCD, reads the temperature, and controls the relay module based on the temperature readings. It also handles the display of temperature and status information on the LCD.