The Arduino Sensor Kit comes with one of these temperature and humidity sensors:
The DHT20 is a newer sensor with I2C support, but may require some configuration when used with the Arduino_SensorKit library.
Identify which sensor you have
The easiest way to identify which sensor is in your kit, is by looking at the color of the sensor module:
Using the DHT20 sensor
Use Arduino_Sensorkit v1.0.10 or later
Support for the DHT20 temperature and humidity sensor was added to the Arduino_Sensorkit library in version 1.0.10[3]. Older versions of the library could not correctly read values from the sensor, resulting in NaN
(Not a Number) values in the serial monitor output. To use a DHT20 sensor with the library, make sure to update to version 1.0.10 or later.
Follow these steps to update the Arduino_Sensorkit library in Arduino IDE:
-
Click the Library Manager button (or select Tools > Manage Libraries).
-
Search for “Arduino_SensorKit”.
-
Make sure 1.0.10 or later is selected and click Update.
-
If you’re asked whether you’d like to install library dependencies, click Install all.
-
Wait for the update process to finish.
The Cloud Editor uses the latest version of all libraries by default.
Uncomment lines for the DHT20
The Temp_and_Humidity.ino
example contains two lines of code that should be uncommented if you’re using the DHT20 sensor.
The modified sketch looks like this:
//#define DHTPIN 3 // By default its connected to pin D3, it can be changed, define it before the #include of the library
#include "Arduino_SensorKit.h"
//uncomment line below if using DHT20
#define Environment Environment_I2C
void setup() {
//uncomment line below if using DHT20
Wire.begin();
Serial.begin(9600);
Environment.begin();
}
void loop() {
Serial.print("Temperature = ");
Serial.print(Environment.readTemperature()); //print temperature
Serial.println(" C");
Serial.print("Humidity = ");
Serial.print(Environment.readHumidity()); //print humidity
Serial.println(" %");
delay(2000);
}