mLink DHT22 Temperature and Humidity Sensor (HCMODU0181)

mLink serial I2C modules
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

mLink DHT22 Temperature and Humidity Sensor (HCMODU0181)

Post by admin » Fri Oct 01, 2021 9:00 am

Image



The mLink DHT22 sensor is a serial (I2C/IIC) temperature and humidity sensor module. It adds the ability of your microcontoller/Arduino to measure temperature (in oC) and relative humidity (%RH) to 1 decimal place using only its I2C interface. It is compatible with other mLink or standard I2C modules allowing you to daisy-chain several different types of modules together using only the two I2C pins of your microcontroller.


For Arduino users you can use the mLink library (see below) to control any type of mLink module. Only one single instance of the library is needed to control multiple types of mLink modules resulting in very little resources overhead and therefore making it great for Arduinos with small amounts of memory and pin counts.

For Raspberry Pi users we have a Python module which can be installed via pip or downloaded and installed directly from our forum. Please see the mLink Python forum thread for requirements and download link here: viewtopic.php?f=131&t=3062&p=8592#p8592



Module specifications:
Module code: 					HCMODU0181
Supply Voltage (VDD): 			3.3V to 5.5V
Current consumption (idle):		5mA
Current consumption (sleep):		1.5mA
Interfaces:					I2C
I2C Interface speed: 				400kbits/s (fast mode)
I2C default address (HEX): 		0h51
Maximum number of modules: 		5 with pullups fitted, 112 with pullups removed*
Module dimensions (inc headers):	64mm x 17mm x 11.5mm


DHT22 specifications:
Operating range:				Humidity 0-100%RH 
							Temperature -40~80 Celsius
Accuracy:						Humidity +-2%RH(Max +-5%RH) 
							Temperature <+-0.5Celsius
Resolution or sensitivity:			Humidity 0.1%RH 
							Temperature 0.1Celsius 
Repeatability:					humidity +-1%RH
							Temperature +-0.2Celsius
Humidity hysteresis:				+-0.3%RH	
Long-term Stability				+-0.5%RH/year
Sensing period					Average: 2s


*Note the maximum number of connected modules will depend on cable lengths and power requirements of each module. Do not exceed 5 mLink modules connected in series with all fitted to all modules. 





Arduino Connection Example:


Image

Image



Read temperature & humidity example

Arduino Temperature & Humidity Example:

This sketch uses the mLink to read the temperature (in oC) an humidity (in RH%) from the mLink DHT22 sensor module (SKU: HCMODU0181).

  1. #include "mLink.h"          // Include the library
  2.  
  3. mLink mLink;                // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x51        // Default I2C address
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.  
  11.   mLink.init();             // Initialise the library
  12. }
  13.  
  14.  
  15. void loop()
  16. {
  17.   mLink.write(I2C_ADD, DHT22_START_MEAS);  // Trigger a new measurement
  18.  
  19.   while(mLink.busy(I2C_ADD));                 // Wait for the new measurement
  20.  
  21.   float temp = mLink.DHT22_Temp(I2C_ADD);     // Get the temperature in oC
  22.   float hum =  mLink.DHT22_Hum(I2C_ADD);      // Get the humidity in %RH
  23.  
  24.   Serial.print("Temperature: "); Serial.println(temp);
  25.   Serial.print("Humidity:    "); Serial.println(hum);
  26.  
  27.   delay(1000);
  28. }

Low power mode example

Arduino Low Power Mode Example:

This sketch uses the mLink to read the temperature (in oC) an humidity (in RH%) from the mLink DHT22 sensor module (SKU: HCMODU0181). Once the sensor has been read the sketch will then put the module back into a low power sleep mode.
  1. #include "mLink.h"          // Include the library
  2.  
  3. mLink mLink;                // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x51        // Default I2C address
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   mLink.init();             // Initialise the library
  11. }
  12.  
  13.  
  14. void loop()
  15. {
  16.   mLink.wake(I2C_ADD);                        // Wake the device up
  17.  
  18.   mLink.write(I2C_ADD, DHT22_START_MEAS);     // Trigger a new measurement
  19.  
  20.   while(mLink.busy(I2C_ADD));                 // Wait for the new measurement
  21.  
  22.   float temp = mLink.DHT22_Temp(I2C_ADD);     // Get the temperature in oC
  23.   float hum =  mLink.DHT22_Hum(I2C_ADD);      // Get the humidity in %RH
  24.  
  25.   mLink.sleep(I2C_ADD);                       // Put the module to sleep
  26.  
  27.   Serial.print("Temperature: "); Serial.println(temp);
  28.   Serial.print("Humidity:    "); Serial.println(hum);
  29.  
  30.   delay(10000);                               // Wait 10 seconds before reading again
  31. }




Raspberry Pi Connection Diagram

Image

Please note: when connecting to a Raspberry Pi the mLink module should either be powered via 3.3V, or the mLink modules I2C pullup resistors should be removed. See the 'Removing the modules I2C pullup resistors' section below for more information.

DHT22 read example

Raspberry Pi DHT22 read Example:
mLink Raspberry Pi DHT22 read example.

This program requires the mLink Python library module to be installed. Please see the following forum thread for more information on how to install the Python module and requirements:

viewtopic.php?f=131&t=3062

  1. from mLink import mLink                     # Import the mLink module
  2. import time
  3.  
  4. ml = mLink.mLink(1)                         # Create an instance of the module
  5.  
  6. I2C_ADD = 0x51                              # Default I2C address is 0x51
  7.  
  8.  
  9. while 1:
  10.     ml.DHT22_Start(I2C_ADD)                 # Trigger a new measurment
  11.  
  12.     while(ml.busy(I2C_ADD)):                # Wait for measurment to complete
  13.         pass
  14.    
  15.     print(ml.DHT22_Read_Temp(I2C_ADD))      # Print out the new temperature in oC
  16.     print(ml.DHT22_Read_Hum(I2C_ADD))       # Print out the new humidity %RH
  17.     print()
  18.        
  19.     time.sleep(0.5)


Removing the modules I2C pullup resistors

Please note that the modules I2C pullup resistors should be removed if you intend to use it as follows:

1) You wish to connect more than 5 modules to the same I2C bus.

2) You wish to power this module at 5V and you have a 3.3V development board that does not have a 5V tolerant I2C interface.

3) You wish to power this module at 5V and you have a 3.3V development board that has its own I2C pullup resistors.


To disconnect the modules two 10K pullup resistors from the I2C bus, locate the 3 jumper pads labelled ‘END DEV’ and cut the two tracks linking them together as follows:

Image





Image

mLink Arduino library
viewtopic.php?f=58&t=3001


mLink Raspberry Pi Python module
The mLink python module can be installed with the following terminal command:

  1. pip install hc-mlink

Alternatively the library can be manually installed by downloading it from the forum and unzipping it to your project folder. See the Python module forum thread for more information and download link:
viewtopic.php?f=131&t=3062&p=8592#p8592

Please note that in some cases there may be additional configuration required. If you have issues getting your Raspberry Pi to communicate with the mLink module then please see the Python module forum thread here: viewtopic.php?f=131&t=3062


mLink Library Quick Start Guide For Arduino Users
https://hobbycomponents.com/downloads/m ... _Guide.pdf


mLink Library Reference Guide For The DHT22 Module
https://hobbycomponents.com/downloads/m ... _Guide.pdf


mLink Specifications and Register Map For The DHT22 Module
https://hobbycomponents.com/downloads/m ... er_Map.pdf


Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.

Post Reply

Return to “mLink”