Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Ideas For Design]
Measure Relative Humidity With A PIC MCU

Claudia A. Angulo, Ricardo Jimenez  |   ED Online ID #9808  |   March 17, 2005


A relative humidity meter can be built using a sensor with a capacitive response and a PIC microcontroller (MCU), as shown in the figure. The capacitance range of the sensor, the HS1101 from Humirel (www.humirel.com), varies from 162 to 202 pF. Functioning as an oscillator, a TLC555 CMOS timer performs the conversion from capacitance to frequency. The timer's frequency equation is given by:

F = 1.44/(RA + 2RB) × CX

where resistors RA and RB equal 421 kΩ and 42.4 kΩ, respectively. CX is the transducer's capacitance. The 1-MΩ resistor connected to the timer's Control-Voltage input is used to unbalance the internal temperature coefficient that matches the sensor's temperature coefficient.

The MCU measures the period of the input signal and converts it to a digital relative-humidity reading. This is achieved by using the MCU's internal counter (TMR1) and the capture/compare/pulse-width modulation module (CCP). Because the transducer's capacitance range is too narrow, the period range of the signal will be too small. Therefore, an 8.000-MHz crystal is used to get 0.5 µs per instruction in the MCU. In addition, the CCP module is configured to divide the input signal by four. This will increase the counting pulses' range within the different periods provided by the TLC555. (The full code listing, 9808.zip, is available at the top of this article.)

The PIC's CCP module can detect rising or falling edges every four or 16 pulses. In this case, it was configured for every four rising edges. This detection is registered in the flag named CCP1IF in register PIR1. The flag is set when the first rising edge is detected, and TMR1 is enabled via software to start counting. Next, the flag must be erased to wait until detection of the fourth rising edge, and then stop the Timer. The total count, which represents a period, must now be transferred from the files TMR1L and TMR1H to the files CCPR1L and CCPR1H, respectively.

With this data, we proceed to converting the period to a humidity percentage. This is done by subtracting from the result the number that corresponds to a humidity of 0%; in this case, 62 decimal (3EH). This was determined from the equation supplied by the manufacturer and from the frequency generated by the TLC555 timer. The 16-bit subtraction is done by using the two's complement from the said number and adding this result to the data obtained from the TMR1. The result of this arithmetic operation corresponds to a humidity percentage. Now, the MCU proceeds to perform the conversion from binary to BCD code.

The binary to BCD conversion uses three files: units, tens, and hundreds. The result of the humidity percentage is sent to the units file, where it will have a subtraction of 10. The accumulator, W, stores this result.

By testing the carry bit from the status register, we will know if the result is greater than 10. If it's lower than 10, the result only has units and there's no need to continue doing more comparisons. This way, the conversion will be located in the units file. On the other hand, if the result is greater than 10, the tens file is incremented, and the same process of subtracting 10 to the units file must continue while the tens file is being incremented.

When the tens file is equal to 10, the hundreds file is incremented. The same process is performed until the number in the units file is lower than 10. When this conversion ends, the result in each file will be in BCD code. The BCD-to-seven-segments conversion is performed using a subroutine called OPTABLE.

The circuit has a four-digit multiplexed common-cathode LED display. It requires a multiplexing routine to display the readings correctly. This multiplexing is done at 200 Hz by switching the three 2N2222 transistors to actuate one display at a time.


Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • In EDA, A Year Of Mergers, Failed And Otherwise
  • 2008 BEST Electronic Design Winners
  • Engineers Rely On Internet For Product Info
  • Rochester Electronics Establishes New Design and Technology Group
  • November 17, 2008
  • Custom Sources Light Way To 22-nm IC Lithography
  • Software Turns Scopes Into Vector RF Signal Analyzers
  • Couple’s $15 Million Gift Advances Rice Engineering Education
    1) Behind The Bright Lights, LED Drivers Evolve To Meet New Requirements
    (747 views today)
    2) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (291 views today)
    3) Ten Top Design Skills For Tough Times
    (247 views today)
    4) Easily Convert Decimal Numbers To Their Binary And BCD Formats
    (171 views today)
    5) Consumer Electronics Series: AMD Live! Home Cinema Platform
    (158 views today)
    ALL TOP 20



    Reader Comments

    where is the 9808.zip

    lucifer -August 12, 2008

    WHERE ARE code listing, 9808.zip?

    Anonymous -June 25, 2008

    WHERE ARE code listing, 9808.zip?

    Anonymous -June 25, 2008

    WHERE ARE code listing, 9808.zip?

    Anonymous -June 25, 2008

    WHERE ARE code listing, 9808.zip?

    Anonymous -June 25, 2008

    Rating Only

    Rating Only -August 14, 2007   (Article Rating: )

    The PIC pin to 7segment allocation is not shown.

    Robin UK -January 27, 2006

    A very interesting and practical project, but both the scematic and code have errors so I'm struggling to make it work.

    Dick -September 18, 2005   (Article Rating: )

    Why not use the RC timing command built into most pic basic compilers to measure the RC timing change directly ? It is much simpler. [capacitance = pot(iopin)*scale +offset ] where (iopin) is connected to a resistor in series with the capacitive humidity sensor.

    Barry Tigner -September 14, 2005

    There are many ways to do this, although serious designer wouldn't go with the exact approach, people would still find this interesting for the next garage project. The value of the design is code with a schematic. To have a similar design to measure temperature, humidity, light intensity etc. once in a while would not turn readers away.

    Anonymous -June 06, 2005

    Since I am not in to these type of devices or the programming of, where might I buy a PIC16F872 already programmed?

    George Van Houten -March 23, 2005   (Article Rating: )

    POST YOUR COMMENTS HERE
    Name:

    Email:
    Your Comments:

    Enter the text from the image below


    Please refresh the page if you have trouble reading this text.

    Search Electronic Design
         
      
     
    Web Seminar
    Sponsored By:
    Title: Read Pacing: A Performance Enhancing Feature of PCI Express Gen 2 Switch Devices
    Speakers: 
    Date: 07/01/08
    Register: 

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF
    Mobile Dev & Design Schematics Find Power Products Military Electronics EE Events Related Resources