Buongiorno a tutti. Sono una new entry sia in questo forum che nel mondo arduino.
Nel progetto che voglio realizzare una parte riguarda quello che è scritto nel titolo di questo post.
Il problema è che non riesco a misurare la temperatura min e max. In realtà come si vede dalle immagini allegate la max viene rilevata e memorizzata ma la minima rimane su -0,00.
Dove sbaglio???
scusate in anticipo se il codice è un po' così a...cavolo!!
//Temperatura con sensore dallas+Dht11 e visualizzazione del confort
//
#include <dht11.h>
#include "OneWire/OneWire.h"
#include "dallas-temperature-control/DallasTemperature.h"
#include "EEPROMex.h"
#define DHT11_PIN 4
#define ONE_WIRE_BUS 2
dht11 DHT;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte humid;
byte temp;
float tempDallas;
byte humidInd;
byte tempInd;
char comfColour;
float MIN;
float MAX;
const int reset=10;
int statoreset=0;
//fill the array based on the colour chart
int comf[10][11] = {
'B','B','B','R','R','R','R','R','R','R','\0', //high humid
'B','B','Y','Y','R','R','R','R','R','R','\0',
'B','B','Y','Y','Y','R','R','R','R','R','\0',
'B','B','Y','G','G','Y','Y','R','R','R','\0',
'B','B','Y','G','G','G','Y','R','R','R','\0',
'B','B','Y','G','G','G','Y','Y','R','R','\0',
'B','B','B','Y','Y','G','Y','Y','R','R','\0',
'B','B','B','B','Y','Y','Y','Y','R','R','\0',
'B','B','B','B','B','B','B','R','R','R','\0',
'B','B','B','B','B','B','B','R','R','R','\0', //low humid
}; //
void setup(){
/////////////////Clear EEPROM/////////////////////
/*{
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);
// turn the LED on when we're done
digitalWrite(13, HIGH);
}*/
//////////////////////////////////////////////////
sensors.begin();// inizializza sensore Dallas
Serial.begin(9600);
Serial.println("DHT COMFORT PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println("Humidity (%),\tTemperature (C),\tComfort,\ttMin,\tTMAX");
}
void HumiTemp(){
//get data
int chk;
chk = DHT.read(DHT11_PIN); // READ DATA
humid = DHT.humidity;
MIN = EEPROM.readFloat(1);
MAX = EEPROM.readFloat(2);
sensors.requestTemperatures(); // Send the command to get temperatures
float tempDallas=sensors.getTempCByIndex(0);
//calc indices into the 2d matrix
humidInd =9- humid/10;
if (temp%2==0) //even temp
{
tempInd=(tempDallas/2)-8;
}
else //odd temp
{
tempInd=(tempDallas/2)-7;
}
if (tempInd < 0) tempInd=0;
if (tempInd > 9) tempInd=9;
// get the current value from the array
comfColour = comf[humidInd][tempInd];
// DISPLAY DATA
Serial.print(humid);
Serial.print(",\t\t\t\t");
Serial.print(tempDallas,2);
Serial.print(",\t\t\t");
if (comfColour == 'R')
{
Serial.print("Disconfort");}
if (comfColour == 'G')
{
Serial.print("Confort");}
if (comfColour == 'B')
{
Serial.print("Disconfort");}
if (comfColour == 'Y')
{
Serial.print("Discreto");}
Serial.print(",\t\t");
Serial.print(MIN,2);
Serial.print(",\t");
Serial.println(MAX,2);
if (tempDallas<MIN)
{
MIN=tempDallas;
EEPROM.writeFloat(1,tempDallas);}
if (tempDallas>MAX)
{
MAX=tempDallas;
EEPROM.writeFloat(2,tempDallas);}
}
void loop(){
HumiTemp();
delay(5000);
}//loop