Buongiorno, nella realizzazione della stazione meteorologica che legge valori di temperatura, umidità, pressione, altitudine e luminosità io utilizzo il seguente sketch:
#include <dht_nonblocking.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <LiquidCrystal.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
Adafruit_BMP085 bmp;
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const int SENSOR = 1;
const int sensor = 0;
int val =0;
void setup() {
lcd.begin(16, 2);
// Print a message to the LCD.
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
}
}
static bool measure_environment( float *temperature, float *humidity, float *pressure, float *altitude)
{
static unsigned long measurement_timestamp = millis( );
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
void loop() {
float temperature;
float humidity;
float pressure;
float altitude;
if( measure_environment( &temperature, &humidity, &pressure, &altitude ) == true )
{
lcd.clear ();
lcd.print( "T = " );
lcd.print( temperature, 1 );
lcd.print( " C");
lcd.setCursor(0, 1);
lcd.print( "H = " );
lcd.print( humidity, 1 );
lcd.print(" %");
lcd.setCursor (1,1);
delay (5000);
lcd.clear ();
lcd.print ( "P = " );
lcd.print ( (int) bmp.readPressure());
lcd.print ( pressure, 1);
lcd.setCursor (0, 1);
lcd.print ("A = ");
lcd.print( (int) bmp.readAltitude());
lcd.print ( altitude, 1);
lcd.setCursor (1, 1);
delay (5000);
val= analogRead (SENSOR);
lcd.clear ();
lcd.print ( "L = " );
lcd.print (val);
lcd.setCursor (0,1);
if( val > 300 ) {
lcd.print ("soleggiato");
lcd.setCursor (1, 1);
} else { lcd.print ("nuvoloso");
lcd.setCursor (1, 1);}
}
delay (5000);
}
Il tutto funziona fino a che non uso il ciclo "IF" per scrivere "soleggiato" o "nuvoloso", perché quando inserisco quella riga di codice il display non fa vedere più nessun valore.
Non saprei come risolvere, potete aiutarmi?
Grazie.