We are building this code to take temperature measurements in a for loop and input them to an array. The goal is to average the array values. The following is a flowchart with our thought process.
This is the code we have developed. We are unsure of where the array needs to be created, how to create it in this context, and how to average the values.
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// Shared Pins for Thermocouples
#define MAXDO 2
#define MAXCLK 3
// digital IO pins for Thermocouple1
#define MAXCS1 4
Adafruit_MAX31855 thermocouple1(MAXCLK, MAXCS1, MAXDO);
// digital IO pins for Thermocouple2
#define MAXCS2 5
Adafruit_MAX31855 thermocouple2(MAXCLK, MAXCS2, MAXDO);
void setup() {
Serial.begin(9600); //communicates and sets data rate in bits per second
while (!Serial) delay(1); //wait for Serial on Leonardo/Zero, etc
//Thermocouple Setup
Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
Serial.print("Initializing sensor...");
if (!thermocouple1.begin()) {
Serial.println("ERROR.");
while (1) delay(10);
}
Serial.println("DONE.");
Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
Serial.print("Initializing sensor...");
if (!thermocouple2.begin()) {
Serial.println("ERROR.");
while (1) delay(10);
}
Serial.println("DONE.");
//Relay Setup
int relay1 = 8; //sets relay1 variable as value of 11
pinMode(relay1, OUTPUT); //sets digital pin 11 as an output
//LED Setup
int led1 = 9;
pinMode(led1, OUTPUT);
}
void loop() {
// basic readout test, just print the current temp
Serial.print("Internal Temp = ");
Serial.println(thermocouple1.readInternal());
float c1 = thermocouple1.readCelsius();
//If-Else Statement providing Error Code
if (isnan(c1)) {
Serial.println("Something wrong with Thermocouple 1.");
}
else {
Serial.print("C1 = ");
Serial.println(c1);
}
// basic readout test, just print the current temp
Serial.print("Internal Temp = ");
Serial.println(thermocouple2.readInternal());
float c2 = thermocouple2.readCelsius();
//If-Else Statement providing Error Code
if (isnan(c2)) {
Serial.println("Something wrong with Thermocouple 2.");
}
else {
Serial.print("C2 = ");
Serial.println(c2);
}
float C_diff = c2 - c1;
if (C_diff >= 100){
for (int i = 0; i < 120; i++){
float c1 = thermocouple1.readCelsius();
float c2 = thermocouple2.readCelsius();
C_diff = c2 - c1;
float arrayC_diff[i] = C_diff;
delay(500);
}
}
else{
digitalWrite(relay1, LOW);
Serial.println("Relay Pin Low");
}
float arrayC_diff[y];
avgarrayC_diff = ???;
if(avgarrayC_diff>125){
digitalWrite(led1, HIGH);
Serial.println("Overheating Condition");
digitalWrite(relay1, HIGH);
Serial.println("Relay Pin High");
}
delay(60000);
}
Any help would be greatly appreciated. Thanks!
