Max31865 that switches a relay by temperature

Hello you all, i would like to switch a relay with the MAX31865 thermocouple. Can anyone help me to get started with the code? I've run the test procedure for the MAX31865 and it works but i don't know how to combine it with a relay.. please help, thanks

Welcome to the forum

Your topic was MOVED to its current forum category as it is more suitable than the original

Please post the code that you have that reads the sensor, using code tags when you do

This sensor uses SPI to communicate, 4 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");

  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}


void loop() {
  uint16_t rtd = thermo.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold"); 
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold"); 
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias"); 
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage"); 
    }
    thermo.clearFault();
  }
  Serial.println();
  delay(1000);
}

`

Did you miss the request to use code tags when posting the code ?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

When you posted your code without code tags did you receive a warning message ?

yes, but i don't know how to use them

As you try to figure out how to use and implement code tags...

Figuring out how to do code tags is important for several reasons such as can you do your own research; can you follow instructions? Things get a bit more complicated after learning how to post using code tags, consider it a test of sorts. Can you do it?

... Consider.

Do you have a relay module? Are you using a 3.3V or 5V MCU? Post the deets on the relay module. Is your project on a breadboard? Post images of your wired project. Describe how the project is powered.

do you know what this means:

MySensorDataStoredHere = ReadingFromSensor;

if( MySensorDataStoredHere is bigger than ANumberStoredHere )
{
RelayON
} else
{
RelayOff
}

How to operate a GPIO pin Open up the Arduino IDE, select File | Examples | 01.Basics | Blink. You can use the LED code to switch a GPIO pin HIGH and LOW.

Did you read the instructions in the link that I posted ?

figured it out! thanks

yes i know it, but the c-language isn't my strongest point. The relay is 5 volts. here is a picture:

thanks, i want to:

if (temperature = 40)
{
RelayOn
}
else
RelayOff
}

But i don't know how te configure it because in the code there is nothing about temperature only strange words like this:

(fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open");

Sure there is:

Serial.println(thermo.temperature(RNOMINAL, RREF));

That gets the temperature and then prints it.

oke, and if i wanted the relay get started by 40degrees, how can i discribe it in the code?

Like this?

if(Serial.print("Temperature = 40")
{
RelayOn
}
else
RelayOff
}

if-temperature-is-equal-to-or-greater-than-40-turn-realy-on-else-turn-relay-off.

if(boolean_expression) {
// statement(s) will execute if the boolean expression is true
} else {
// statement(s) will execute if the boolean expression is false
}

hope those hints help.

what happens when you try?

hang on, i will try

This is what i've made, the following error i'll get:
exit status 1
'temperature' was not declared in this scope

#include <Adafruit_MAX31865.h>

// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  100.0
#define RELAY1 9

void setup(){ {
  Serial.begin(9600);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}
// setup Relay
  pinMode(RELAY1, OUTPUT);
  digitalWrite(RELAY1, HIGH);

 
  Serial.println("DONE.");

}

void loop() {
  uint16_t rtd = thermo.readRTD();

  Serial.print("RTD value: "); Serial.println(rtd);
  float ratio = rtd;
  ratio /= 32768;
  Serial.print("Ratio = "); Serial.println(ratio,8);
  Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
  Serial.print("Temperature = "); Serial.println(thermo.temperature(RNOMINAL, RREF));

  // Check and print any faults
  uint8_t fault = thermo.readFault();
  if (fault) {
    Serial.print("Fault 0x"); Serial.println(fault, HEX);
    if (fault & MAX31865_FAULT_HIGHTHRESH) {
      Serial.println("RTD High Threshold"); 
    }
    if (fault & MAX31865_FAULT_LOWTHRESH) {
      Serial.println("RTD Low Threshold"); 
    }
    if (fault & MAX31865_FAULT_REFINLOW) {
      Serial.println("REFIN- > 0.85 x Bias"); 
    }
    if (fault & MAX31865_FAULT_REFINHIGH) {
      Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_RTDINLOW) {
      Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); 
    }
    if (fault & MAX31865_FAULT_OVUV) {
      Serial.println("Under/Over voltage"); 
    }
    thermo.clearFault();
  }
  Serial.println();
  delay(1000);


if(temperature >= 40){
    digitalWrite(RELAY1, HIGH);
    Serial.println("RELAY PIN HIGH");
} 
else{
   digitalWrite(RELAY1, LOW)
}
delay(1000);
}

Try:

if(thermo.temperature(RNOMINAL, RREF) >=40)

The problem is that although you read the temperature and print it you never save its value so that you can compare it with a value in the sketch

As a quick and dirty fix, change

  if (temperature >= 40)

to

  if (thermo.temperature(RNOMINAL, RREF) >= 40)

Yes it works!! thanks you all!! now i will try to expand it with more relay's and thermocouples to optimize the heating system!!