Hi all,
So I drive a pretty old car, a 1972 Hillman Imp in fact. This one, actually:
Anyways, as you can imagine the equipment is somewhat basic. So, as I intend to embark on some serious engine tuning so, I thought I'd make use of an arduino to improve the condition monitoring a bit!
Basically I intend to use the arduino to monitor the AFR (Air Fuel Ratio) with help from an AEM wideband controller and it's 0-5V analogue output, the induction boost level, the oil pressure/temp and coolant temp. Also, the plan is to use the arduino to control an electric water pump (such as a Davies Craig etc) using a PWM signal and a suitable transistor. At the same time it could be used to control a cooling fan mounted on the radiator.
I'm not decided yet, but I may even use the arduino to control other features in the car, such as the heater, etc.
The display will be mounted on the dash, with the button to change screen being on or near the steering wheel.... easy reach basically.
I am completely new to electronics, apart from a bit of soldering here and there, but I have used matlab at a basic level before, so am familiar with some aspects of coding! It's great fun learning though and quite rewarding when stuff gets working as you want it to!
At present, all the components are a bit cheap simple, in particular the screen. however, in order to ensure that the digital gauges are able to produce accurate and hence useful readings, the screen especially will have to be upgraded so that it is quicker and has less ghosting etc. I only have one pot too at the moment, hence AFR and water temp being hooked up to the same thing!
Here is the progress so far anyway. I have no real questions at the moment as such (but would welcome any advice) but thought I would start this thread so I have a "base" for the inevitable questions that will arise throughout the project.
and my code (excuse a lot of the comments, mainly for my own reference in case I mind blank and forget what is going on!):
/* LCD Screen Attempt 3
With 3 screens, selection of which is controlled by an
incremented variable "screen" and a digital interrupt on pin 2
With PWM powered LED representing water pump
* LCD pins:
RS: Pin 8
EN: Pin 3
D4: Pin 4
D5: Pin 5
D6: Pin 6
D7: Pin 7
* Button is on Pin 2, but interrupt 0
*/
//Include the LCD library
#include <LiquidCrystal.h>
// Initialize an LCD object
LiquidCrystal lcd(8,3,4,5,6,7);
// Define some variables/constants/booleans //
int buttonInt = 0;
int buttonPin = 2;
int ledPin = 13;
int ewpPin = 9;
int waterTemp = 0;
int potIn = 0;
volatile int screen = 0; //Must be volatile when used in int
void setup()
{
//Begin the LCD interface
lcd.begin(16,2);
//Display something at start
lcd.clear();
delay(2000);
lcd.print("Hillman Pimpin'!");
delay(3000);
lcd.clear();
//Pin Modes
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(ewpPin, OUTPUT);
pinMode(waterTemp, INPUT);
//Attach the Interrupt
attachInterrupt(buttonInt, buttonPress, RISING);
//Start water pump at 10% capacity
analogWrite(ewpPin, 255/100);
}
void loop()
{
int potRead = analogRead(potIn);
int waterTemp = potRead / 10;
if (waterTemp < 25)
{
analogWrite(ewpPin, 255/100);
}
if (waterTemp >= 25 && waterTemp < 50)
{
analogWrite(ewpPin, 255/10);
}
if (waterTemp >= 50)
{
analogWrite(ewpPin, 255);
}
if (screen == 0)
{
lcd.setCursor(0,0);
lcd.print("AFR :");
lcd.setCursor(0,1);
lcd.print("Boost :");
float AFR = (potRead / 63.94) + 7;
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(10,0);
if (AFR < 10)
{
lcd.print(" ");
lcd.setCursor(11,0);
}
lcd.print(AFR);
delay(500);
lcd.setCursor(0,0);
}
if (screen == 1)
{
lcd.setCursor(0,0);
lcd.print("Water T:");
lcd.setCursor(0,1);
lcd.print("Oil T:");
float waterT = (potRead / 10);
lcd.setCursor(8,0);
lcd.print(" ");
if (waterT < 100)
{
lcd.setCursor(9,0);
lcd.print(" ");
lcd.setCursor(10,0);
if (waterT < 10)
{
lcd.print(" ");
lcd.setCursor(11,0);
}
}
else
{
lcd.setCursor(9,0);
}
lcd.print(waterT);
delay(500);
lcd.setCursor(0,0);
}
if (screen == 2)
{
lcd.setCursor(0,0);
lcd.print(" Screen 3 ");
lcd.setCursor(0,1);
lcd.print(" ");
}
if (screen == 3)
{
lcd.setCursor(0,0);
lcd.print(" Screen 4 ");
lcd.setCursor(0,1);
lcd.print(" ");
}
}
void buttonPress()
{
/* Debouncing code found using google search, thanks to
"Mikalhart" on the old forum */
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
/* If interrupts come faster than 200ms, assume it's a bounce
and ignore */
if (interrupt_time - last_interrupt_time > 200)
{
screen = ++screen;
if (screen == 4)
{
screen = 0;
}
}
last_interrupt_time = interrupt_time;
}