Hi All. Im using 2 of the playingwithfusion K-type thermocouple breakout boards (Playing With Fusion - MAX31855 K-Type Thermocouple Sensor Breakout (1ch)). with an arduino mega.
These are wired with individual CS pins to the board and the DO,CLK,V+,V- all on a bus. Would that cause enough noise ? wouldnt think so.
I have within the program that if there is no thermocouple present that some of the actions will not take place. this works as I intended it to until on random times I will get a brief/ multiple isnan readings and this will quickly trigger some of the outputs. this happens at completely random times!!!
From what I have read, If the boards are close to noise this could be the problem. I isolated them and no joy.
I also Added a 10uf capacitor across the +/- junctions as recommended by another user on another thread. This doesn't seem to solve the issue. Grounded or u-grounded thermocouples also seem to make no difference.
Here is my script below.
Feel free to criticize etc. all Improvements welcomed in any shape of form. I am some what new to C++ and Arduino.
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>
int thermoCLK = 7;
int thermoCS = 8;
int thermoDO = 9;
int thermoCS1= 13;
const int diverter = 37; // the number of the relay 17 pin (NORMALLY OPEN SOLINOID)
const int pump = 39; // the number of relay 2 pin 16 (THE PUMP)
const int heater = 6; // The heater relay
const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int buttonPin = 10;
const int tankvalve = 31;
const int highlevel = 33;
const int lowlevel = 35;
// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS1, thermoDO);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int trigger = 0; // variable for reading the trigger status
int fulltank = 0;
int emptytank = 0;
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("MAX31855 test");
// wait for MAX chip to stabilize
pinMode(diverter, OUTPUT);
pinMode(pump, OUTPUT);
pinMode(heater, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(highlevel,INPUT);
pinMode(lowlevel,INPUT);
pinMode(tankvalve,OUTPUT);
delay(50);
}
void loop() {
int sensorVal1 = analogRead(sensorPin1);// read the value on AnalogIn pin 0 and store it in a variable
int sensorVal2 = analogRead(sensorPin2);// read the value on AnalogIn pin 1 and store it in a variable
float voltage = (sensorVal1/1024.0) * 5.0; // convert the ADC reading to voltage
float Pressure = (voltage*2) ;
float voltage2 = (sensorVal2/1024.0) * 5.0; // convert the ADC reading to voltage
float Pressureselect = (voltage2 * 2 ) ;
lcd.setCursor(0, 0);
// Print a message to the LCD.
lcd.print("Bar=");
// set the cursor to column 0, line 1
// line 1 is the second row, since counting begins with 0
lcd.print(Pressure,1);
lcd.setCursor(9, 0);
lcd.print ("SP="); // Set poinit
lcd.print (Pressureselect,1);
lcd.print (" ");
double blocktemperature = thermocouple1.readCelsius(); //storing what is read in a float/double so it can be used
double steamtemperature = thermocouple2.readCelsius(); //storing what is read in a float/double so it can be used
lcd.setCursor(1, 1);
lcd.print("T1="); //actuall wrighting on lcd screen
lcd.print(blocktemperature,0); //Float value too be printed
lcd.print (" ");
lcd.setCursor(9, 1);
lcd.print("T2="); //actuall wrighting on lcd screen
lcd.print(steamtemperature,0); //Float value too be printed
lcd.print (" ");
Serial.println(blocktemperature);
Serial.println(steamtemperature);
Serial.println(voltage);
Serial.println(voltage2);
// read the state of the trigger value:
trigger = digitalRead(buttonPin);
fulltank = digitalRead(highlevel);
emptytank = digitalRead(lowlevel);
#define TEMPDEADBAND 100 // 100 refers to 100°C
#define PRESSUREDEADBAND 0
if (isnan( blocktemperature)) // isnan means if ther is nothing present in its brackets it can be used to do something
{
digitalWrite(heater, LOW); // heaters will not turn on
}
if (blocktemperature <300 - TEMPDEADBAND)
{
digitalWrite (heater, HIGH);
//digitalWrite (pinout, HIGH); // this is for when I have more outputs. led or high output for another system
}
else if
( blocktemperature >300)
{
digitalWrite (heater, LOW);
}
if (fulltank == HIGH && emptytank == HIGH) {
digitalWrite (tankvalve, LOW);
}
else if (fulltank == LOW && emptytank == HIGH){
digitalWrite (tankvalve, HIGH);
}
else if (fulltank == LOW && emptytank == LOW){
digitalWrite (tankvalve, HIGH);
}
if (trigger == LOW || isnan(steamtemperature)||(steamtemperature >300)|| (emptytank == LOW)|| ( blocktemperature < 200) ) { //If any of these statements are true. the pump or valve will not activate.
// turn both Relay's off:
digitalWrite(diverter, LOW); // this is telling pin 3 to go LOW ie. Off
digitalWrite(pump, LOW); // this is telling pin 4 to go LOW ie. Off
}
else if (trigger == HIGH && (voltage < voltage2 - PRESSUREDEADBAND)){ // if one condtioin is false the statement will not continue further
// turn relay's sequence:
digitalWrite(diverter, HIGH);
digitalWrite(pump, HIGH);
}
else if ((trigger == HIGH) && (voltage >= voltage2) ) {
//greater than 5 bar turn off pump
digitalWrite(diverter, HIGH);
digitalWrite(pump,LOW);
}
delay(5);
}
Thank you for any input
Regards