MySensors v2: measurement of temperature and humidity (DHT11/DHT22) [Exclusive Guide]

4:00 pm November 2, 201610720

firmware MySensors allows you to very easily perform a probe temperature and humidity at base DHT11 or DHT22 , which we can easily retrieve the values on a home automation software or program any. This is a good exercise to discover the MySensors library and home automation. If you start with the MySensors library, you can start with this article.

it is preferable to use a adapter with a voltage regulator integrated to achieve a best of show / radio signal reception (and it’s also much easier to wire). The connection of the module nRFF24L01 to the Arduino Nano is the following:

  • 5V-> V
  • +

  • GND-> GND
  • D13-> SCK (green)
  • D12-> MISO (purple)
  • D11-> MOSI (blue)
  • D10-> CSN (yellow)
  • D9-> THIS (orange)
  • D2-> IRQ (gray)

the DHT22 for only a 3-pin wiring.

the MySensors development team advises the use of a Arduino Nano as the basis for a MySensors node. It is also possible to add a node to a gateway or use an ESP8266 since v2.

mysensors arduino micro dht22 nrf24l01

copy the code below into a new Arduino project. You can change the following settings:

  • the strength of the signal. Here it is set to LOW for privileged scope in view of the low volume of data to be transmitted and the frequency of sending.
  • the module type Radio.
  • the identifier of the node. The v2 is stable but the automatic assignment of an identifier is still random. For the moment, I prefer to assign a number manually.
  • parameter SLEEP_NODE allows you to sleep the module for the period SLEEP_TIME

you may also need to add the DHT Bookstore from the Bookstore Manager. Unlike the examples found on the Web, I used the Adafruit library which is available in the Library Manager.

 / * * The MySensors Arduino library handles the wireless radio link protocol and * your home built between sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes.
 * Created by Henrik Ekblad  * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * This program is free software; You can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation.
 * * * REVISION HISTORY * Version 1.0 - DIY PROJECTS * DESCRIPTION * Example sketch showing how-to measue light level using a photo-resistor LM393 * http://www.mysensors.org/build/light * / / / Active debug mode / Enable debug prints to serial monitor #define MY_DEBUG / / Radio Mode / Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_RF24_PA_LEVEL RF24_PA_LOW / / node of the object / Object Node MY_NODE_ID 3 #include #define  #include  #include  #define CHILD_ID_TEMP 0 CHILD_ID_HUM 1 #define SLEEP_NODE true #define / / set to True to enable the implementation of sleep (Sleep Mode) / True to activate Sleep Mode unsigned long SLEEP_TIME = 10 * 1000; Time to sleep (in ms) / Sleep time between reads (in milliseconds) DHTPIN 3 #define / / pin on which the DHT is connected / what we're connected to #define DHTTYPE DHT22 pin / / DHT 22 (AM2302), DHT11 float lastTemp;
float lastHum;
Boolean metric = true; 
MsgHum (CHILD_ID_HUM, V_HUM) MyMessage;
MsgTemp (CHILD_ID_TEMP, V_TEMP) MyMessage;

void setup() {} void presentation() {/ / Presenttion of the sketch / Send the sketch version information to the gateway and Controller sendSketchInfo("Sonde Temp/Hum DHT22", "1.0");}

  Statement of the sensors attached to the node present (CHILD_ID_TEMP, S_TEMP);
  present (CHILD_ID_HUM, S_HUM);
} void loop() {DHT dht(DHTPIN, DHTTYPE,3); / / create an object of dht in the loop, otherwise the values are not measured wake up float temperature = dht.readTemperature ();}
  float humidity = dht.readHumidity ();
  If (isnan (temperature)) {Serial.println ("could not read the temperature on the DHT");
  } else {if (temperature! = lastTemp) {lastTemp = temperature;}
      If (! metric) {temperature = dht.readTemperature (true);}
      } Serial.print ("T:");
      Serial.print (temperature);
      Serial.print("|) H: ");
      Serial.println (humidity);
      send (msgTemp.set(temperature, 1));
      send (msgHum.set(humidity, 1));
    } else {Serial.println("Temperature identique => on force l'envoi");  
      Serial.print ("T:");
      Serial.print (temperature);
      Serial.print("|) H: ");
      Serial.println (humidity);
      send (msgTemp.set(temperature, 1));
      send (msgHum.set(humidity, 1));
    }} if (SLEEP_NODE) {Serial.println ("Sleep");
    sleep (SLEEP_TIME);
  } else {delay (SLEEP_TIME);
  }} 

it is more that they integrate this small Probe temperature and humidity in software automation such as Domoticz. If you are new to home automation (or Domoticz), read this article which explains how to add a network gateway at ESP8266 base.

go to the devices. From the first transmission of data, Domoticz was added automatically to the list of available devices. Press the green arrow and give it a name.

domoticz dispositif mysensors temperature humidite dht11 dht22 arduino nano

then go to the Temperature page to see your new probe MySensors.

domoticz dispositif mysensors temperature humidite dht11 dht22 arduino nano