Maintenance: Project Hub will be unavailable on Wednesday 25 (9AM to 6PM CET) while we deploy critical improvements
Components and supplies
52mm Triple Gauge Kit Oil Temp Water Temp Temperature Oil Pressure Car Meter
Nextion Enhanced NX4024K032 - Generic 3.2'' HMI Touch Display
Nokia 5110 LCD display $2
Arduino UNO
Oil Pressure/Temperature Temp Gauge Filter Sandwich Plate Sensor 1/8 NPT
Tools and machines
Soldering iron (generic)
Project description
Code
Nextion HMI code
properties
https://nextion.itead.cc/download.html
1inary file (no preview
Nextion HMI code
properties
https://nextion.itead.cc/download.html
1inary file (no preview
Arduino code for Nokia LCD display
arduino
84*48 LCD Module White Backlight Adapter PCB for Nokia 5110 Arduino
1#include "U8glib.h" 2 3#define backlight_pin 9 4int piezoPin = 5 8; //8 digital pin the piezo buzzer is attached for alarm. 6const int oiltemppin 7 = A1; //analog pin 8const int oilpressurepin = A2; //oil spacer temp and 9 pressure 10const int watertemppin = A3; // fitted in water hose after thermostat 11const 12 int voltpin = A4; // from acc 13const int fuelpin = A5; //from 14 dash fuel gauge 15; 16 17int TA = 130; //OilTmp alarm level over 130 18float 19 OA = 1.5; //OilPres alarm level under 1.5 20int WA = 100; //WaterTmp alarm 21 level over 100 22float VA = 12.0; //Volts alarm under 12.0v 23float FA = 5; 24 //Fuel alarm under 10 25 26U8GLIB_PCD8544 u8g(13,11, 7, 5, 6); // CLK=13, 27 DIN=11, CE=7, DC=5, RST=6 28 29void draw(void) { 30 float oiltempres = analogRead(oiltemppin);//resistance 31 value (432.667-Resistance)/1.75 32 double oiltemp = (432.667 - oiltempres) 33 /1.80;// 50c=347ohm 60=324 70=312 80c= 95c= 110= 120= 34 35 float 36 watertempres = analogRead(watertemppin);//resistance value (350.124-Resistance)/1.25 37 38 double watertemp = (350.124 - watertempres) /1.25;// 40c=297ohm 50=287 60=276 39 70=263 80=250 90=233 fan on 40 41 float oilpresres = analogRead(oilpressurepin);// 42 1= 2= 2.5=170 3=195 4=227 5=258 6=280 12.1v 43 float oilpressure = (98.5 44 - oilpresres) / -31.098; // 45 if (oilpressure < 0) {oilpressure = 0;} 46 47 48 float volts = analogRead(voltpin) / 65.0; //65 49 float fuel = analogRead(fuelpin) 50 / 2.0; 51 52 analogWrite(backlight_pin,20); /* Set the Backlight intensity 53 */ 54 55 u8g.setFont(u8g_font_profont11); // select font 56 u8g.drawStr(0, 57 8, "OilTmp: "); // put string of display at position X, Y 58 u8g.drawStr(0, 59 17, "OilPres: "); 60 u8g.drawStr(0, 26, "WtrTmp: "); 61 u8g.drawStr(0, 35, 62 "Volts: "); 63 u8g.drawStr(0, 44, "Fuel: "); 64 65 u8g.setPrintPos(55, 66 8); // set position 67 u8g.print(oiltemp, 0); 68 u8g.drawStr(80, 8, "c "); 69 70 if (oiltemp > TA) {u8g.drawStr(50, 8, "# ");tone(piezoPin, 500,3000);analogWrite(backlight_pin,250);} 71 //tone(pin,freq,duration) 72 73 u8g.setPrintPos(55, 17); 74 u8g.print(oilpressure, 75 1); 76 u8g.drawStr(80, 17, "% "); 77 if ((oilpressure < OA)&(volts > 13.0)) 78 {u8g.drawStr(50, 17, "# ");tone(piezoPin, 1000,3000);analogWrite(backlight_pin,250);} 79 80 81 u8g.setPrintPos(55, 26); 82 u8g.print(watertemp, 0); 83 u8g.drawStr(80, 26, 84 "c "); 85 if (watertemp > WA) {u8g.drawStr(50, 26, "# ");tone(piezoPin, 1500,3000);analogWrite(backlight_pin,250);} 86 87 88 u8g.setPrintPos(55, 35); 89 u8g.print(volts, 1); 90 u8g.drawStr(80, 35, 91 "v "); 92 if (volts < VA) {u8g.drawStr(50, 35, "# ");tone(piezoPin, 2500,3000);analogWrite(backlight_pin,250);} 93 94 95 u8g.setPrintPos(55, 44); 96 u8g.print(fuel, 0); 97 u8g.drawStr(80, 44, "l 98 "); 99 if ((fuel < FA)& (oilpressure > 1)) {u8g.drawStr(50, 44, "# ");tone(piezoPin, 100 3000,1000);analogWrite(backlight_pin,250);} 101 102 //used for testing only 103 104 //u8g.setPrintPos(60, 44); 105 //u8g.print(fuel, 0); 106 //u8g.setPrintPos(30, 107 44); 108 //u8g.print(oilpresres, 1); 109 //u8g.setPrintPos(5, 44); 110 // u8g.print(watertempres, 111 0); 112} 113 114void setup(void) { 115 analogWrite(backlight_pin,20); /* Set the 116 Backlight intensity */ 117} 118 119void loop(void) { 120 u8g.firstPage(); 121 122 do { 123 draw(); 124 } while( u8g.nextPage() ); 125 delay(1000); // update 126 every 1000 = 1 sec 127}
Arduino code for Nokia LCD display
arduino
84*48 LCD Module White Backlight Adapter PCB for Nokia 5110 Arduino
1#include "U8glib.h" 2 3#define backlight_pin 9 4int piezoPin = 8; //8 digital pin the piezo buzzer is attached for alarm. 5const int oiltemppin = A1; //analog pin 6const int oilpressurepin = A2; //oil spacer temp and pressure 7const int watertemppin = A3; // fitted in water hose after thermostat 8const int voltpin = A4; // from acc 9const int fuelpin = A5; //from dash fuel gauge 10; 11 12int TA = 130; //OilTmp alarm level over 130 13float OA = 1.5; //OilPres alarm level under 1.5 14int WA = 100; //WaterTmp alarm level over 100 15float VA = 12.0; //Volts alarm under 12.0v 16float FA = 5; //Fuel alarm under 10 17 18U8GLIB_PCD8544 u8g(13,11, 7, 5, 6); // CLK=13, DIN=11, CE=7, DC=5, RST=6 19 20void draw(void) { 21 float oiltempres = analogRead(oiltemppin);//resistance value (432.667-Resistance)/1.75 22 double oiltemp = (432.667 - oiltempres) /1.80;// 50c=347ohm 60=324 70=312 80c= 95c= 110= 120= 23 24 float watertempres = analogRead(watertemppin);//resistance value (350.124-Resistance)/1.25 25 double watertemp = (350.124 - watertempres) /1.25;// 40c=297ohm 50=287 60=276 70=263 80=250 90=233 fan on 26 27 float oilpresres = analogRead(oilpressurepin);// 1= 2= 2.5=170 3=195 4=227 5=258 6=280 12.1v 28 float oilpressure = (98.5 - oilpresres) / -31.098; // 29 if (oilpressure < 0) {oilpressure = 0;} 30 31 float volts = analogRead(voltpin) / 65.0; //65 32 float fuel = analogRead(fuelpin) / 2.0; 33 34 analogWrite(backlight_pin,20); /* Set the Backlight intensity */ 35 36 u8g.setFont(u8g_font_profont11); // select font 37 u8g.drawStr(0, 8, "OilTmp: "); // put string of display at position X, Y 38 u8g.drawStr(0, 17, "OilPres: "); 39 u8g.drawStr(0, 26, "WtrTmp: "); 40 u8g.drawStr(0, 35, "Volts: "); 41 u8g.drawStr(0, 44, "Fuel: "); 42 43 u8g.setPrintPos(55, 8); // set position 44 u8g.print(oiltemp, 0); 45 u8g.drawStr(80, 8, "c "); 46 if (oiltemp > TA) {u8g.drawStr(50, 8, "# ");tone(piezoPin, 500,3000);analogWrite(backlight_pin,250);} //tone(pin,freq,duration) 47 48 u8g.setPrintPos(55, 17); 49 u8g.print(oilpressure, 1); 50 u8g.drawStr(80, 17, "% "); 51 if ((oilpressure < OA)&(volts > 13.0)) {u8g.drawStr(50, 17, "# ");tone(piezoPin, 1000,3000);analogWrite(backlight_pin,250);} 52 53 u8g.setPrintPos(55, 26); 54 u8g.print(watertemp, 0); 55 u8g.drawStr(80, 26, "c "); 56 if (watertemp > WA) {u8g.drawStr(50, 26, "# ");tone(piezoPin, 1500,3000);analogWrite(backlight_pin,250);} 57 58 u8g.setPrintPos(55, 35); 59 u8g.print(volts, 1); 60 u8g.drawStr(80, 35, "v "); 61 if (volts < VA) {u8g.drawStr(50, 35, "# ");tone(piezoPin, 2500,3000);analogWrite(backlight_pin,250);} 62 63 u8g.setPrintPos(55, 44); 64 u8g.print(fuel, 0); 65 u8g.drawStr(80, 44, "l "); 66 if ((fuel < FA)& (oilpressure > 1)) {u8g.drawStr(50, 44, "# ");tone(piezoPin, 3000,1000);analogWrite(backlight_pin,250);} 67 68 //used for testing only 69 //u8g.setPrintPos(60, 44); 70 //u8g.print(fuel, 0); 71 //u8g.setPrintPos(30, 44); 72 //u8g.print(oilpresres, 1); 73 //u8g.setPrintPos(5, 44); 74 // u8g.print(watertempres, 0); 75} 76 77void setup(void) { 78 analogWrite(backlight_pin,20); /* Set the Backlight intensity */ 79} 80 81void loop(void) { 82 u8g.firstPage(); 83 do { 84 draw(); 85 } while( u8g.nextPage() ); 86 delay(1000); // update every 1000 = 1 sec 87}
MR2 Arduino code for Nextion display ver2
arduino
1#include "Nextion.h" 2 3NexGauge pointer1 = NexGauge(0, 3, "z0"); //(Page?,ID,"name") 4NexGauge pointer2 = NexGauge(0, 4, "z1"); 5 6NexProgressBar pb1 = NexProgressBar(0, 9, "pb1"); //volts page0 7NexProgressBar pb2 = NexProgressBar(0, 5, "pb2"); //oil pressure page0 8NexProgressBar pb3 = NexProgressBar(0, 10 , "pb3"); //Fuel page0 9 10NexProgressBar pb6 = NexProgressBar(2, 1, "pb6");//oil pressure page2 11NexProgressBar pb7 = NexProgressBar(2, 2, "pb7");//oil temp page2 12NexProgressBar pb8 = NexProgressBar(2, 3, "pb8");//water temp page2 13NexProgressBar pb9 = NexProgressBar(2, 11, "pb9");//volts page2 14 15NexText t6 = NexText(0, 7, "t6"); // oil pressure 16NexText t7 = NexText(0, 8, "t7"); // oil temp 17NexText t8 = NexText(0, 9, "t8"); // water temp 18NexText t9 = NexText(0, 10, "t9"); // volts 19NexText t10 = NexText(0, 11, "t10"); //fuel 20NexText t11 = NexText(0, 12, "t11"); // min oil pressure 21NexText t12 = NexText(0, 13, "t12"); // max oil pressure 22NexText t14 = NexText(0, 13, "t14"); //oiltemp max 23NexText t15 = NexText(0, 13, "t15"); //watertemp max 24NexText t20 = NexText(1, 18, "t20"); //Alarm 25 26char ot[100] = {0}; //oiltemp 27char op[100] = {0}; //oilpress 28char wt[100] = {0}; //watertemp 29char vo[100] = {0}; //volts 30char fu[100] = {0}; //fuel 31char opmax[100] = {0}; //oilpressmax 32char opmin[100] ={0}; //oilpressmin 33char otmax[100] = {0}; //oiltempmax 34char wtmax[100] = {0}; //watertempmax 35String alarm = "";String alarm1 = "";String alarm2 = ""; 36String alarm3 = "";String alarm4 = "";String alarm5 = ""; 37String alarm6 = "";String alarm7 = "";int al=0;// page 0 alarm @ 38 39int piezoPin = 8; //8 digital pin the piezo buzzer is attached for alarm. 40const int oiltemppin = A0; //analog pin 41const int oilpressurepin = A1; //oil spacer temp and pressure 42const int watertemppin = A2; // fitted in water hose after thermostat 43const int voltpin = A4; // from acc 44const int fuelpin = A5; //from dash fuel gauge 45 46int TA = 150; //OilTmp alarm level over 130 47float OA = 1.0; //OilPres alarm level under 1.5 48int WA = 110; //WaterTmp alarm level over 100 49float VA = 11.8; //Volts alarm under 12.0v 50float FA = 10; //Fuel alarm under 10 51 52float watertemp=30,watertempmax=20,v1,volts=10,fuel; 53float oiltemp=30,oiltempmax=20,otr,oilTempRes=30,waterTempRes=30; 54float oilpressure,oilpressmax = 0,oilpressmin = 10; 55 56boolean setComponentText(String component, String txt){ 57 String componentText = component + ".txt=\\"" + txt + "\\"";//Set Component text for float to txt 58 sendCommand(componentText.c_str());} 59 60void setup() { 61 nexInit(); 62} 63 64void loop() { 65calc(); 66} 67 68void calc(void) { 69 70 const float filterCoeff = 0.3; 71 float rawvolts = analogRead(voltpin) / 65.0; //65 72 volts = volts + ((rawvolts - volts) * filterCoeff); 73 float voltcorrection = (14.2 - volts) * 1.5;//14.2 1.5 74 75 float rawoilTempRes = analogRead(oiltemppin);//resistance value *********************************OIL TEMP**************************** 76 oilTempRes = oilTempRes + ((rawoilTempRes - oilTempRes) * filterCoeff); 77 78 // 50c=347ohm 60=324 70=312 80c= 95c= 110= 120= 130 79 //test use only 24=450 30=420 40=400 50=360/840 60=774 70c = 751ohm 75=740 80c =730 95c= 65c=800 14.5 volts 80 //double oiltemp = oilTempRes; 81 //if (oilTempRes < 500) {oilTempRes = oilTempRes * 2.3;} 82 83 double oiltemp = (525 - oilTempRes)/2.2 - voltcorrection;//Oil y=1024+-3.5x 1.9 = 95 525 2.6 84 if (oiltempmax < oiltemp&&volts>13.5) {oiltempmax = oiltemp;}//max oil temp 85 86 float rawwaterTempRes = analogRead(watertemppin);//resistance value ***************************WATER TEMP*************************** 87 waterTempRes = waterTempRes + ((rawwaterTempRes - waterTempRes) * filterCoeff); 88 // to test resistance value 24C=448 40c=437 50=428 60=405 65=380 70=367 75=360 80=355 82=317 85=315 90= 290 fan on volts 14.5 89 //float watertemp = waterTempRes; 90 91 double watertemp = ((520 - waterTempRes)/3.1) - voltcorrection ;//Water temp =(530-B8)/2.3 2.7 = 90 525/2.6 92 if (watertempmax < watertemp&&volts>13.5) {watertempmax = watertemp;}//max watertemp 93 94 float oilpresres = analogRead(oilpressurepin);// 1= 2= 2.5=170 3=195 4=227 5=258 6=280 12.1v ************OIL PRESSURE******* 95 float oilpressure = (120.5 - oilpresres) / -31.098; //oilpressure = (120.5 - oilpresres) / -31.098; 96 if (oilpressmax < oilpressure) {oilpressmax = oilpressure;}//max oil pressure 97 if ((oilpressure >= 0)&&(oilpressmax > 3)&&(oilpressmin > oilpressure)) {oilpressmin = oilpressure;}//min oil pressure 98 if (oilpressure <= 0) {oilpressure = 0;}// when off and cold reads negative value this set to zero 99 100 float rawfuel = 100 - analogRead(fuelpin) / 3.6; //90 is half 60 is full 101 fuel = fuel + ((rawfuel - fuel) * filterCoeff); 102 103 // Alarms last highest prority 104 alarm = " ";alarm1=" ";alarm2=" ";alarm3=" ";alarm4=" ";alarm5=" ";alarm6=" ";al=0; 105 if ((fuel < FA)& (oilpressure > 1)) {alarm = "Fuel low";alarm6 ="LOW";}//tone(piezoPin, 3000,1000);} 106 if (volts < VA) {alarm = "Battery volts low";alarm4 ="Alarm";}//tone(piezoPin, 2500,3000);al=1;} 107 if (oiltemp > TA) {alarm = "Oil Temp High";alarm2 ="Alarm"; tone(piezoPin, 1000,100);al=1;}//tone(pin,freq,duration) 108 if (watertemp > WA) {alarm = "Water Temp High";alarm3 ="Alarm";tone(piezoPin, 3000,100);al=1;} 109 if ((oilpressure < OA)&(volts > 13.4)) {alarm = "Oil Pressure Low";alarm1 ="Alarm";tone(piezoPin, 50,500);al=1;} 110 if (al>0){alarm5 = "Alarm";} 111 112 int poiltemp;//pointer oiltemp gauge 113 poiltemp = oiltemp; 114 pointer1.setValue(poiltemp); 115 pointer2.setValue(watertemp); 116 117 //int scaled_value = map(oilpressure, act min value, act max value, 0, 100); // always map value from 0 to 100 118 119 int vopb1 = map(v1, 10, 16, 0, 100); 120 pb1.setValue(vopb1);//volts page 0 121 122 int oppb2 = map(oilpressure, 0, 7, 0, 100);//bar reads 0-100% 123 pb2.setValue(oppb2); //oil pressure p0 124 125 int fupb3 = map(fuel, 0, 100, 0, 100); 126 pb3.setValue(fupb3);//fuel p0 127 128 int oppb6 = map(oilpressure, 0, 7, 0 , 100); 129 pb6.setValue(oppb6); // oil pressure p2 130 131 int otpb7 = map(oiltemp, 0, 150, 0, 100); 132 pb7.setValue(otpb7); // oiltemp p2 133 134 int otpb8 = map(watertemp, 0, 150, 0, 100); 135 pb8.setValue(otpb8); // water temp p2 136 137 int vopb9 = map(v1, 10, 16, 0, 100); 138 pb9.setValue(vopb9);//volts page 2 139 140 itoa(oilpressmin,opmin,10); 141 itoa(oilpressmax,opmax,10); 142 itoa(oiltemp,ot,10); 143 itoa(oiltempmax,otmax,10); 144 itoa(watertemp,wt,10); 145 itoa(watertempmax,wtmax,10); 146 itoa(fuel,fu,10 ); 147 148 setComponentText("t6", String(oilpressure).c_str());//gives decimal places 149 t7.setText(ot); // oil temp p0,p1,p2 150 t8.setText(wt); // water temp p0,p1,p2 151 setComponentText("t9", String(volts).c_str()); 152 t10.setText(fu); // fuel % p0 153 t11.setText(opmin); //oilpressure max p1 154 t12.setText(opmax); //oilpressure min p1 155 t14.setText(otmax); //oiltemp max p1 156 t15.setText(wtmax); //watertemp max p1 157 setComponentText("t20", alarm);//alarm text variable 158 setComponentText("w1", alarm1);setComponentText("w2", alarm2);setComponentText("w3", alarm3); 159 setComponentText("w4", alarm4);setComponentText("w5", alarm5);setComponentText("w6", alarm6); 160} 161 162
Downloadable files
Sketch of input board
Voltage divider to drop car 12-15v levels to arduino input 5v with zener protection for any voltage spikes.
Sketch of input board
Sketch of input board
Voltage divider to drop car 12-15v levels to arduino input 5v with zener protection for any voltage spikes.
Sketch of input board
Comments
Only logged in users can leave comments