New member, question about an automotive gauge

Status
Not open for further replies.

2_Wheeler

Member
I've been working on designing an automotive oil temperature gauge that would incorporate air temperature and humidity via a DHT22 sensor. The oil temperature is measured by a General Motors OEM thermistor. It will output to a 1.3" 128x64 OLED using I2C. The display will alternate between oil temp/air temp/humidity and heat index. I've designed a housing using some 3D printer software.

I have some code for the Arduino using the above sensors but have not integrated the OLED output yet. I saw a Teensy YouTube video and joined here to learn more. My current version relies on an Arduino Uno remotely mounted from the gauge. The Teensy is so small it could fit inside a gauge housing, so I thought I'd look into this before doing more work on the project. I'm not locked in to the OLED, but of course need something small enough to fit inside a 50mm opening.

I'm going to be looking at some tutorials but thought maybe I could get some advice as to if this is a feasible project.

UPDATE: I had a successful bench test for all desired functions. See post #15 for the final code
 
Last edited:
I've been doing some reading here and have a question after reading this thread (not sure if it is OK to post on old threads here):
https://forum.pjrc.com/threads/25128-teensy-3-1-5V-output

Regarding 6 feet of cable, that's a pretty long distance to send signals. The pins on Teensy and also on a PIC are meant to drive relatively short wires, pretty much on the same circuit board or to close-by parts.

At least 2 types of problems come up when sending signals over long distances.

#1: Ground differences between the 2 locations can cause big problems. The pins on a Teensy or PIC are not meant to handle negative voltages, which can happen if the grounds differ slightly. Teensy 3.1 is 5V tolerant, so it can handle a 3.3V signal that's up to 1.7V too high.

#2: Long wires tend to have signal reflections that can cause stress or damage to the parts, not to mention simply causing unreliable results.

Usually "long" wires are driven by special transceiver chips. These chips give you 3 things. They're able to handle a wider "common mode range", or signals that are slightly below ground or above the power, due to the 2 sides not having exactly the same ground. They typically have some sort of slew rate control, which limits signal reflections and helps prevent radio frequency emissions. They also often have some sort of design for impedance matching (often you supply a resistor) to the cable, which *really* helps give excellent signal quality. Some chips, like the RS-485 ones, transmit the signal on a pair of wires and receive it as a difference, which gives you incredible resilience to noise and interference. Some others, like RS-232, use a wider voltage range.

But adding transceiver chips means more parts, more work, more cost and more complexity. For 6 feet on a non-critical project, you can probably "get away" with just connecting the pins to a cable. I would recommend at least connecting 100 ohm resistors between the pins and the wires. That will give you a little better impedance matching, and if things go horribly wrong (like accidentally shorting wires to stuff), some impedance might limit the current into the chip and lessen the odds of destroying it.

My sensors will be at the front of the car about 5-6 feet from the gauge. Additionally, the coolant temp sensor is designed to operate on a "typical voltage supply" of 5V. I don't see a 5V out pin on the Teensy. Here's the datasheet for the sensor:
http://pe-ltd.com/assets/coolant_temp.pdf

In the testing I've done with this on my Arduino Uno, I used a pair of resistors (2.2K and 550K) to get the proper reading at room temp. This was with about a 6" pigtail connecting the sensor to my breadboard. The Uno puts out 5V to the sensor.

The DHT22 air temp and humidity sensor will operate OK on 3.3V, so this is not as much of a concern:
https://cdn-shop.adafruit.com/datasheets/DHT22.pdf

I suppose I can test it with the Arduino on the 3.3V output there, as well as using some longer wiring.
 
Update-
I used two 6' strands of 18 gauge automotive TXL wire and the reading was within 1 degree of ambient.

I then rewired the board to run the sensor on 3.3V. I had to change the resistor value in the formula from 10K to 4.3K but it then reported an accurate temperature.

I tested both by heating the tip of the thermistor with a soldering iron and watched the temperature climb. When I was testing the 5V setup, I also placed it in a bottle of ice water and it dropped accordingly.

Looks like it will be usable with the Teensy. :D

EDIT: Outdated code removed
 
Last edited:
The Teensy doesn't have a 5V reg, so normaly setup would be to use some form of regulator/switch mode system to convert 12V to 5V on the Vin pin and then tap that to power any 5V sensors, converting any outputs that would be an issue.
 
Thanks for the advice. It looks like I can operate on 3.3V OK.

I'm planning on having a 6 pin connector at the rear of the gauge. At this point it will be as follows:
1) 12V + in
2) Ground
3) Board ground (to coolant sensor)
4) Air temp/humidity sensor data wire
5) Board ground (to air temp sensor)
6) 3.3V output to both sensors

The 4 wires to the OLED would be internal.

I read an "instructable" that suggested using the power supply from an old cell phone charger as an economical means of obtaining 5V from 12V. The only problem may be fitting it into the housing.

This is not an elaborate setup, so I'm thinking the Teensy LC board would work OK for this.
 
Along with a rugged 12V-5V conversion process you may need to shield those sensor wires and/or put some filters on them. Under the bonnet is a very hostile environment RF wise if you have spark plugs running so may be worth dragging a test lashup of the two sensors out to the car and confirming they do in fact work under the bonnet without to many glitches. Also suggest having a different cable for power in and sensors out unless you have a plug on the far end. A plug with three tails out is ok, a plug with three tails where one tail is hard wired to the car is going to be a pain.
 
Along with a rugged 12V-5V conversion process you may need to shield those sensor wires and/or put some filters on them. Under the bonnet is a very hostile environment RF wise if you have spark plugs running so may be worth dragging a test lashup of the two sensors out to the car and confirming they do in fact work under the bonnet without too many glitches. Also suggest having a different cable for power in and sensors out unless you have a plug on the far end. A plug with three tails out is ok, a plug with three tails where one tail is hard wired to the car is going to be a pain.
Thanks for the advice. I will give that a try when the rest of my parts get here- have to get the car running also LOL.

I am now planning on segregating the power in/sensor out into two different connectors. I'm laying out a 3D printable 52mm gauge housing w/ an internal slot and rear USB opening. The plan is for it to accept a 1.57mm perfboard so the Teensy could be mounted on the perfboard internally and accessed via the USB for off-car programming. While I'm not planning to do any programming while the gauge is in the car powered by 12V to 5V, I'll likely disconnect (cut the pads) the USB and board power inlet to avoid any mishaps. Here's a screenshot of the front and rear:

52mm_both.jpg
 
Last edited:
I picked up a 12V to USB adapter at the Dollar Tree (everything is $1) and took it apart. The board inside is like 30mm x 15mm, and once the USB port was removed it was fairly simple to solder on some 22G wires for 12V in, Ground, and 5V out. I metered it and got about 5.1V out. The unit is rated for 1 amp. It should easily fit within the above housing under the LC board I'm planning on using.
 
BlackMagicSwami, can you please edit your post to make a bit more sense or it'll be assumed you are not a human and be deleted as spam
 
BlackMagicSwami, can you please edit your post to make a bit more sense or it'll be assumed you are not a human and be deleted as spam

Reported some as SPAM already (and others have gone missing) - they were not thread responsive - and not clear as to what the point was . . . that's the only common element to many postings ... a swarm all in the last few hours . . .
 
Thanks for helping to keep the thread clean.

It occurs to me that I could if need be tap the incoming 5V and run that to the coolant sensor. So long as it is on the same ground, wouldn't the output (resistance) be correct with the original resistor formula? I'm new to this stuff, but since this sensor does not output a voltage it seems like this should work. I like the idea of running a sensor designed for 5V on 5V.
 
DHT22 added to sketch

My DHT22 air temp and humidity sensor arrived today and the next step has been completed. I have now bench tested both sensors on an Arduino Uno and they are within .09 degree F of each other. The DHT worked OK on the Arduino 3.3V pin.

I've ordered a Teensy LC and a set of the prototype housings shown above. I have a revision I may try that incorporates internal rods from the front part that exit from the rear of the gauge. They would serve two purposes, one to hold the gauge together and the other to allow a u-bracket to mount the gauge via some 3mm standoffs. These would also allow use of a 48mm ID o-ring to seal the housing where it joins, but I don't see that as critical.

The next challenge will be incorporating the OLED display. It has not arrived yet.

Something else I'm studying is how to dim the OLED for night use. It may not be needed or even possible based upon preliminary research.

EDIT: Outdated code removed
 
Last edited:
Would need to know more about the temp sensor design to know how if it would be better running of 5V or 3.3V. If it's truly presenting a variable resistance that you measure then using the reference circuit powered with 3.3V should allow you to also use the same math since the proportions are the same.

I think dimming the low end OLEDs is a case of fitting some sort of flip down sunglasses to them, though playing with the drive hardware may be possible depending on the design. Would certainly suggest having spares if doing so given the out of spec operation intended.
 
More success!

The OLED arrived today and I learned about matching the code I had so it would display on the OLED as I wanted it to. I'm sure what is below is not perfect, but it gets the job done so far. My car is still under repair so I can't do any real world testing as yet, and I won't have the gauge housing until next week..

It's been a learning experience. I ended up using simpler code for the GM sensor and segregating all outputs onto their own screen- the original DHT file I used had all three on one screen. I was able to make the data font large (42 point) and the title font small (11 point). It should be easily readable when in place on my A-pillar. I reduced the output down to no decimal places since I won't need that while driving.

I spot checked the GM sensor using a pot of boiling water and a manual thermometer and it appears to be spot on. I measured the water after it was off the stove and the thermometer read 200 while the OLED read 199.

As a finishing touch, I downloaded and converted a Dodge logo for a startup file since it is going into one. It's not super-clear, but not bad IMO.

The bulk of the hard part is through! :D

Final code with Dodge logo bitmap:
Code:
// Automotive Oil Temperature, Air temperature, Humidity, and Heat Index meter//
// This was used to read the popular GM coolant sensor 12146312 
// The sensor needed 2.2K and 550 ohm resistors in series
// No display options are used here other than serial print for testing
// This sketch uses analog pin 0 to read the GM sensor
// All temperature output is in Fahrenheit

#include <DHT.h>
#include "U8glib.h"
#include <math.h>         //loads the more advanced math functions

//Data for thermistor
int a;
float temperature;
int B=3975; //B value of the thermistor
float resistance;

#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

//Code for OLED I2C SH1106 display
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);  // Dev 0, Fast I2C / TWI;

// Original humidty meter logo removed, inserted Dodge logo here
const uint8_t logo[] PROGMEM = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0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0xF7, 0xFF, 0xFF,
0x40, 0x10, 0x00, 0xA0, 0x00, 0x08, 0x60, 0x00, 0x50, 0x00, 0x08, 0x60, 0x00, 0x08, 0x00, 0x02,
0xC8, 0x00, 0x02, 0xA0, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02,
0xC0, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0xC0, 0x00, 0x02, 0xA0, 0x00, 0x02, 0x03, 0xF8, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x00, 0x02,
0x00, 0x00, 0x02, 0x41, 0xFF, 0x80, 0x0C, 0x04, 0x01, 0xFF, 0x80, 0x0C, 0x00, 0x00, 0x00, 0x04,
0x80, 0x28, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x40, 0x01, 0x00, 0x20, 0x04, 0x00, 0x00, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00,
0x40, 0x11, 0x00, 0x03, 0xFE, 0x04, 0x1F, 0xF8, 0x01, 0xFF, 0x00, 0x1C, 0x00, 0x20, 0x00, 0x05,
0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08,
0x40, 0x10, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x40, 0x00, 0x01,
0x48, 0x82, 0x20, 0x80, 0x00, 0x12, 0x00, 0x00, 0x80, 0x00, 0x12, 0x00, 0x00, 0x80, 0x00, 0x0B,
0x47, 0x00, 0xC0, 0x80, 0x00, 0x6D, 0xC0, 0x07, 0x00, 0x00, 0x6D, 0xC0, 0x07, 0x30, 0x00, 0x19,
0x21, 0x01, 0x89, 0xFF, 0xF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FF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};


bool first;
float hum=0.0;
float tempF=0.0;
float hIndex=0.0;
float Temp=0.0; //Added coolant sensor output
void dht_test(float * humPerc, float *tempF, float *heatIndex );

void setup(void) {
  Serial.begin(115200);
  dht.begin();
  first = true;
  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
    // picture loop
  u8g.firstPage();  
 //Logo fle displayed here
  do {
    u8g.drawBitmapP( 0, 0, 16, 64, logo);
  } while( u8g.nextPage() );

  dht_test(&hum, &tempF, &hIndex);
}

//This section defines the input and text/data displayed
//All three DHT22 outputs were on one screen
//All were split, renamed, and placed on their own screen
//See loop section below which changes the screens
//Added coolant sensor output as 1st screen

  void OilTemp(float *Temp) { 
  u8g.setFont(u8g_font_fub11);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
  u8g.drawStr( 15, 0, "Oil Temp");
  u8g.setFont(u8g_font_fub42n);
  u8g.setPrintPos( 10, 64);
  u8g.print( *Temp,0);
  }

  void HumMeter1(float *tempF) { 
  u8g.setFont(u8g_font_fub11);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
  u8g.drawStr( 15, 0, "Air Temp");
  u8g.setFont(u8g_font_fub42n);
  u8g.setPrintPos( 10, 64);
  u8g.print( *tempF,0);
  }

  void HumMeter2(float *humPerc) {
  u8g.setFont(u8g_font_fub11);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
  u8g.drawStr( 15, 0, "Humidity %");
  u8g.setFont(u8g_font_fub42n);
  u8g.setPrintPos( 10, 64);
  u8g.print( *humPerc,0);
  }

  void HumMeter3(float *heatIndex) {
  u8g.setFont(u8g_font_fub11);
  u8g.setFontRefHeightExtendedText();
  u8g.setDefaultForegroundColor();
  u8g.setFontPosTop();
  u8g.drawStr( 15, 0, "Heat Index");
  u8g.setFont(u8g_font_fub42n);
  u8g.setPrintPos( 10, 64);
  u8g.print( *heatIndex,0);  
  }
  
void loop(void) {
a=analogRead(0);
 resistance=(float)(1023-a)*10000/a;
   //get the resistance of the sensor
 Temp=1/(log(resistance/10000)/B+1/298.15)-273.15;
   //convert to temperature via datasheet
 Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celsius to Fahrenheit

  
  dht_test(&hum, &tempF, &hIndex);
  if(first)
  {
    first = false;
  }
  else
  {
    
//This section orders and times the screens displayed
//HumMeter1 is air temp, HM2 is humidity, and HM3 is heat index
//Added oil temp as first screen, 1 second longer delay
     u8g.firstPage();  
    do {
      OilTemp(&Temp);
    } while( u8g.nextPage() );
    delay(3000);
    u8g.firstPage();  
    do {
      HumMeter1(&tempF);
    } while( u8g.nextPage() );
    delay(2000);
    u8g.firstPage();  
    do {
      HumMeter2(&hum);
    } while( u8g.nextPage() );
    delay(2000);
     u8g.firstPage();  
    do {
      HumMeter3(&hIndex);
    } while( u8g.nextPage() );
    delay(2000);
    
  }
}

void dht_test(float * humPerc, float *tempF, float *heatIndex ) {
  // Wait a few seconds between measurements.
  delay(2000);
  *humPerc = 0;
  *tempF = 0;
  *heatIndex = 0;
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);


  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  *humPerc = h;
  *tempF = f;
  *heatIndex = hif;
}
 
Congrats on getting things together there. One thing to be aware of is that you have blocking code, as in your loop routine takes multiple seconds to process through. This works, but if you want to have some sort of user interface on the thing the more elegant approach is to have a tight loop which tracks which display mode it's in, and displays that mode before checking if any button pushes/alarm conditions/whatever have happened.

You probably won't need it for this project, but moving forward suggest looking at:
https://learn.adafruit.com/multi-tasking-the-arduino-part-1/overview
https://www.pjrc.com/teensy/td_timing_elaspedMillis.html
 
Thanks for the advice, this is all new stuff to me. From what I've read, the DHT22 sensor is considered a "slow" sensor that needs a couple of seconds of delay. I've had the program running overnight and see from time to time the air temp/humidity/heat index will be 0 for one cycle, then return to normal. I will try to tweak it using the millis functions.
 
Status
Not open for further replies.
Back
Top