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.
5V
to LCD I2C Display VCC, Adafruit MAX31865 RTD Sensor Breakout VIN, and 1 Channel 5V Relay Module VCC+GND
to LCD I2C Display GND, Adafruit MAX31865 RTD Sensor Breakout GND, and 1 Channel 5V Relay Module VCC- (GND)D21/SCL
to LCD I2C Display SCLD20/SDA
to LCD I2C Display SDAD52
to Adafruit MAX31865 RTD Sensor Breakout SCLKD50
to Adafruit MAX31865 RTD Sensor Breakout SDOD48
to Adafruit MAX31865 RTD Sensor Breakout DRDYD53
to Adafruit MAX31865 RTD Sensor Breakout CSD51
to Adafruit MAX31865 RTD Sensor Breakout SDID35
to 1 Channel 5V Relay Module INRTDIN+
to PT100 -RTDIN-
to PT100 +-
to Adafruit MAX31865 RTD Sensor Breakout RTDIN++
to Adafruit MAX31865 RTD Sensor Breakout RTDIN-IN
to Arduino Mega 2560 D35VCC+
to Arduino Mega 2560 5VVCC- (GND)
to Arduino Mega 2560 GNDVCC
to Arduino Mega 2560 5VGND
to Arduino Mega 2560 GNDSCL
to Arduino Mega 2560 D21/SCLSDA
to Arduino Mega 2560 D20/SDA/*
* 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
}
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.