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:
DHT dht(DHTPIN, DHTTYPE);
In the setup()
function of the sketch, we need to initialize the DHT sensor:
dht.begin();
Then, start the serial connection:
Serial.begin(115200);
In the loop()
function of the sketch, we make the measurements:
float temperature = dht.readTemperature...