Hardware Reference
In-Depth Information
1.3
Testing the Sensors
Now that the hardware of the project is fully assembled, we are going to test the different
sensors on the board. And to do so, we are going to write a simple Arduino sketch. We will
simply read out data from the sensors, and print this data on the Serial port.
The DHT11 sensor is digital sensor, so we will use a dedicated library to get data from this
sensor. For the photocell, which is a purely analog sensor, we will use the analogRead()
function of Arduino to perform light level measurements.
This is the complete code for this section:
// Libraries
#include "DHT.h"
// DHT sensor
#define DHTPIN 7
#define DHTTYPE DHT11
// DHT instance
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
// Initialize the Serial port
Serial.begin(9600);
// Init DHT
dht.begin();
}
void loop()
{
// Measure from DHT
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Measure light level
float sensor_reading = analogRead(A0);
 
Search WWH ::




Custom Search