Hi Tom, sorry about that brain was a bit tired when i wrote this post.
I have had some success i spoke with a work colleague today who has a degree in computer engineering it turns out i needed some more brackets to separate some of the parameters.
This is what it looks like now and appears to be working. Im having allot of trouble getting the LM35 sensors to read without massive error. But I have ordered some digital temp probes that i hope will provide more stable results over the long distances between the probes and the controller. Im using a Mega 2560 and the new digital sensors will be DS18B20.
// Vehicle Information System.
// Version 5.0.
// JTechNZ Engineering and Tech Soultions.
#include <max6675.h>
#include <SeeedOLED.h>
#include <Wire.h>
int intertempPin = A1; // Inter-cooler outlet Temperature. LM35 Sensor
int atPin = A2; // Ambient Air Temperature. LM35 Sensor
int intertemp;
int AT;
int egt;
int fan = 11; // Fan PWM Output.
int led = 8; // Red EGT status LED.
int led1 = 9; // Green EGT Status LED.
int fanSpeed;
int fanOLED;
int egttempMax = 500; // Max EGT temp.
int mindiffTemp = 5; // Min temp above ambient to start fan.
int maxdiffTemp = 70; // Max temp above ambient for fan to be at 100%.
// MAX6675 Pin outs
int thermo_gnd_pin = 45;
int thermo_vcc_pin = 47;
int thermo_so_pin = 49;
int thermo_cs_pin = 51;
int thermo_sck_pin = 53;
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin); // EGT Probe.
void setup()
{
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(intertempPin, INPUT);
pinMode(atPin, INPUT);
pinMode(thermo_vcc_pin, OUTPUT);
pinMode(thermo_gnd_pin, OUTPUT);
digitalWrite(thermo_vcc_pin, HIGH);
digitalWrite(thermo_gnd_pin, LOW);
Wire.begin();
SeeedOled.init(); //initialze SEEED OLED display.
SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner.
SeeedOled.setNormalDisplay(); //Set display to Normal mode.
SeeedOled.setPageMode(); // Set addressing mode to Page Mode.
SeeedOled.setBrightness(255);
SeeedOled.setTextXY(0, 0);
SeeedOled.putString("InterC Temp:");
SeeedOled.setTextXY(2, 0);
SeeedOled.putString("Intake Temp:");
SeeedOled.setTextXY(4, 0);
SeeedOled.putString("FanSpeed:");
SeeedOled.setTextXY(6, 0);
SeeedOled.putString("EGT Temp:");
}
void loop() {
readTemp(); // Read Inter-cooler Temperature.
readTemp1(); // Read Ambient Air Temperature.
egt = thermocouple.readCelsius(); // Read the Exhaust Gas Temperature (EGT).
SeeedOled.setTextXY(0, 12);
SeeedOled.putNumber(intertemp);
SeeedOled.setTextXY(2, 12);
SeeedOled.putNumber(AT);
SeeedOled.setTextXY(4, 12);
SeeedOled.putNumber(fanOLED);
SeeedOled.setTextXY(6, 12);
SeeedOled.putNumber(egt);
delay(500);
if (egt > egttempMax) { // if EGT temperature is higher that temp max turn on red LED.
digitalWrite(led, HIGH); // turn on Red LED.
} else {
digitalWrite(led, LOW); // turn off red LED.
}
if (egt <= egttempMax) { // If EGT temp is below egttempMax Light Green LED.
digitalWrite(led1, HIGH);
} else {
digitalWrite(led1, LOW);
}
if (intertemp < (AT + mindiffTemp)) { // If Intercooler is less than Ambient air temperature Stop FAN.
fanSpeed = 0;
digitalWrite(fan, LOW);
}
else if ((intertemp >= (AT + mindiffTemp)) && (intertemp <= (AT + maxdiffTemp))) { // If intercooler is above ambient temperature PLUS mindiffTemp spin fan.
fanSpeed = map(intertemp, AT + mindiffTemp, AT + maxdiffTemp, 15, 255); // the actual speed of fan.
fanOLED = map(intertemp, AT + mindiffTemp, AT + maxdiffTemp, 0, 100); // speed of fan to display on OLED.
analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed.
}
else if (intertemp > (AT + maxdiffTemp)) {
analogWrite(fan, 255);
}
}
void readTemp() { // get the temperature and convert it to celsius.
intertemp = analogRead(intertempPin) * 0.48828125;
}
void readTemp1() {
AT = analogRead(atPin) * 0.48828125;
}
[/code]