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

Arduino Mega 2560 Based Temperature Monitoring and Relay Control System

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Based Temperature Monitoring and Relay Control System

Circuit Documentation

Summary

This circuit is designed to interface with a PT100 temperature sensor through the Adafruit MAX31865 RTD Sensor Breakout. It controls a 1 Channel 5V Relay Module based on temperature thresholds and displays the temperature readings on an I2C LCD display. The Arduino Mega 2560 serves as the central microcontroller unit, managing the sensor data, controlling the relay, and communicating with the LCD display.

Component List

Arduino Mega 2560

Adafruit MAX31865 RTD Sensor Breakout

PT100

1 Channel 5V Relay Module

LCD I2C Display

Wiring Details

Arduino Mega 2560

Adafruit MAX31865 RTD Sensor Breakout

PT100

1 Channel 5V Relay Module

LCD I2C Display

Documented Code

Arduino Mega 2560 Code

/*
 * This Arduino sketch interfaces with a PT100 temperature sensor via the
 * MAX31865 RTD Sensor Breakout, controls a relay module based on temperature
 * thresholds, and displays information on an I2C LCD display.
 */

#include <SPI.h>
#include <Adafruit_MAX31865.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// MAX31865 pins
#define MAX31865_CS 53
#define MAX31865_DRDY 48

// Relay pin
#define RELAY_PIN 35

// Create the RTD sensor object
Adafruit_MAX31865 rtd = Adafruit_MAX31865(MAX31865_CS);

// The value of the Rref resistor
#define RREF 420.0

// Temperature threshold
float tempThreshold = 0.0;

// Create the LCD object
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  while (!Serial) delay(10); // Wait for serial monitor

  Serial.println("Enter temperature threshold:");
  while (Serial.available() == 0) delay(10); // Wait for input
  tempThreshold = Serial.parseFloat();
  Serial.print("Threshold set to: ");
  Serial.println(tempThreshold);

  // Initialize the MAX31865
  rtd.begin(MAX31865_2WIRE);

  // Set relay pin as output
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW); // Ensure relay is off

  // Initialize the LCD
  lcd.begin();
  lcd.backlight();
  lcd.print("Temp: ");
}

void loop() {
  uint16_t rtdRaw = rtd.readRTD();
  float ratio = rtdRaw;
  ratio /= 32768;
  float rtdResistance = ratio * RREF;
  float temperature = (rtdResistance - 100) / 0.385;

  Serial.print("Temperature: ");
  Serial.println(temperature);

  lcd.setCursor(6, 0);
  lcd.print(temperature);
  lcd.print(" C");

  if (temperature >= tempThreshold) {
    digitalWrite(RELAY_PIN, HIGH); // Turn on relay
  } else {
    digitalWrite(RELAY_PIN, LOW); // Turn off relay
  }

  delay(1000); // Wait 1 second before next read
}

Adafruit MAX31865 RTD Sensor Breakout Code

The Adafruit MAX31865 RTD Sensor Breakout does not have separate code as it is controlled by the Arduino Mega 2560 through the SPI interface. The relevant code is included in the Arduino Mega 2560 sketch above.