Sei sulla pagina 1di 3

#include <LiquidCrystal.

h>
#include <SFE_BMP180.h>
#include <Wire.h>
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(6, 7, 2, 3, 4, 5);


SFE_BMP180 pressure;

double baseline;
int menu = 0;
float h;
float t;
float l;
void setup()
{
Serial.begin(9600);
dht.begin();
lcd.begin(16, 2);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode(14, INPUT);

if (pressure.begin())
Serial.println("BMP180 init success");
else
{

Serial.println("BMP180 init fail (disconnected?)\n\n");


while (1);
}

baseline = getPressure();
}

void loop() {

if (digitalRead(14) == 1) {
menu++;
if (menu > 5) {
menu = 0;
}
delay(300);
}

double a, P;

switch (menu) {
case 0:
lcd.setCursor(0, 0);
lcd.print(" ICSV ");
lcd.setCursor(0, 1);
lcd.print("XII F Ciencias");
break;
case 1:
l = analogRead(A3);
l = (l * 100) / 1023;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Luminosidad");
lcd.setCursor(0, 1);
lcd.print(l);
lcd.print(" %");
delay(1000);
break;
case 2:
t = dht.readTemperature();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temperatura");
lcd.setCursor(0, 1);
lcd.print(t);
lcd.print(" *C");
delay(2000);
break;

case 3:
h = dht.readHumidity();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Humedad Relativa");
lcd.setCursor(0, 1);
lcd.print(h);
lcd.print(" %");
delay(2000);
break;
case 4:
P = getPressure();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pres. bar.");
lcd.setCursor(0, 1);
lcd.print(P);
lcd.print(" mili bares");
delay(2000);
break;
case 5:
P = getPressure();
a = pressure.altitude(P, baseline);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Altura SNM");
lcd.setCursor(0, 1);
lcd.print(a);
lcd.print(" metros");
delay(2000);

break;
}
}

double getPressure()
{
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0)
{

delay(status);

status = pressure.getTemperature(T);
if (status != 0)
{

status = pressure.startPressure(3);
if (status != 0)
{
delay(status);

status = pressure.getPressure(P, T);


if (status != 0)
{
return (P);
}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");
}