DHTxx Sensor

The DHT11, DHT21 and DHT22 are inexpensive sensors for measuring temperature and humidity. In this article we show you how to visualize data from a DHTxx sensor in RAPIFIRE.


Here are the components needed for this project:

  • Arduino YUN,
  • DHT21 sensor,
  • a breadboard,
  • 4k7 resistor (4,700 Ohms),
  • wires

Wiring diagram

The diagram below shows the connections between the different project components.

Wiring Diagram



Arduino YUN Configuration

We assume that the your Arduino is properly configured and it has access to the internet. If it is not please follow this manual.

Software Dependencies

This project uses the following libraries:

All the libraries are available in the Library Manager.


RapifireMqttClient is provided with an example of DHTxx sensor usage. You can find in File > Examples menu.

Arduino IDE

Before you start testing this example please update the Thing's details at the beginning of the sketch. This post contains more information about the configuration.

Now you can upload a compiled sketch to the board and see the data visualization in RAPIFIRE.

Line Charts

Source Code

The latest version of this example is available on github.


Below are the implementation details.

Thing's Authentication

Arduion YUN connects with RAPIFIRE in order to publish events (i.e. your data). The Arduino library takes care of the connection details so the only thing that you have to do is to provide your Thing details:

The Internet Connection

The library uses the YunClient API to connect to the server so you need to initialize the YUN's bridge in the setup function.

void setup() {  

  Serial.println(F("Starting bridge..."));

  Serial.println(F("Bridge ready."));
MQTT Connection

The data from the DHTxx sensor is delivered with the usage of MQTT protocol so you have to initialize the connection before you start publishing events.

  if (!rapifire.connected()) {
    Serial.println(F("Connecting to RAPIFIRE.."));

    if (rapifire.connect()) {
Data Publishing

The section below is responsible for reading data from the sensor and publishing it to RAPIFIRE.

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

  rapifire.addValue("temperature", "C", temperature);
  rapifire.addValue("humidity", "%RH", dht.readHumidity());

  if (rapifire.publish()) {
    Serial.print(F("Message published, temp: "));
    Serial.print(F("C, humidity: "));

Thank you for reading this blog. Now go try it out and monitor your office's temperature.