//Thermistors int ThermistorPinR = 0; int ThermistorPinL = 1; int VoL; int VoR; float RR1 = 10000; float logRR2, RR2, TR; float cR1 = 1.009249522e-03, cR2 = 2.378405444e-04, cR3 = 2.019202697e-07; float RL1 = 10000; float logRL2, RL2, TL; float cL1 = 1.009249522e-03, cL2 = 2.378405444e-04, cL3 = 2.019202697e-07; //Motors int motorSpeedA = 0; int motorSpeedB = 0; const int switchPin = 2; const int leftMotor = 9; const int rightMotor = 7; void setup() { //Set up the pins Serial.begin(9600); pinMode(leftMotor, OUTPUT); pinMode(rightMotor, OUTPUT); } void loop() { Serial.println("R"); //Print the value to the serial port Serial.println(TR); //Print the value to the serial port Serial.println(VoR); //Print the value to the serial port Serial.println("L"); //Print the value to the serial port Serial.println(TL); //Print the value to the serial port Serial.println(VoL); //Print the value to the serial port // Right VoR = analogRead(ThermistorPinR); RR2 = RR1 * (1023.0 / (float)VoR - 1.0); logRR2 = log(RR2); TR = (1.0 / (cR1 + cR2 * logRR2 + cR3 * logRR2 * logRR2 * logRR2)); TR = TR - 273.15; TR = (TR * 9.0) / 5.0 + 32.0; TR = TR * -1.8; // Left VoL = analogRead(ThermistorPinL); RL2 = RL1 * (1023.0 / (float)VoL - 1.0); logRL2 = log(RL2); TL = (1.0 / (cL1 + cL2 * logRL2 + cL3 * logRL2 * logRL2 * logRL2)); TL = TL - 273.15; TL = (TL * 9.0) / 5.0 + 32.0; TL = TL * -1.8; // If statements if (TL > 75 && TL < 85) { //if the left temp is above 75 degrees and below 85 degrees, turn on the left fans to 45. digitalWrite(leftMotor, HIGH); motorSpeedA = 45; } else if (TR > 75 && TR < 85) { //if the right temp is above 75 degrees and below 85 degrees, turn on the right fans to 45. digitalWrite(leftMotor, HIGH); motorSpeedB = 45; } else if (TL > 85 && TL < 90) { //if the left temp is above 85 degrees and below 90 degrees, turn on the left fans to 80. digitalWrite(leftMotor, HIGH); motorSpeedA = 80; } else if (TR > 85 && TR < 90) { //if the right temp is above 85 degrees and below 90 degrees, turn on the right fans to 80. digitalWrite(rightMotor, HIGH); motorSpeedB = 80; } else if (TL > 90) { //if the left temp is above 85 degrees, turn on the left fans to 100. digitalWrite(leftMotor, HIGH); motorSpeedA = 100; } else if (TR > 90) { //if the right temp is above 65 degrees, turn on the left fan to 100. digitalWrite(rightMotor, HIGH); motorSpeedB = 100; } else if (TL < 65) { //if the left temp is below 65 degrees, turn off the left fan. digitalWrite(leftMotor, LOW); } else if (TR < 65) { //if the right temp is below 65 degrees, turn off the right fan. digitalWrite(rightMotor, LOW); motorSpeedB = 0; } delay(1000); }