14 weather

11
237 Chapter 14. Weather Monitoring System 14.1.1. Objective Our objective is to design a weather monitoring system interfacing various sensors with the Cypress PSoC 1 Evaluation board. The weather system is capable of capturing the following measurements. Humidity Temperature Ambient Light Wind Speed Rain The values calculated by the PSoC are sent to a PC using a USB-UART connection. These values can be updated dynamically. 14.1.2. System Design Figure 280: Weather Monitoring System Design 14.1.3. Conceptual Background The idea of interfacing all the above sensors with PSoC, is to explore the potential and understand the full functionalities of a PSoC. In contrast to a design based on microprocessor, the PSoC integrates all the external hardware that would have been needed in to a single chip, facilitating a very less time to design. The PSoC consists of both Analog and Digital blocks that are configurable, some even during run time. The user modules offer a variety of small systems that can be placed in the digital or analog blocks accordingly. In the current project, we used 3 analog sensors and 2 switch based sensors (that can be modeled as digital outputs). 14.1.4. Equipment Required PSoC 1 Evaluation board MiniProg ½

Upload: nika-kobaidze

Post on 06-May-2017

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 14 Weather

237

Chapter 14. Weather Monitoring System

14.1.1. Objective

Our objective is to design a weather monitoring system interfacing various sensors with the Cypress PSoC 1

Evaluation board. The weather system is capable of capturing the following measurements.

· Humidity

· Temperature

· Ambient Light

· Wind Speed

· Rain

The values calculated by the PSoC are sent to a PC using a USB-UART connection. These values can be

updated dynamically.

14.1.2. System Design

Figure 280: Weather Monitoring System Design

14.1.3. Conceptual Background

The idea of interfacing all the above sensors with PSoC, is to explore the potential and understand the full

functionalities of a PSoC. In contrast to a design based on microprocessor, the PSoC integrates all the external

hardware that would have been needed in to a single chip, facilitating a very less time to design. The PSoC consists

of both Analog and Digital blocks that are configurable, some even during run time. The user modules offer a

variety of small systems that can be placed in the digital or analog blocks accordingly.

In the current project, we used 3 analog sensors and 2 switch based sensors (that can be modeled as digital outputs).

14.1.4. Equipment Required

· PSoC 1 – Evaluation board

· MiniProg – ½

Page 2: 14 Weather

238

· RS232 – USB connector

· Humidity sensor – HIH-4030/31

· Ambient Light sensor – TEMT6000

· Temperature sensor – LM335A

· Anemometer – p/n 80422

· Rain guage – p/n 80422

Figure 281: Equipment Used

Humidity Sensor (HIH-4031):

It needs a 5v dc supply. The output is an analog signal that varies in linearly with humidity.

RH = (Vout - 0.958) / 0.0307

Figure 282: Humidity Sensor (HIH-4031)

Ambient Light Sensor (TEMT6000): The supply voltage can be from 3.3v or 5v. In our case we used 5v dc supply. The output is an analog voltage that

ranges from 0v to 5v based on the brightness (luminance).

Page 3: 14 Weather

239

Figure 283: Ambient Light Sensor (TEMT6000)

Figure 284: Circuit Diagram Light Sensor

Temperature Sensor (LM 335A) It is also an analog sensor that gives an output between 0v and 5v with a linearity of 10mv per Kelvin change in

temperature.

Figure 285: Temperature Sensor (LM 335A)

Anemometer & rain gauge (p/n 80422) They are based on a reed switch, which is activated by the magnetic field produced during the motion of a sensor. The cup-type anemometer measures wind speed by closing the reed switch contact. A wind speed of 1.492 MPH causes the switch to close once per second. The rain gauge is a self-emptying tipping bucket type. Each 0.2794 mm of rain causes one momentary contact closure that can be recorded with a digital counter or microcontroller interrupt input. The gauge’s switch is connected to the two centre conductors of the RJ11-terminated cable.

Page 4: 14 Weather

240

Figure 286: Anemometer & rain gauge (p/n 80422)

Figure 287: Anemometer Basic Design

14.1.5. Choose and Place User Modules

The PSoC user modules required for each of the sensors are given below.

Table 5: User Modules Weather Monitoring

Humidity Amplifier(PGA) ADC (12 bit)

Light Amplifier(PGA) ADC (12 bit)

Temperature Amplifier(PGA)

ADC (12 bit)

Wind speed Timer 32 bit

Rain gauge Timer 8 bit

PSoC Usage:

· ROM 18% full. 5861 out of 32768 bytes used (does not include absolute areas).

· RAM 7% full. 120 bytes used (does not include stack usage).

In addition to the above, we need a UART user module to send data to a PC through USB. Another timer is also

used to update the data periodically to the UART.

Page 5: 14 Weather

241

The PSoC program is written in C language. As soon as it is programmed to the chip, press the reset button once.

Then after 3 seconds, the data appears on the hyper terminal. The new values get updated every 3 seconds. This

duration can also be altered by configuring the timer. (Check the configuration file).

Figure 288: Schematic

Figure 289: Pin out View

Page 6: 14 Weather

242

Figure 290: Top Design View

14.1.6. Coding #include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules #include "stdlib.h" // Header file used to support standard library function link ftoa #include "string.h" void initialize(void); void humidity(void); void brightness(void); void temperature(void); void windspeed(void); void rain(void); void welcomeScreen(void); #pragma interrupt_handler Timer24CaptureISR

Page 7: 14 Weather

243

#pragma interrupt_handler Timer8CaptureISR #pragma interrupt_handler Timer81CaptureISR #define DATA_AVAILABLE 0x01 #define FALLING_EDGE 0x02 int generate=0; int gcount=0; int speed_count=0; int rg_count=0; BYTE Flags; BYTE Flags8; char hm[10]="000000000"; char br[10]="000000000"; char tp[10]="000000000"; char ws[10]="000000000"; char rg[10]="000000000"; void main(void) { initialize(); while(1) { //if (UART_bCmdCheck() || rg_available || ws_available) if(generate) { UART_PutChar(12); humidity(); brightness(); temperature(); windspeed(); rain(); UART_CPutString("\n\rRelative Humidity %: "); UART_PutString(hm); //UART_CPutString("\n\r"); UART_CPutString("\n\rBrightness : "); UART_PutString(br); //UART_CPutString("\n\r"); UART_CPutString("\n\rTemperature : "); UART_PutString(tp); //UART_CPutString("\n\r"); UART_CPutString("\n\rWindSpeed: "); UART_PutString(ws); //UART_CPutString("\n\r"); UART_CPutString("\n\rRain : "); UART_PutString(rg);

Page 8: 14 Weather

244

UART_CPutString("\n\r"); generate=0; speed_count=0; UART_CmdReset(); } } } void initialize(void) { M8C_EnableGInt; PGA_1_Start(PGA_1_HIGHPOWER); ADCINC12_1_Start(ADCINC12_1_HIGHPOWER); ADCINC12_1_GetSamples(0); PGA_2_Start(PGA_2_HIGHPOWER); ADCINC12_2_Start(ADCINC12_2_HIGHPOWER); ADCINC12_2_GetSamples(0); PGA_3_Start(PGA_3_HIGHPOWER); ADCINC12_3_Start(ADCINC12_3_HIGHPOWER); ADCINC12_3_GetSamples(0); UART_IntCntl(UART_ENABLE_RX_INT); UART_Start(UART_PARITY_NONE); Flags = 0; // Start timer and enable interrupt Timer24_Start(); Timer24_EnableInt(); Timer24_FUNC_LSB_REG &= ~0x80; Timer8_Start(); Timer8_EnableInt(); Timer8_FUNC_REG &= ~0x80; Timer81_Start(); Timer81_EnableInt(); Timer81_FUNC_REG &= ~0x80; UART_CmdReset(); //Clear the screen in Hyper terminal window UART_PutChar(12); // Print welcome screen welcomeScreen(); } void humidity(void)

Page 9: 14 Weather

245

{ float f; int idata; while(!ADCINC12_1_fIsDataAvailable()); idata = ADCINC12_1_iGetData() + 0x0800; f = (float)idata * 0.00122; f = (f - 0.958)/0.0307; itoa(hm, f, 10); } void brightness(void) { float f; int idata; while(!ADCINC12_2_fIsDataAvailable()); idata = ADCINC12_2_iGetData() + 0x0800; f = (float)idata * 0.00122; f = (f*1000); itoa(br, f, 10); } void temperature(void) { float f; int idata; while(!ADCINC12_3_fIsDataAvailable()); idata = ADCINC12_3_iGetData() + 0x0800; f = (float)idata * 0.00122; f = (f*300/4.1); itoa(tp, f, 10); } void windspeed(void) { float f; f = (speed_count/3) * (1.493); itoa(ws, f, 10); } void rain(void) { //float f; //f = rg_count * 2.794;

Page 10: 14 Weather

246

itoa(rg, rg_count, 10); } void Timer24CaptureISR(void) { speed_count++; } void Timer8CaptureISR(void) { rg_count++; } void welcomeScreen(void) { UART_CPutString("\n\r........Welcome to TAMU Weather Station........."); UART_CPutString("\n\r............Updates every 3 seconds............."); UART_CPutString("\n\r"); } void Timer81CaptureISR(void) { generate=1; gcount++; }

14.1.7. Total Assembly

The sensors are mounted on the breadboard that is provided along with the PSoC. The RS232 port is connected to

the USB of a PC and the baud rate is set to be 19200. The 5v dc supply is available on the evaluation board. 2

(100K) resistors are used to pull down the interrupts used by the wind speed and rain gauge sensor.

Figure 291: Working Configuration

Page 11: 14 Weather

247

Figure 292: Anemometer connection

14.1.8. Expected Result Humidity 0% RH – 0.958 v

75% RH – 3.268v

Light Ev = 20 lx, standard light A

Temperature 0v – 0 K

10mv/K

Wind speed 1.492 MPH / per pulse

Rain gauge 0.2794 mm / per pulse

14.1.9. Suggested Modifications

The output data is currently being sent to a hyper terminal. It can be used to update an online webpage dynamically.

The entire assembly can be mounted on a building top and the PSoC is to be securely placed. The sampling

frequency of the ADCs can be reduced so that they consume less switching power. The digital switches can be

captured as I/O interrupts rather than timer interrupts so that only one timer can serve all the purposes.

14.1.10. References

· Cypress 210 chip level design tutorial.

· HIH-4030/31 Series datasheet.

· TEMT6000 datasheet.

· LM 335A Precision temperature sensor datasheet.

· Wind p/n 80422 datasheet.

· Cypress example project UART datasheet.