Thank you for purchasing our DHT sensor kit. This page will walk you through building your kit and explaining the code which will control your DHT sensor and connecting it to the Internet of Things.

Kit Description

This is what is included in the package:

  1. Breadboard
  2. ESP8266 microprocessor, Arduino™-compatible
  3. DHT11 sensor
  4. Set of 15cm wires


Kit Assembly

Open the anti-static bag containing the ESP8266 microprocessor. We recommend that you align the ESP8266 in such a way that the end with the micro-USB connector is near pins 1 of the breadboard, and that the ESP8266 is centered in the breadboard. This will leave one row of breadboard pins on either side of the ESP8266 logic board.


Next you will need to insert the DHT sensor into the breadboard. Before inserting the sensor, notice that the sensor has 3 pins. One of them is marked with an “S”, which is where the Sensor output will come from. The other is marked with a “-“, which will be connected to the ground (GND) pin of the ESP8266 logic board. The middle pin is the voltage pin, and will be connected to the 3.3V output of the ESP8266 logic board. Here is a close-up of your DHT sensor.

You can insert the DHT sensor anywhere on the breadboard that you want. There is plenty of room between rows 19-30 of the breadboard. PLEASE NOTE: the 3 pins of the sensor MUST be placed on different rows of the breadboard. Each row on each side of the breadboard is connected with a conductive material. If you place all 3 pins of the sensor on 1 row of the breadboard, you will short out the pins of your sensor.

Keep track into which breadboard row the Sensor, 3.3v, and Ground pins are connected. You will need to use the wires to connect the correct pins of the ESP8266 logic board to the corresponding pins of the sensor.


This is the wiring diagram we recommend you use. Pin 1 of the breadboard is the 3.3v output which needs to connect to the middle pin of the DHT11 sensor (not labeled). Pin 2 of breadboard is ground, and will connect to the right pin of the DHT11 sensor (labeled “-“). Pin 14 of the bread board is labeled D2, and will connect to the left pin of the DHT11 sensor (labeled “S”).


Here is the final assembled product.


Arduino Libraries

The next part of this project presumes familiarity with the Arduino IDE and Arduino programming. We have more information about Arduino in our learn page.

We are almost ready to program the ESP8266 using the Arduino IDE. First, we need to install the Adafruit Unified Sensor and DHT libraries for Arduino, which will provide objects and command to interact with the DHT22 sensor. You can download the libraries directly in the Arduino IDE. From the menu, choose Sketch -> Include Library -> Manage Libraries…. This will bring up a list of tons of LIbraries available to use in the project. We need to use the search bar to find the correct libraries.

Search for “adafruit unified sensor”, scroll down until you see the “Adafruit Unified Sensor by Adafruit”. Select that row and click on “Install”.

Then, search for DHT and look for “DHT sensor library by Adafruit”. Select that row and click on “Install”.

If you’d like to download the source code for these libraries, you can download the Unified Sensor library and the DHT library from their Github repositories. You can learn more about Adafruit and the work they’ve done for the maker and Arduino community at Adafruit’s learning site and at their DHT learning page. It’s a great resource to bookmark, explore and learn.

Arduino Programming

Here is the full source code to get the UnoKit DHT22 kit up and running.

// Copyright (c) 2018 Jeff Jolley for UnoKits.io
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.



// THIS SOFTWARE IS FOR USE WITH THE UnoKits.io DHT PROJECT WHICH
// IS DESIGNED TO SHOW THE OWNER HOW TO PROGRAM ARDUINO-COMPATIBLE
// HARDWARE TO WORK WITH DIGITAL HUMIDITY AND TEMPERATURE SENSORS.

// MORE INFO: http://kit.uno/dht



// INCLUDE CORRECT LIBRARIES HERE //
#include <DHT.h>
#include <DHT_U.h>



// DEFINE ARDUINO PIN CONNECTED TO DHT SENSOR
// GPIO5 IS CONNECTED TO PIN D1 ON THE ESP8266 NODEMCU MODULE 
#define DHT_SENSOR 5

// DEFINE DHT INSTANCE
DHT_Unified dht(DHT_SENSOR, DHT22);


void setup() {
  // LAWAYS START THE SERIAL CONNECTION IN SIMILAR FASHION //
  // OR ELSE THE ARDUINO SERIAL MONITOR WILL NOT WORK AND //
  // YOUR CODE MAY NOT RUN AT ALL //
  Serial.begin(115200);

  Serial.println("Init 1");
  Serial.println("Init 2");


  // INITIALIZE THE DHT LIBRARY //
  Serial.println("dht.begin...");
  dht.begin();

  Serial.println("done with setup.");
}


void loop() {
  // THE FOLLOWING CODE COMES FROM SAMPLE CODE SHOWING //
  // HOW TO UTILIZE THE ADAFRUIT_IO LIBRARY //


  // READ TEMPERATURE FROM DHT //
  sensors_event_t event;
  dht.temperature().getEvent(&event);

  float celsius = event.temperature;
  float fahrenheit = (celsius * 1.8) + 32;

  // OUTPUT DEBUG INFORMATION TO SERIAL PORT //
  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");
  Serial.print("fahrenheit: ");
  Serial.print(fahrenheit);
  Serial.println("F");


  // READ HUMIDITY FROM DHT //
  dht.humidity().getEvent(&event);

  // OUTPUT DEBUG INFORMATION TO SERIAL PORT //
  Serial.print("humidity: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");
  Serial.println("");

  // wait 30 seconds (10000 milliseconds == 10 seconds)
  delay(10000);


}

Let’s see how that runs 🙂