Measuring Relatve Humidity and Temperature with an AHT11 Unit

copyright, Peter H Anderson, Baltimore, MD, Oct 5, '10


Introduction

(Feb 15, '12). I have found an AMT1001 on eBay which appears to be an equivalent for the AHT11. I will shortly have some of these on hand.

This note illustrates how to interface with an AHT11 unit. These units appear to have been manufactured by Aosong of China. They are available at Satistronics in China. Satistronics has an interesting inventory and the shipping is reasonable. As of this writing the AHT11 was nominally $7.00.

Detailed Discussion

Data Sheet (English). Note that the Voltage vs Temperature Plot on page 4 is incorrect. Rather, the AHT11 unit has only a 10K NTC thermistor tied to +5 VDC. The R_thermistor vs Tc characteristic of this thermistor is provided in a Chinese data sheet. I have included this in the spreadsheet in this discussion.


Fig 1 - AHT11 Unit, Fig 2 - Vrh vs RH

Fig #1 illustrates the wiring layout of the AHT11 unit. Note that the yellow lead is a voltage representative of relative humidity RH and this may be connected directly to an A/D input. But, it is important to note that the temperature cuitry consists only of a nomianl 10K NTC thermistor which in itself does nothing. Additional external ciruitry is required.

Figure #2 is a graph taken from the data sheet showing the voltage output vs RH which allowed me to develop an equation of the form;

     y = mx + b
 
(1)  Vrh = 1.5 / 50 * RH + 0	
Expressing Vrh in terms of ADVal;
(2)     Vrh = ADVal / 1024 * Vref 

Fig 3 - Linearizing Circuitry, Fig 4 - Excel Spreadsheet

Figure 3 illustrates the circuitry I used to linearize and measure the temperature using the 10K NTC thermistor on the AHT 11 unit. I used a 100K parallel fixed resistor and a voltage divider consisting of the 100K in parallel with the thermistor and a 22K resistor to ground.

I used the Excel spreadsheet to attempt to develop a reqasonably linear expression of Tc vs ADVal.

Column A is the temperature in degrees C over the range of 0 to 50 degrees. Col B are the corresponding resistances of the NTC thermistor taken from the Chinese version of the data sheet. Col C is the parallel equivalent or the NTC thermistors and the 100K fixed resistor. Col D is the result of the voltage division, expressed as a function of the 10-bit A/D and Col E was my attempt to develop and equation for Col D.

(3)   ADVal = 318 + 8.36 * Tc
or
(4)   Tc_10 = 0.121 * ADVal - 380

Fig 5 - Tc vs ADVal Plot

Note that Columns D and E are in close agreement and Col D appears to be linear.

This note was written to illustrate how to very inexpensively measure relative humidity and temperature using an AHT-11 assembly. However, more generally, a very simple technique using only two fixed resistors was developed to linearize a NTC thermistor, at least over the range of 0 to 50 degrees C.


PICAXE Routine

Although this routine was written and tested on a PICAXE-20X2, I am certain that it might be ported to any of the PICAXE devices, including the PICAXE-08M.

A/D converters 1 and 2 are enabled.

64 A/D conversions are performed on ADC #1 (RH) and the result is averaged. The relative humidity is calculated and displayed. Similarly, 64 conversions are performed on ADC #2 and the temperature in degrees C is calculated and displayed.

' AHT11_1.Bas,  PICAXE-20X2
'
' Illutrates an interface with an Aosong AHT-11 analog humidity
' and temperature sensor.
'
' Periodically measures and displays RH and Temperature in degrees C
'
' copyright, Peter H Anderson, Oct 15, '10


Symbol ADVal = W0
Symbol RH_10 = W1
Symbol T_10 = W1
Symbol Sum = W2
Symbol N = B6
Symbol Channel = B7
Symbol Whole = B8
Symbol Fract = B9


  Pause 1000
  SerTxD ("_____", CR, LF)
 
  ADCSetup = $0006 ' ADC2 & ADC1


  Do
      Channel = 1
      GoSub ADConv
      GoSub Calc_RH_10
      GoSub Display_RH_10

      Channel = 2
      GoSub ADConv
      GoSub Calc_T_10
      GoSub Display_T_10
 
  
      Pause 5000
  Loop


ADConv:
 
    Sum = 0
    For N = 1 to 64			' sum 64 readings
       ReadADC10 Channel, ADVal
       Sum = Sum + ADVal
    Next
 
    ADVal = Sum / 64			' calculate the average
 
    Return
    
Calc_RH_10:   

     RH_10 = adval
     RH_10 = 6 * adval /10 + RH_10
     RH_10 = 3 * adval / 100 + RH_10
    
     Return
    
Display_RH_10:

    Whole = RH_10 / 10		'  whole
    Fract = RH_10 % 10		'  fract to tenths
   
    SerTxD ("RH = ", #Whole, ".", #Fract, CR, LF)
    Return
              
Calc_T_10: 

    T_10 = ADVal
    T_10 = 2 * ADVal / 10 + T_10
    T_10 = ADVal / 100 + T_10
    T_10 = T_10 - 380
    Return  
            

Display_T_10:

    Whole = T_10 / 10		'  whole
    Fract = T_10 % 10		'  fract to tenths
   
    SerTxD ("Tc = ", #Whole, ".", #Fract, CR, LF)
    Return
              


Arduino

This follows the PICAXE routine. Although the Arduino has robust floating point capability, it proved to be unnecessary in this application.


// AHT11_1.PDE,  Arduino
//
// Illutrates an interface with an Aosong AHT-11 analog humidity
// and temperature sensor.
//
// Periodically measures and displays RH and Temperature in degrees C.
//
// copyright, Peter H Anderson, Oct 31, '10

int ad_conv(byte channel, byte num);
int calc_RH10(int adval);
int calc_TC10(int adval);
void display(int x);

void setup()
{
   Serial.begin(9600);
   delay(100);   
}


void loop()
{
  int adval, RH10, TC10;
  
  adval = ad_conv(0, 32); // 32 samples on Channel 0
  RH10 = calc_RH10(adval);
  display(RH10);  
  Serial.print("  ");
  
  adval = ad_conv(1, 32);  
  TC10 = calc_TC10(adval);
  display(TC10);
  Serial.println();
  
  delay(5000);
  
}

int ad_conv(byte channel, byte num)
{
    long sum = 0;
    byte n;
    
    for (n=0; n<num; n++)
    {
       sum = sum + analogRead(channel);
    }
    return(sum / num);
}

int calc_RH10(int adval)
{
   int RH10;
   
   RH10 = adval + 6 * adval / 10 + 3 * adval / 100; // 1.63 * adval
   
   return(RH10);
}

int calc_TC10(int adval)
{
    int TC10;
 
    TC10 = adval + 2 * adval / 10 + adval / 100 - 380;
 
    return(TC10);
}   
   
void display(int x)
{
   int whole, fract;
   
   whole = x / 10;
   fract = x % 10;
   
   Serial.print(whole, DEC);
   Serial.print(".");
   Serial.print(fract, DEC);
}