CART
  • Cart is empty.

    ItemQuantityPrice

    Total: $0

Humidity and Temperature Measurement using TH-1-SHT


This example measure ambient temperature and humidity using the TH-1-SHT peripheral board and sends the results in human readable form to the RS232 Serial port of the MINI-MAX/51 board. Results are displayed as degrees Celsius and percent humidity ( relative humidity ).

Toolkit:Micro C 8051 Development System

Location:\bipom\devtools\microc\examples\8051\medium\SHT7x

Code Example


	for(;;)
	{
		// Read raw temperature value from Sensirion

		ec = SHT_Measure( &temperature, &cs, MEASURE_TEMP );

		if( ec ) 
		{
			printf ("\n ERROR Reading Temperature"); 
			continue;
		}
		
		// Read raw humidity value from Sensirion

		ec = SHT_Measure( &humidity, &cs, MEASURE_HUMI );
		
		if( ec ) 
		{
			printf ("\n ERROR Reading Humidity"); 
			continue;
		}
		
		//printf ("\n 14-bit temperature: 0x%04x",temperature);

		//printf ("\n 12-bit humidity   : 0x%04x",humidity);

		
		// Convert raw values to human readable form

		SHT_Calculate(&temperature, &humidity);
		
		printf ("\n Temperature: ");
		
		if ( temperature & 0x8000)	printf ("-");
		else						printf ("+");
		
		temperature &=(~0x8000);
		
		// Display temperature as Celcius

		printf ("%d.%dC", temperature10, temperature%10 );
		
		// Display humidity as RH%

		printf ("\n Humidity   : %d.%d%%", humidity10, humidity%10 );

		// Wait a little bit before next measurement

		delay(2000);
	}