Sensor acquisition

From Contiki
Revision as of 11:54, 3 August 2014 by Nitin (Talk | contribs)

Jump to: navigation, search

Back to Contiki Tutorials


This article is about the Sensor Acquisition Program, which is used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.

Sensor Acquisition Program on the Tmote Sky!

Step 1

Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.

make TARGET=sky savetarget (This save the target for any future compilations)
make sensor-acq.upload (This will upload the code on the Tmote Sky)
make login (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)

Step 2

Press the reset button on the Tmote Sky. The following message will appear on the terminal window

Temperature=28.04 C (6764)
Humidity=73.20% (2259)
Light=38.26 lux (94)

Values inside the round brackets (ex 6764, 2259 and 94) are the actual sensor values and the calibrated values can be obtained by performing calculations on these sensor values. You can find the calculations at

Step 3

Press Ctrl-C to quit.


PROCESS(sensor_acq_process,"Sensor Acquisition");

      static struct etimer et;
      static int val;
      static struct sensors_sensor *sensor;
      static float s = 0;
      static int dec;
      static float frac;


      printf("Starting Sensor Example.\n");
	   etimer_set(&et, CLOCK_SECOND * 2);

           val = sht11_sensor.value(SHT11_SENSOR_TEMP);
      	   if(val != -1) 
		s= ((0.01*val) - 39.60);
      	  	dec = s;
      	  	frac = s - dec;
      	  	printf("\nTemperature=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100),val);               

	   if(val != -1) 
		s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));  
      	  	dec = s;
      	  	frac = s - dec;
      	  	printf("Humidity=%d.%02u % (%d)\n", dec, (unsigned int)(frac * 100),val);               

           val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
      	   if(val != -1) 
      		s = (float)(val * 0.4071);
      	  	dec = s;
      	  	frac = s - dec;
      	  	printf("Light=%d.%02u lux (%d)\n", dec, (unsigned int)(frac * 100),val);               

      } //end of while



Understanding the Code

etimer_set(&et, CLOCK_SECOND * 2);

This will set the timer to repeat the iterations every 2 seconds.

Back to Contiki Tutorials