Wireless Weather Station

Feb. 10, 2009
In the Midwest, the main topics of conversation may include the local football team or how the crops are doing. Inevitably though, the conversation always leads to the weather. Most of us take the weather for granted and don’t give it a second thoug

By Jerry Wasinger

I. Introduction

In the Midwest, the main topics of conversation may include the local football team or how the crops are doing. Inevitably though, the conversation always leads to the weather. Most of us take the weather for granted and don’t give it a second thought. But, in states like Kansas, Oklahoma, and Texas, weather is spelled with a capital “W” and is closely monitored by both individuals and the media. Weather is thunderstorms, tropical depressions, tornados, blizzards, squall lines, stationary fronts, cold fronts from Canadian, warm moist Gulf air, and hurricanes. The onset of any one of these events can be detected by monitoring a few basic conditions.

When you check the weather on the television or the radio, it’s always what conditions are like at the airport or some other remote location. But, what are conditions like in my backyard? To address this, I embarked on the design of the Wireless Weather Station. I had meant to do this project many years ago but two bits of technology finally spurred me into action: the first was the development of low-cost, solid state humidity sensors and the second was the availability of small, monolithic RF transceivers.

II. The Design

The Wireless Weather Station is composed of a remote station and a base station. The remote station is solar-powered and wakes up once a minute to collect and transfer data. The base station receives and buffers the incoming data and then transfers it via an RS232 connection to a PC for processing. Within each of the stations is a dedicated circuit card as well as a separate, RF circuit card. We’ll start our discussion with the remote station design.

A. Remote Station
The Remote Station consists of four functional sections: the sensors, the PIC16F873 microcontroller, the RF circuit, and the power supply. The schematic, shown in Figure2, shows the sensor and microprocessor areas.

For humidity sensing, I opted for the Humirel HS1101 capacitive sensor. This device, when combined with a CMOS 555 timer operating as an astable multivibrator, produces a signal with a humidity dependent frequency. To minimize temperature effects, it is important to use the Texas Instruments TLC555 device in this design. Refer to the HS1101 datasheet if another device is used. Also note that care must be taken at the node of the HS1101 and the 555. Stray capacitance values will lead to erroneous and unpredictable measurements. I chose to solder this node above the circuit card.

The relationship between the output frequency of the 555 and the relative humidity can be seen in Figure 1. A first order equation that relates relative humidity to frequency is:

R.H. = 565.1 – 0.0767 * f

A second order equation can be used for improved accuracy,:

R.H. = -6.4790E-06 * f2 + 1.0047E-02 * f + 2.7567E+02

Temperature sensing is very straight-forward with the LM335. This output of this device is equal to the absolute temperature in degrees Kelvin divided by 100 or:

Vout=Temperature(K)/100

To determine the temperature in degrees C, use the equation:

ºC = 100 * Vout – 273

To determine the temperature in degrees Fahrenheit, use the equation:

ºF = 1.8 * ºC +32.2

= 1.8 * (100 * Vout – 273) + 32.2

= 180 * Vout - 459.2

At room temperature, this device outputs about 3volts.

Pressure sensing is provided by a Motorola MPX5100A, which operates from 0 to 16 PSI. However, we’re interested in only a very small part of that range. Barometric pressure readings fall between 28 and 32 inches of mercury. This translates to 13.75 to 15.72 PSI. To increase the dynamic range of the output, I added an amplifier circuit (U4), which subtracts about 3.7 volts from the sensor output and then multiplies the difference by 4. Since the MPX5100 can require as much as 10mA, Q1 was added to provide microprocessor-controlled switching.

I chose the Microchip PIC16F873 because it had the right mix of program and data memory, a 10-bit A/D, and three timers. Timer2 is used to measure the period of the humidity signal. The A/D is used to measure the temperature and pressure sensors as well as to monitor the battery voltage. To maximize accuracy I used an external 4.096 volt 0.1% reference from National Semiconductor. With the 10-bit A/D, this provides a resolution of 4mV per count.

The interface to the RF link consists of an enable line and a data output. Since the transmitter circuit operates at 3.3 volts, I used analog switches to translate from the five-volt outputs of the microprocessor. Although not shown, pin 14 of the 74HC4066 needs to be connected to +5 volts while pin 7 needs to be grounded. JP1 is a 6-pin header that connects to the RF circuit card.

 


The power supply for the Remote Station is shown in Figure 3. When the sun is shining on the solar panel (SC1 – part number 980-1045 from RadioShack.com), enough power is generated to drive the 50mA current source formed by Q1, U1, and R1. This current acts as a trickle charger for three AA NiCAD batteries. The batteries power U2 - a switchmode regulator that provides the 5 volts for the microprocessor and sensors. This is followed by U3, which is a linear regulator that provides the 3.3 volts for the RF circuitry. L2 and C5 were added to reduce the switching noise from U3. D2 is used to isolate the solar panel from the rest of the circuit when it is dark. Note that C3 and C5 should be 6.3V low ESR capacitors.

 


The RF section of this design, shown in Figure 4, was built around the TX5002 and RX5002 chips from RF Monolithics. Due to the footprint of these devices, it was necessary to design a small printed circuit board. Fortunately, the chips have a pin-out that allowed a single board to be used for both the transmitter and the receiver. The completed layout can be seen in Figure 5.

I was able to get all the traces on a single layer so fabrication was greatly simplified. The four corner holes were drilled out to allow mounting with 4-40 screws. The antenna is connected via a BNC jack on the left side. However, a length of coax can be connected to this pad in order to use a panel-mount connector.

It is necessary to use solder paste to connect the RFM modules to the PCB. Carefully apply the paste to the pads of U1 on the board. Position the module on board and heat with a hot air gun until the solder melts. Except for C2, the remaining components are in 0603 SMT packages. C2 is a tantalum capacitor in an “A” package.

Connection of the RF board is through header J2. This plugs into socket JP1 on the Remote Station.

As mentioned earlier, the same board is used for both the transmitter and the receiver. The function of the board is controlled by which parts are used. Table 1 summarizes which components are used for each board.


 

Reference Transmitter Value RCVR Value
C1,C4 100pF 100pF
C2 10uF 10uF
C3

Not Used

.015uF
     
JP1 Used Not Used
JP2 Not Used Used
JP3 Not Used Used
JP4 Not Used Used
JP5 Used Used
JP6 Used Used
JP7 Used Used
J1 BNC BNC
J2 6-pin Header 6-pin Header
     
L1 56nH 56nH
L2 220nH 220nH
L3 BEAD BEAD
     
R1 Not Used 270K
R2 Not Used 330K
R3 Not Used 27K 1%
R4 Not Used 100K 1%
R5 Not Used 30K
R6 47K 47K
R7

8.2K

Not Used
R8 10K Not Used
     
U1 TX5002 RX5002


Note that he BEAD used was a J.W. Miller part available from Digikey part # PMC0603-301-ND.More data about the bead requirements can be found from the datasheet of the device.

To maximize range, λ/4 stub antennas over λ/2 ground planes were used for both the transmitter and receiver. The antenna length can be calculated from:

λ = c/418*106

λ = 3*1010 cm/sec / 418*106 cycles/second

λ = 71.8cm

λ/4 = 18cm

The construction details for the antennas are shown in Figure 6

B. Base Station
The Base Station (Figure 7), is also built around the PIC16F873 microprocessor. For this application, I used the second onboard oscillator to generate a real time clock and configured the MSSP as a UART for asynchronous communication with the host PC.

RS232 buffering and level translation is accomplished through the MAX232. A standard DB25 connector is used to connect to the PC. J3 provides connectivity to the RF Receiver board which was assembled with the components specified in Table 1. No voltage conversion is required between the DataIn pin of the RF Receiver and the microprocessor since the minimum Input High voltage for the PIC is 2.0 volts.

Power is provided via a 9VDC wall mount power supply driving a 78L05 regulator for 5 volts and an LT1121 for 3.3V. A single green LED is used to provide a power indicator. When the microprocessor detects the reception of a valid data packet, additional current is injected into the LED causing it to pulse.

 


C. Microprocessor Code

1. Remote Station
The code for the remote station is very simple and can be explained easily with psuedocode:

 

Loop
  Sleep for 1 minute
  Turn on Pressure Sensor
  Perform A/D conversion on Temp Sensor
    Average four readings
    Add Hamming codes to data
  Measure pulse width of humidity sensor circuit
    Measure period of 555 oscillator / 16
    Compress data to fit into 10 bits
    Add Hamming codes to data
  Perform A/D conversion on battery
    Average four readings
    Add Hamming codes to data
  Delay additional 20msec for Pressure Sensor Stabilization
  Perform A/D conversion on Pressure Sensor
    Average four readings
    Add Hamming codes to data
  Turn Off Pressure sensor
  Transmit Data
    Turn on transmitter and wait two bit times for settling
    Send Preamble of eight 1's and eight 0's
    Send 14 bits of temperature data
    Send 14 bits of pressure data
    Send 14 bits of humidity data
    Send 14 bits of battery data
    Turn off transmitter
Repeat Loop


See the Appendix for an explanation of Hamming Codes.

2. Base Station
The firmware in the base station performs the following functions

 

  • Detect and decode data from the RF Receiver
  • Perform error correction on the received data
  • Encode the received data into ASCII format
  • Transmit the ASCII data to the RS232 port
  • Perform hourly data logging on RCVD data for a total of 24 hours of data
  • Detect and respond to RS232 requests for latest and historical data

The base station firmware relies on interrupts to detect and collect incoming data as well as to maintain the one hour clock for data logging. Once these events occur, flags are set that inform the main loop that either new data is available or that it is time to store a reading in memory.

The main loop monitors the flags set by the interrupt service routine. If the Received Data flag is set, the RS232 transmitter routine is called. If the log data flag is set, the last received data block is buffered. In addition, the main loop monitors the RS232 receiver. If the character “L” is received, the last reading is transmitted to the serial port. If the character “H” is received, the last 24 hours of logged data are sent to the serial port.

The serial data is transmitted at 9600 baud using an 8N1 format. The ASCII encoded measurement data stream looks like:

T:ttt, P:ppp, H:hhh, B:bbb

In the above, T is temperature, P is pressure, H is humidity, and B is battery voltage. “ttt”, “ppp”, “hhh”, and “bbb” are the 10 bit readings in hexadecimal format. This data has been error corrected but not calibrated. It is the function of the application software to convert the 10 bit hex values and perform the calibration corrections.

To convert the temperature and pressure, the measured voltage is the hex code multiplied by .004 or

Vtemp = ttt * 0.004

Vpres = ppp * 0.004

The conversion of battery voltage is similar:

Vbat = 2 * bbb * .004

= bbb * .008

The frequency of the humidity sensor circuit can be derived from:

f = 1/T =(16 * 106) / (hhh+2000)

Recall from earlier in this document that relative humidity is derived from the circuit frequency via:

R.H. = -6.4790E-06 * f2 + 1.0047E-02 * f + 2.7567E+02

III. Calibration

A. Temperature
The temperature sensor is typically accurate to within 2ºC before calibration. To improve accuracy, you will need an extension cable between the circuit board and the sensor as well as an ice-water slurry.

Place the sensor in the slurry and measure its output voltage using a voltmeter. Use the measured value in the following correction factor:

K=2.73/measured_value

Multiply your raw A/D readings by this correction factor to improve the precision of your temperature measurements.

B. Pressure
Your pressure sensor will require calibration and there are two possible methods to do it. The first method requires that you monitor your local weather channel for a couple of weeks while the second method necessitates some specialized equipment.

If you choose the first method, create a table and label the first column as Pressure Sensor and the second column as actual. Next, for about two weeks, monitor and record your local weather channel for the actual pressure. At the same time, measure and record the voltage across the pressure sensor. You will need to connect the Emitter and Collector of Q1 together so that power is routed to the sensor.

Enter your data into Excel and use a linear interpolation function to derive the equation:

Actual=K*measured+offset.

Use the following steps for the second method:

1. Acquire some flexible tubing, a vacuum pump (available at Pep Boys), and a manometer or vacuum gauge.

 

2. Again, short the emitter and collector of Q1 to provide power to the pressure sensor.
3. Record the initial voltage across the sensor as V0
4. Get the local barometric pressure (in inches of mercury – typically around 30) and record as P0
5. Connect the vacuum gauge and vacuum pump to the sensor using the following diagram:
6. Squeeze the pump until the gauge indicates a vacuum of 1” of mercury.
7. Record the voltage across the sensor as V1.
8. Perform the following calculations:

Using the above terms, barometric pressure can be calculated from the sensor voltage as:

Pressure = m * Voltage + b

C. Humidity
I found the humidity sensor to be pretty accurate and to not require calibration. However, be sure to follow the construction tips in this article to insure good performance.

IV. Weather Monitor Application Program

To take full advantage of the Remote Weather Monitor, I wrote a simple program in Visual Basic to collect the data from the base station, perform the calibration corrections and data conversions, and display it on the screen. Buttons are provided to display the basic data using a small window or to plot the data for the last 24 hours. See Figure 8 for a screen shot of the monitor window.

V. Closing

An engineer’s work is never complete – there’s always room for improvement. A couple of things could be done to further embellish this design. First and foremost, the protocol between the remote and base stations could be modified to support multiple remotes. This would allow monitoring the climate, inside, outside, in the attic, etc.

The second improvement would be the addition of an anemometer. If time had permitted, I would have designed one based on ultrasonic transducers. This would have allowed measurements of wind speed and direction and, when combined with temperature, wind chill.

But, I’ll get to those projects later. According to my data, it’s too nice of a day to be inside.

VI. Appendix

A. Ensuring Data Integrity with Hamming Codes
In mission critical applications when there is only one opportunity to exchange data, it is common to employ Forward Error Correction, or FEC. One application of this technique is for the data sent from a distant satellite – because of the time delays inherent with the great distances between a space probe and ground station, it is more efficient to encode the transmitted data with Forward Error Correction than to request a retransmission. FEC is accomplished by transmitting extra bits with an n-bit sequence so that errors can be detected and corrected by the receiver. One common implementation of FEC is through the use of Hamming codes.

In our application, the basic data block consists of a 10-bit A/D value. By adding four parity bits for the Hamming code, we increase our block size to 14 bits but with the added benefit of being able to detect and correct a single bit error. Consider the following data arrangement:
 

Position

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Contents

P1

P2

D9

P4

D8

D7

D6

P8

D5

D4

D3

D2

D1

D0

P1, P2, P3, and P4 are our parity bits while D9-D0 are our A/D reading. To calculate each of the parity bits, we use modulo-1 arithmetic. With modul0-1 arithmetic, the sum of an even number of 1’s results in a zero while the sum of an odd number of 1’s results in a 1.

Each of the parity bits is calculated using the equations below:

P1=D9+D8+D6+D5+D3+D1

P2=D9+D7+D6+D4+D3+D0

P4=D8+D7+D6+D2+D1+D0

P8=D5+D4+D3+D2+D1+D0
 

On the receive side, the Check bits are calculated from:

C1=P1+D9+D8+D6+D5+D3+D1

C2=P2+D9+D7+D6+D4+D3+D0

C4=P4+D8+D7+D6+D2+D1+D0

C8=P8+D5+D4+D3+D2+D1+D0
 

If there are no errors in the data, the value of the nibble formed by C8-C4-C2-C1 will be zero. If there is an error, the value of C8-C4-C2-C1 will contain the bit location that requires correction. To correct the bit, just invert its value!
 

Examples:

Let’s assume that we have an A/D value of 3A8h or 1111001000b. Our transmitted Hamming code for this block becomes:

Position

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Contents

P1

P2

D9

P4

D8

D7

D6

P8

D5

D4

D3

D2

D1

D0

Value

0

0

1

1

1

1

1

1

0

0

1

0

0

0

On the receive side we might receive the following:

Position

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Contents

P1

P2

D9

P4

D8

D7

D6

P8

D5

D4

D3

D2

D1

D0

No Error

0

0

1

1

1

1

1

1

0

0

1

0

0

0

Error in bit 9

0

0

1

1

1

1

1

1

1

0

1

0

0

0

Error in bit 3

0

0

0

1

1

1

1

1

0

0

1

0

0

0

When the data is received correctly, the code values are:

C8=1+0+0+1+0+0+0=0

C4=1+1+1+1+0+0+0=0

C2=0+1+1+1+0+1+0=0

C1=0+1+1+1+0+1+0=0
 

Thus the check code, C8C4C2C1, is equal to 0000b when the data is correctly received.

When an error occurs in the ninth bit, the check code values are:

C8=1+1+0+1+0+0+0=1

C4=1+1+1+1+0+0+0=0

C2=0+1+1+1+0+1+0=0

C1=0+1+1+1+1+1+0=1
 

C8C4C2C1=1001 indicates the erroneous bit position of 9.

Finally if an error occurs in the third bit, we get:

C8=1+0+0+1+0+0+0=0

C4=1+1+1+1+0+0+0=0

C2=0+0+1+1+0+1+0=1

C1=0+0+1+1+0+1+0=1

C8C4C2C1=0011 confirms the erroneous bit position of 3.

B. Images - click for a larger view

C. Source and design Files

PIC uProcessor HEX and ASM files
WeatherMon - Visual Basic Application Program
Gerber files for transceiver layout

Sponsored Recommendations

Highly Integrated 20A Digital Power Module for High Current Applications

March 20, 2024
Renesas latest power module delivers the highest efficiency (up to 94% peak) and fast time-to-market solution in an extremely small footprint. The RRM12120 is ideal for space...

Empowering Innovation: Your Power Partner for Tomorrow's Challenges

March 20, 2024
Discover how innovation, quality, and reliability are embedded into every aspect of Renesas' power products.

Article: Meeting the challenges of power conversion in e-bikes

March 18, 2024
Managing electrical noise in a compact and lightweight vehicle is a perpetual obstacle

Power modules provide high-efficiency conversion between 400V and 800V systems for electric vehicles

March 18, 2024
Porsche, Hyundai and GMC all are converting 400 – 800V today in very different ways. Learn more about how power modules stack up to these discrete designs.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!