THERMOHYGROMETER BY WET AND DRY THERMOMETER WITH LED MATRIX

This is still related to https://arduinoproyek.wordpress.com/thermohygrometer-by-wet-and-dry-thermometer/
so the bluetooth still displayed. You can view the data display on LCD via Bluetooth or view the LED matrix

DS18S20B Heat index matrix

 

#include <OneWire.h>
#include <MaxMatrix.h> //include matrix library
#include <avr/pgmspace.h>
#include <stdlib.h>
int DS18S20_Pin1 = 2; //DS18S20 Signal pin on digital 2
int DS18S20_Pin2 = 3;
//Temperature chip i/o
OneWire ds1(DS18S20_Pin1); // on digital pin 2
OneWire ds2(DS18S20_Pin2);
float a;
float b;
float c;
float d;
float e=2.71828182845904;
float f=0.6687451584;
float g;
float k1=-8.78469475556;
float k2=1.61139411;
float k3=2.33854883889;
float k4=-0.14611605;
float k5=-0.012308094;
float k6=-0.0164248277778;
float k7=0.002211732;
float k8=0.00072546;
float k9=-0.000003582;
#define motorpin 5

const PROGMEM prog_uchar CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // ”
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // ‘
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // –
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B00100100, B00000000, B00000000, B00000000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};

int data = 12; // DIN pin of MAX7219 module
int load = 10; // CS pin of MAX7219 module
int clock = 11; // CLK pin of MAX7219 module
int maxInUse = 8; //change this variable to set how many MAX7219’s you’ll use
MaxMatrix m(data, load, clock, maxInUse); // define module
byte buffer[10];

void setup(void) {
m.init(); // module initialize
m.setIntensity(2); // dot matix intensity 0-15
Serial.begin(9600);
pinMode(motorpin, OUTPUT);
}
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void loop(void) {
int sensorValue0 = analogRead(A0);
if (sensorValue0 <= 100) {
getData1();
}
if (sensorValue0 > 100) {
getData2();
}
}
float getTemp1(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data1[12];
byte addr1[8];
if ( !ds1.search(addr1)) {
//no more sensors on chain, reset search
ds1.reset_search();
return -1000;
}
if ( OneWire::crc8( addr1, 7) != addr1[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr1[0] != 0x10 && addr1[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds1.reset();
ds1.select(addr1);
ds1.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds1.reset();
ds1.select(addr1);
ds1.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data1[i] = ds1.read();
}

ds1.reset_search();

byte MSB = data1[1];
byte LSB = data1[0];
float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

float getTemp2(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data2[12];
byte addr2[8];
if ( !ds2.search(addr2)) {
//no more sensors on chain, reset search
ds2.reset_search();
return -1000;
}
if ( OneWire::crc8( addr2, 7) != addr2[7]) {
Serial.println(“CRC is not valid!”);
return -1000;
}
if ( addr2[0] != 0x10 && addr2[0] != 0x28) {
Serial.print(“Device is not recognized”);
return -1000;
}
ds2.reset();
ds2.select(addr2);
ds2.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds2.reset();
ds2.select(addr2);
ds2.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data2[i] = ds2.read();
}

ds2.reset_search();

byte MSB = data2[1];
byte LSB = data2[0];
float tempRead = ((MSB << 8) | LSB); //using two’s compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;

}

void getData1(){
digitalWrite(motorpin, HIGH);
float temperature1 = getTemp1()-1;
float temperature2 = getTemp2()-1;
float td=temperature1;
float hi;

c=17.502*temperature1/(240.97+temperature1);
d=17.502*temperature2/(240.97+temperature2);
a=6.112*pow(e,c);
b=6.112*pow(e,d);
g=((b-f*(1+0.00115*temperature2)*(temperature1-temperature2))/a)*100;
if(td>26){
hi = k1+k2*td+k3*g+k4*td*g+k5*pow(td,2)+k6*pow(g,2)+k7*pow(td,2)*g+k8*td*pow(g,2)+k9*pow(td,2)*pow(g,2);
}
if(td<=26){
hi = ((0.5*((td*9/5+32)+61.0+(((td*9/5+32)-68.0)*1.2)+(g*0.094)))-32)*5/9;
}
Serial.print(temperature1);
Serial.print(” “);
Serial.print(temperature2);
Serial.print(” “);
Serial.print(g);
Serial.print(” “);
Serial.println(hi);

}

void getData2(){
digitalWrite(motorpin, LOW);
float temperature1 = getTemp1()-1;
float temperature2 = getTemp2()-1;
float td=temperature1;
float hi;

c=17.502*temperature1/(240.97+temperature1);
d=17.502*temperature2/(240.97+temperature2);
a=6.112*pow(e,c);
b=6.112*pow(e,d);
g=((b-f*(1+0.00115*temperature2)*(temperature1-temperature2))/a)*100;
if(td>26){
hi = k1+k2*td+k3*g+k4*td*g+k5*pow(td,2)+k6*pow(g,2)+k7*pow(td,2)*g+k8*td*pow(g,2)+k9*pow(td,2)*pow(g,2);
}
if(td<=26){
hi = ((0.5*((td*9/5+32)+61.0+(((td*9/5+32)-68.0)*1.2)+(g*0.094)))-32)*5/9;
}
char tm[4];
char gm[4];
char him[4];
int tmr=round(td);
int gmr=round(g);
int himr=round(hi);

itoa(tmr,tm,10);
itoa(gmr,gm,10);
itoa(himr,him,10);

Serial.print(temperature1);
Serial.print(” “);
Serial.print(temperature2);
Serial.print(” “);
Serial.print(g);
Serial.print(” “);
Serial.println(hi);

printStringWithShift(“Air temperature: “, 40);
printStringWithShift(tm, 40);
printStringWithShift(” C “, 40);
printStringWithShift(“|| “, 40);
printStringWithShift(“Humidity: “, 40);
printStringWithShift(gm, 40);
printStringWithShift(” % “, 40);
printStringWithShift(“|| “, 40);
printStringWithShift(“Heat Index: “, 40);
printStringWithShift(him, 40);
//printStringWithShift(” % “, 40);
printStringWithShift(” “, 40);

m.shiftLeft(false, true);
resetFunc(); //call reset

//delay(100); //just here to slow down the output so it is easier to read
}

void printCharWithShift(char c, int shift_speed){
if (c < 32) return;
c -= 32;
memcpy_P(buffer, CH + 7*c, 7);
m.writeSprite(maxInUse*8, 0, buffer);
m.setColumn(maxInUse*8 + buffer[0], 0);

for (int i=0; i<buffer[0]+1; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}

void printStringWithShift(char* s, int shift_speed){
while (*s != 0){
printCharWithShift(*s, shift_speed);
s++;
}
}

void printString(char* s)
{
int col = 0;
while (*s != 0)
{
if (*s < 32) continue;
char c = *s – 32;
memcpy_P(buffer, CH + 7*c, 7);
m.writeSprite(col, 0, buffer);
m.setColumn(col + buffer[0], 0);
col += buffer[0] + 1;
s++;
}
}