I purchased a oil and temp gauge on eBay to mess with. I was going to try to repurpose it as a boost and afr gauge, but the bi-metal strips are not near fast enough to keep up with a boost or afr signal.
starting out I have coded warning lights on both the oil and temp gauge. I havent designed a circuit yet for either sensors though. Still just playing around with it for now.
I have ordered a few Arduino Pro Minis to mount on custom printed boards that will run the gauges. Here is my code, feel free to let me know what I scewed up on or could improve. I am very, very new to programming.
Code: Select all
const int tempPin = A0;
const int batteryPin = A1;
const int oilPin = A2;
const int tempOutput = 9;
const int oilOutput = 10;
const int tempLed = 12;
const int oilLed = 13;
int oilPressure = 0;
int coolantTemp = 0;
float sourceVoltage = 0.00;
void setup() {
Serial.begin(9600);
pinMode(tempLed, OUTPUT);
pinMode(oilLed, OUTPUT);
}
void loop() {
batteryVoltage();
tempGauge();
//oilGauge();
// print the results to the serial monitor:
Serial.print(" ");
Serial.print(sourceVoltage);
Serial.print("V");
Serial.print(" ");
Serial.print(coolantTemp);
Serial.print("*F");
Serial.print(" ");
Serial.print(oilPressure);
Serial.println("psi");
delay(100);
}
void batteryVoltage() {
sourceVoltage = analogRead(batteryPin) * 0.0198817038;
}
void tempGauge() {
// gauge variables
const int sensorCalMin = 0; //minimum sensor value
const int sensorCalMax = 1023; //maximum sensor value
const int valueMin = 15; //gauge value at 120*
const int valueMax = 88; //gauge value at 250*
const int warning = 220; // warning level value
int tempSensor = 0;
int outputValue = 0;
tempSensor = analogRead(tempPin); // read the analog in value:
coolantTemp = map(tempSensor, sensorCalMin, sensorCalMax, 0.00, 300.00); //calibration of temp sensor
outputValue = map(coolantTemp, 120, 250, valueMin, valueMax); //calibration of temp gauge
outputValue = constrain(outputValue, 0, 100); //Gauge limits
analogWrite(tempOutput, outputValue);
if (coolantTemp >= (warning)) // Low warning light
{
digitalWrite(tempLed, HIGH);
}
if (coolantTemp <= (warning - 5)) //Hysteresis for light off
{
digitalWrite(tempLed, LOW);
}
//Serial for DeBug
//Serial.print(" Temp Sensor Value = ");
//Serial.print(tempSensor);
//Serial.print(" output = ");
//Serial.print(outputValue);
}
void oilGauge() {
// gauge variables
const int sensorCalMin = 0; //minimum sensor value
const int sensorCalMax = 1023; //maximum sensor value
const int valueMin = 41; //gauge value at 0psi
const int valueMax = 115; //gauge value at 90psi
const int warning = 15; // warning level value
int oilSensor = 0;
int outputValue = 0;
// read the analog in value:
oilSensor = analogRead(oilPin);
// map it to the range of the analog out:
oilPressure = map(oilSensor, sensorCalMin, sensorCalMax, 0, 90);
outputValue = map(oilPressure, 0, 90, valueMin, valueMin);
outputValue = constrain(outputValue, 0, 120); //Gauge limits
analogWrite(oilOutput, outputValue);
if (oilPressure <= (warning)) // Low warning light
{
digitalWrite(oilLed, HIGH);
}
if (oilPressure >= (warning + 3)) //Hysteresis for light off
{
digitalWrite(oilLed, LOW);
}
}