// 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,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, 0x00, 0xA0, 0x00, 0x07, 0xC0, 0x00, 0x50, 0x00, 0x05, 0x40, 0x00, 0x08, 0x00, 0x02,
0x8E, 0x6E, 0xF2, 0xFF, 0xFF, 0xF7, 0x9F, 0xFF, 0xAF, 0xFF, 0xF2, 0x9F, 0xFF, 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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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
};
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;
}