We brought an old car to use for track days a Toyota MR2 1990.
Not having an OBD port we needed to measure Oil temps and pressure and alarm abnormal values. So decided to use Arduino uno and nokia display getting data from resistive sensors installed in car. Put pic of sensors here.
Next was board for input to Arduino OP = oil pressure OT = oil temp WT water Temp V = volts
This is program used for LCD display
#include "U8glib.h"
#define backlight_pin 9
int piezoPin = 8; //8 digital pin the piezo buzzer is attached for alarm.
const int oiltemppin = A1; //analog pin
const int oilpressurepin = A2; //oil spacer temp and pressure
const int watertemppin = A3; // fitted in water hose after thermostat
const int voltpin = A4; // from acc
const int fuelpin = A5; //from dash fuel gauge
;
int TA = 130; //OilTmp alarm level over 130
float OA = 1.5; //OilPres alarm level under 1.5
int WA = 100; //WaterTmp alarm level over 100
float VA = 12.0; //Volts alarm under 12.0v
float FA = 5; //Fuel alarm under 10
U8GLIB_PCD8544 u8g(13,11, 7, 5, 6); // CLK=13, DIN=11, CE=7, DC=5, RST=6
void draw(void) {
float oiltempres = analogRead(oiltemppin);//resistance value (432.667-Resistance)/1.75
double oiltemp = (432.667 - oiltempres) /1.80;// 50c=347ohm 60=324 70=312 80c= 95c= 110= 120=
float watertempres = analogRead(watertemppin);//resistance value (350.124-Resistance)/1.25
double watertemp = (350.124 - watertempres) /1.25;// 40c=297ohm 50=287 60=276 70=263 80=250 90=233 fan on
float oilpresres = analogRead(oilpressurepin);// 1= 2= 2.5=170 3=195 4=227 5=258 6=280 12.1v
float oilpressure = (98.5 - oilpresres) / -31.098; //
if (oilpressure < 0) {oilpressure = 0;}
float volts = analogRead(voltpin) / 65.0; //65
float fuel = analogRead(fuelpin) / 2.0;
analogWrite(backlight_pin,20); /* Set the Backlight intensity */
u8g.setFont(u8g_font_profont11); // select font
u8g.drawStr(0, 8, "OilTmp: "); // put string of display at position X, Y
u8g.drawStr(0, 17, "OilPres: ");
u8g.drawStr(0, 26, "WtrTmp: ");
u8g.drawStr(0, 35, "Volts: ");
u8g.drawStr(0, 44, "Fuel: ");
u8g.setPrintPos(55, 8); // set position
u8g.print(oiltemp, 0);
u8g.drawStr(80, 8, "c ");
if (oiltemp > TA) {u8g.drawStr(50, 8, "# ");tone(piezoPin, 500,3000);analogWrite(backlight_pin,250);} //tone(pin,freq,duration)
u8g.setPrintPos(55, 17);
u8g.print(oilpressure, 1);
u8g.drawStr(80, 17, "% ");
if ((oilpressure < OA)&(volts > 13.0)) {u8g.drawStr(50, 17, "# ");tone(piezoPin, 1000,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 26);
u8g.print(watertemp, 0);
u8g.drawStr(80, 26, "c ");
if (watertemp > WA) {u8g.drawStr(50, 26, "# ");tone(piezoPin, 1500,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 35);
u8g.print(volts, 1);
u8g.drawStr(80, 35, "v ");
if (volts < VA) {u8g.drawStr(50, 35, "# ");tone(piezoPin, 2500,3000);analogWrite(backlight_pin,250);}
u8g.setPrintPos(55, 44);
u8g.print(fuel, 0);
u8g.drawStr(80, 44, "l ");
if ((fuel < FA)& (oilpressure > 1)) {u8g.drawStr(50, 44, "# ");tone(piezoPin, 3000,1000);analogWrite(backlight_pin,250);}
//used for testing only
//u8g.setPrintPos(60, 44);
//u8g.print(fuel, 0);
//u8g.setPrintPos(30, 44);
//u8g.print(oilpresres, 1);
//u8g.setPrintPos(5, 44);
// u8g.print(watertempres, 0);
}
void setup(void) {
analogWrite(backlight_pin,20); /* Set the Backlight intensity */
}
void loop(void) {
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
delay(1000); // update every 1000 = 1 sec
}
Due to issues with Nokia display getting lighter (shade of grey) poor connection on display. I decided to upgrade to Nextion display, and it looks nicer.
Since the Uno only has one HardwareSerial port (pins 0/1), and it is shared with the USB-Serial UART, it is a pain to debug projects with the Nextion displays so goto page in link and follow instructions this will allow serial connection on pins 10,11.
https://www.reddit.com/r/arduino/comments/4b6jfi/nexconfigh_for_nextion_display_on_arduino_uno/
My hardware connections of the Nextion HID:
- +5V (Red): 5V from arduino board
- TX (Blue): Pin 10 (SoftwareSerial RX)
- RX (Yellow): Pin 11 (SoftwareSerial TX)
- GND (Black): GND of Uno.
Colors are those of the pigtail that came with the display. It came with a Micro USB connector on a tiny breakout board.
Pic of Nextion display in
Comments