non riesco a metter il codice lo divido in due:
//Lettura temperatura e umidità
//Paolo prova 6 del 16-02-2013
//This is a re-written DHT11
//DHT stuff in subroutines.
//N.B. "bit" is used in the narrow, computer "1 or 0"
// sense throughout.
//"DHT" from sensor's names: DHT11, DHT22.
//DHT aka Aosong AM2302, and there's an AM2303 which
//seems to be in the same family.
//Comments on this based on Aosong AM2302, aka DHT22, datasheet.
//Believed to generally apply to DHT11 as well, except in the
//case of the DHT11, I believe the second and fourth bytes are
//always zero.
//***N.B.****
//The code WORKS... the comments may not yet be EXACTLY right.
//See the web-page cited above for latest news.
//This code works with a DHT11 humidity/ temperature sensing module
//from nuelectronics.com, complied with ver 0018 of the Arduino environment
//Sensor attached to P4 (nuelectonics shield)/ analog 0, aka digital 14.
//That "module", according to the
//nuelectronics site, and visual inspection simply provides for easy
//connection of an Aosong DHT11 unit to the nuelectronics datalogging
//shield. Only 3 wires are involved: Vcc, ground, and a single data
//line. One of the DHT11's 4 pins goes nowhere.
//You should not need to change anything except the next line to use
//the software with the sensor on a different line, or for a DHT22.
//Just "huffing" on the sensor from deeply filled lungs should show
//a near instant rise in humidity
//#define dht_PIN 0 //no ; here. deprecate ADC0...
//even though we are using it as a digital pin.
//Other parts of code restrict us to using
//ADC0-5, aka D14-19
#define dht_dpin 14 //no ; here. Set equal to channel sensor is on,
//where if dht_dpin is 14, sensor is on digital line 14, aka analog 0
//#define LIGHT_SENSOR_PIN 1
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
byte bGlobalErr; //for passing error code back from complex functions.
byte dht_dat[4]; //Array to hold the bytes sent from sensor.
//int light_intensity = 0;
//unsigned int flip = 0;
void setup(){
//Blink LED to detect hangs
pinMode(13, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2); //Setta dysplay 16 su 2 linee
lcd.print("Realizzato Paolo"); // Scrive su prima riga posizione 0
lcd.setCursor(0, 1); //Setta la sriga sotto x la scrittura
lcd.print("Arduino UNO Test"); //Scrive sulla seconda riga
delay(5000); //Ritardo prima di passare oltre
lcd.setCursor(0, 0); //Setta dove scrivere
lcd.print(" "); //Scrive tutti spazzi per pulire il display
lcd.setCursor(0, 1); //Scrive tutti spazzi per pulire il display
lcd.print(" "); //Scrive tutti spazzi per pulire il display
InitDHT(); //Do what's necessary to prepare for reading DHT
//Serial.begin(9600);
delay(300); //Let system settle
//Serial.println("Humidity and temperature\n\n");
delay(700); //Wait rest of 1000ms recommended delay before
//accessing sensor
} //end "setup()"
void loop(){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
//lcd.setCursor(0, 1);
// print the number of seconds since reset:
//lcd.print("100");
//lcd.print(millis()/1000);
//if ( flip & 1 )
{
digitalWrite(13, HIGH);
// } else {
digitalWrite(13, LOW);
}
//flip++;
// light_intensity=analogRead(LIGHT_SENSOR_PIN);
ReadDHT(); //This is the "heart" of the program.
//Fills global array dht_dpin[], and bGlobalErr, which
//will hold zero if ReadDHT went okay.
//Must call InitDHT once (in "setup()" is usual) before
//calling ReadDHT.
//Following: Display what was seen...
switch (bGlobalErr) {
case 0:
lcd.setCursor(0, 0);
// Serial.print("temperatura e umidita= ");
lcd.print("Temp = gradi");
lcd.setCursor(7, 0);
lcd.print( dht_dat[2], DEC);
//Serial.print(dht_dat[0], DEC);
//Serial.print(".");
//Serial.print(dht_dat[1], DEC);
//Serial.print("% ");
lcd.setCursor(0, 1);
//Every 7 out of 15 times we show humidity, rest temp
// if ((flip % 15) > 7 )
{
lcd.print("Umidita' = %");
lcd.setCursor(11, 1);
lcd.print( dht_dat[0], DEC);
//} else {
//lcd.print("Light = ");
//lcd.setCursor(8, 1);
// lcd.print( light_intensity, DEC);
}
//Serial.print("temperature = ");
//Serial.print(dht_dat[2], DEC);
//Serial.print(".");
//Serial.print(dht_dat[3], DEC);
//Serial.println("C ");
delay(10000);
lcd.setCursor(0, 0); //Setta dove scrivere
lcd.print(" "); //Scrive tutti spazzi per pulire il display
lcd.setCursor(0, 1); //Scrive tutti spazzi per pulire il display
lcd.print(" "); //Scrive tutti spazzi per pulire il display
lcd.setCursor(0, 0);
lcd.print("Umidita' = %");