Book Image

Arduino Home Automation Projects

By : Marco Schwartz
Book Image

Arduino Home Automation Projects

By: Marco Schwartz

Overview of this book

Table of Contents (14 chapters)
Arduino Home Automation Projects
About the Author
About the Reviewers

Testing the sensors

Before sending the data from our sensors to the cloud, we'll first make sure these sensors are working correctly. To do this, we are going to make the usual test sketch that will try to read data from the sensors and print this data on the serial monitor.

Let's now go to the Arduino IDE. The Arduino sketch starts by importing the correct library for the DHT sensor. The library is as follows:

#include "DHT.h"

We also have to declare the variables to store the measurements:

int lightLevel;
float humidity;
float temperature;

And to define on which pin the DHT sensor is connected, use the following code:

#define DHTPIN 7
#define DHTTYPE DHT11

We also have to create the instance for the DHT sensor:


In the setup() function of the sketch, we need to initialize the DHT sensor:


Then, start the serial connection:


In the loop() function of the sketch, we make the measurements:

float temperature = dht.readTemperature();
float humidity...