Hardware Reference
In-Depth Information
void
loop
(
void
)
{
// Measure the humidity
float
humidity
=
dht.readHumidity();
// Measure light level
int
lightLevel
=
analogRead(A0);
// Measure pressure & temperature from BMP sensor
sensors_event_t
event;
bmp.getEvent(
&
event);
float
pressure
=
event.pressure;
float
temperature;
bmp.getTemperature(
&
temperature);
float
seaLevelPressure
=
SENSORS_PRESSURE_SEALEVELHPA;
float
altitude;
altitude
=
bmp.pressureToAltitude(seaLevelPressure,
event.pressure,
temperature);
// Print measurements
Serial.print(
"Humidity: "
);
Serial.println(humidity);
Serial.print(
"Light level: "
);
Serial.println(lightLevel);
Serial.print(
"Barometric pressure: "
);
Serial.println(pressure);
Serial.print(
"Temperature: "
);
Serial.println(temperature);
Serial.print(
"Altitude: "
);
Serial.println(altitude);
Serial.println(
""
);
// Repeat 50 ms
delay(
50
);
}
Let's now see the details of the code. The first step in the code is to import the correct lib-
raries:
#include "DHT.h"
#include <Wire.h>