I am trying to program my arduino to detect the thermistor resistance from 4 heated seats and then have the arduino power off the relay associated with each thermistor, with the way the code is currently the relays will activate or deactivate when they sense a certain resistance on either of the 4 analog inputs when i only want the associated relay to be activated with its thermistor. Any help would be appreciated.
/****************************************/
#include <math.h>
/****************************************/
const int relayPin1 = 8;
const int ThermistorPin1 = A0;
const int relayPin2 = 9;
const int ThermistorPin2 = A1;
const int relayPin3 = 10;
const int ThermistorPin3 = A2;
const int relayPin4 = 11;
const int ThermistorPin4 = A3;
double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1023.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
Temp = (Temp * 9.0)/ 5.0 + 32.0;
return Temp;
}
/****************************************/
void setup() {
Serial.begin(9600);
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
}
void loop() {
int val1;
int val2;
int val3;
int val4;
double temp1;
double temp2;
double temp3;
double temp4;
val1=analogRead(ThermistorPin1);
temp1=Thermistor(val1);
val2=analogRead(ThermistorPin2);
temp2=Thermistor(val2);
val3=analogRead(ThermistorPin3);
temp3=Thermistor(val3);
val4=analogRead(ThermistorPin4);
temp4=Thermistor(val4);
Serial.print("Temperature = ");
Serial.print(temp1);
Serial.println(" F");
if (temp1 >= 107){
digitalWrite(relayPin1, LOW);
}
if (temp1 <= 107){
digitalWrite(relayPin1, HIGH);
}
if (temp2 >= 107){
digitalWrite(relayPin2, LOW);
}
if (temp2 <= 107){
digitalWrite(relayPin2, HIGH);
}
if (temp3 >= 107){
digitalWrite(relayPin3, LOW);
}
if (temp3 <= 107){
digitalWrite(relayPin3, HIGH);
}
if (temp4 >= 107){
digitalWrite(relayPin4, LOW);
}
if (temp4 <= 107){
digitalWrite(relayPin4, HIGH);
}
delay(1000);
}