Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
petemnz
Published © GPL3+

Car Sensor monitoring & Alarm

Monitor Oil Temp and Pressure, Water Temp, Voltage, Fuel level. Display on Nextion display or Nokia LCD

IntermediateShowcase (no instructions)6 hours60,325
Car Sensor monitoring & Alarm

Things used in this project

Hardware components

Itead Nextion Enhanced NX4024K032 - Generic 3.2'' HMI Touch Display
×1
Nokia 5110 LCD display $2
×1
52mm Triple Gauge Kit Oil Temp Water Temp Temperature Oil Pressure Car Meter
×1
Oil Pressure/Temperature Temp Gauge Filter Sandwich Plate Sensor 1/8 NPT
×1
Arduino UNO
Arduino UNO
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Sketch of input board

Voltage divider to drop car 12-15v levels to arduino input 5v with zener protection for any voltage spikes.

Code

Nextion HMI code

Properties
https://nextion.itead.cc/download.html
No preview (download only).

MR2 Arduino code for Nextion display ver2

Arduino
#include "Nextion.h"

NexGauge pointer1  = NexGauge(0, 3, "z0");        //(Page?,ID,"name")
NexGauge pointer2  = NexGauge(0, 4, "z1");

NexProgressBar pb1 = NexProgressBar(0, 9, "pb1");   //volts page0
NexProgressBar pb2 = NexProgressBar(0, 5, "pb2");   //oil pressure page0
NexProgressBar pb3 = NexProgressBar(0, 10 , "pb3"); //Fuel page0

NexProgressBar pb6 = NexProgressBar(2, 1, "pb6");//oil pressure page2
NexProgressBar pb7 = NexProgressBar(2, 2, "pb7");//oil temp page2
NexProgressBar pb8 = NexProgressBar(2, 3, "pb8");//water temp page2
NexProgressBar pb9 = NexProgressBar(2, 11, "pb9");//volts page2
 
NexText t6 = NexText(0, 7, "t6");      // oil pressure
NexText t7 = NexText(0, 8, "t7");      // oil temp
NexText t8 = NexText(0, 9, "t8");      // water temp
NexText t9 = NexText(0, 10, "t9");     // volts
NexText t10 = NexText(0, 11, "t10");   //fuel
NexText t11 = NexText(0, 12, "t11");   // min oil pressure
NexText t12 = NexText(0, 13, "t12");   // max oil pressure
NexText t14 = NexText(0, 13, "t14");   //oiltemp max
NexText t15 = NexText(0, 13, "t15");  //watertemp max
NexText t20 = NexText(1, 18, "t20");  //Alarm

char ot[100] = {0};     //oiltemp
char op[100] = {0};     //oilpress
char wt[100] = {0};     //watertemp
char vo[100] = {0};     //volts
char fu[100] = {0};     //fuel
char opmax[100] = {0};  //oilpressmax
char opmin[100] ={0};   //oilpressmin
char otmax[100] = {0};  //oiltempmax
char wtmax[100] = {0};  //watertempmax
String alarm = "";String alarm1 = "";String alarm2 = "";
String alarm3 = "";String alarm4 = "";String alarm5 = "";
String alarm6 = "";String alarm7 = "";int al=0;// page 0 alarm @

int piezoPin = 8;  //8 digital pin the piezo buzzer is attached for alarm.
const int oiltemppin = A0;      //analog pin
const int oilpressurepin = A1;  //oil spacer temp and pressure
const int watertemppin = A2;    // fitted in water hose after thermostat
const int voltpin = A4;         // from acc
const int fuelpin = A5;         //from dash fuel gauge

int TA = 150;      //OilTmp alarm level over 130
float OA = 1.0;    //OilPres alarm level under 1.5
int WA = 110;      //WaterTmp alarm level over 100
float VA = 11.8;   //Volts alarm under 12.0v 
float FA = 10;      //Fuel alarm under 10

float watertemp=30,watertempmax=20,v1,volts=10,fuel;
float oiltemp=30,oiltempmax=20,otr,oilTempRes=30,waterTempRes=30;
float oilpressure,oilpressmax = 0,oilpressmin = 10;

boolean setComponentText(String component, String txt){
    String componentText = component + ".txt=\"" + txt + "\"";//Set Component text for float to txt
    sendCommand(componentText.c_str());}

void setup() {    
    nexInit();   
}

void loop() {
calc();
}

void calc(void) {
 
    const float filterCoeff = 0.3;
    float rawvolts = analogRead(voltpin) / 65.0; //65 
    volts = volts + ((rawvolts - volts) * filterCoeff);
    float voltcorrection = (14.2 - volts) * 1.5;//14.2 1.5
 
    float rawoilTempRes = analogRead(oiltemppin);//resistance value *********************************OIL TEMP****************************
    oilTempRes = oilTempRes + ((rawoilTempRes - oilTempRes) * filterCoeff);
    
    // 50c=347ohm  60=324   70=312   80c=     95c=   110=   120=   130
    //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
    //double oiltemp = oilTempRes;  
    //if (oilTempRes < 500) {oilTempRes = oilTempRes * 2.3;}  
           
    double oiltemp = (525 - oilTempRes)/2.2 - voltcorrection;//Oil y=1024+-3.5x  1.9 = 95  525 2.6
    if (oiltempmax < oiltemp&&volts>13.5) {oiltempmax = oiltemp;}//max oil temp
    
    float rawwaterTempRes = analogRead(watertemppin);//resistance value  ***************************WATER TEMP*************************** 
    waterTempRes = waterTempRes + ((rawwaterTempRes - waterTempRes) * filterCoeff);
    // 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
    //float watertemp = waterTempRes;
    
    double watertemp = ((520 - waterTempRes)/3.1) - voltcorrection ;//Water temp =(530-B8)/2.3 2.7 = 90 525/2.6
    if  (watertempmax < watertemp&&volts>13.5) {watertempmax = watertemp;}//max watertemp
    
  float oilpresres = analogRead(oilpressurepin);// 1=   2=   2.5=170  3=195  4=227  5=258 6=280  12.1v ************OIL PRESSURE*******
  float oilpressure = (120.5 - oilpresres) / -31.098; //oilpressure = (120.5 - oilpresres) / -31.098;
    if  (oilpressmax < oilpressure) {oilpressmax = oilpressure;}//max oil pressure
    if  ((oilpressure >= 0)&&(oilpressmax > 3)&&(oilpressmin > oilpressure)) {oilpressmin = oilpressure;}//min oil pressure
    if  (oilpressure <= 0) {oilpressure = 0;}// when off and cold reads negative value this set to zero
   
  float rawfuel = 100 - analogRead(fuelpin) / 3.6; //90 is half 60 is full
  fuel = fuel + ((rawfuel - fuel) * filterCoeff);

 // Alarms last highest prority
 alarm = "      ";alarm1="      ";alarm2="      ";alarm3="      ";alarm4="      ";alarm5=" ";alarm6=" ";al=0;
   if ((fuel < FA)& (oilpressure > 1)) {alarm = "Fuel low";alarm6 ="LOW";}//tone(piezoPin, 3000,1000);}
   if (volts < VA) {alarm = "Battery volts low";alarm4 ="Alarm";}//tone(piezoPin, 2500,3000);al=1;}
   if (oiltemp > TA) {alarm = "Oil Temp High";alarm2 ="Alarm"; tone(piezoPin, 1000,100);al=1;}//tone(pin,freq,duration)
   if (watertemp > WA) {alarm = "Water Temp High";alarm3 ="Alarm";tone(piezoPin, 3000,100);al=1;}
   if ((oilpressure < OA)&(volts > 13.4)) {alarm = "Oil Pressure Low";alarm1 ="Alarm";tone(piezoPin, 50,500);al=1;}
   if (al>0){alarm5 = "Alarm";}

     int poiltemp;//pointer oiltemp gauge
     poiltemp = oiltemp;
     pointer1.setValue(poiltemp);
     pointer2.setValue(watertemp);
    
   //int scaled_value = map(oilpressure, act min value, act max value, 0, 100); // always map value from 0 to 100
  
    int vopb1 = map(v1, 10, 16, 0, 100);
      pb1.setValue(vopb1);//volts page 0
      
    int oppb2 = map(oilpressure, 0, 7, 0, 100);//bar reads 0-100%
      pb2.setValue(oppb2); //oil pressure p0  
    
    int fupb3 = map(fuel, 0, 100, 0, 100);
      pb3.setValue(fupb3);//fuel p0
   
    int oppb6 = map(oilpressure, 0, 7, 0 , 100);
      pb6.setValue(oppb6); // oil pressure p2

    int otpb7 = map(oiltemp, 0, 150, 0, 100);
      pb7.setValue(otpb7); // oiltemp p2 
      
    int otpb8 = map(watertemp, 0, 150, 0, 100);
      pb8.setValue(otpb8); // water temp p2
       
    int vopb9 = map(v1, 10, 16, 0, 100);
      pb9.setValue(vopb9);//volts page 2
    
    itoa(oilpressmin,opmin,10);
    itoa(oilpressmax,opmax,10);
    itoa(oiltemp,ot,10);
    itoa(oiltempmax,otmax,10);
    itoa(watertemp,wt,10);
    itoa(watertempmax,wtmax,10);
    itoa(fuel,fu,10 );
    
    setComponentText("t6", String(oilpressure).c_str());//gives decimal places
    t7.setText(ot); // oil temp p0,p1,p2
    t8.setText(wt); // water temp p0,p1,p2
    setComponentText("t9", String(volts).c_str());
    t10.setText(fu); // fuel % p0
    t11.setText(opmin); //oilpressure max p1
    t12.setText(opmax); //oilpressure min p1
    t14.setText(otmax); //oiltemp max p1
    t15.setText(wtmax); //watertemp max p1
    setComponentText("t20", alarm);//alarm text variable
    setComponentText("w1", alarm1);setComponentText("w2", alarm2);setComponentText("w3", alarm3);
    setComponentText("w4", alarm4);setComponentText("w5", alarm5);setComponentText("w6", alarm6);
}

Arduino code for Nokia LCD display

Arduino
84*48 LCD Module White Backlight Adapter PCB for Nokia 5110 Arduino
#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
}

Credits

petemnz

petemnz

2 projects • 32 followers

Comments