SparkFun Inventor's Kit for MicroView
Experiment 6: Temperature Sensor
A temperature sensor is exactly what it sounds like – a sensor used to measure ambient temperature. This particular sensor has three pins – a positive, a ground, and a signal. This is a linear temperature sensor. A change in temperature of one degree centigrade is equal to a change of 10 millivolts at the sensor output. The TMP36 sensor has a nominal 750 mV at 25°C (about room temperature). In this circuit, you’ll learn how to integrate the temperature sensor with your MicroView, and use the serial monitor to display the temperature.
Parts Needed
You will need the following parts:
- 1x TMP36 Temperature Sensor
- 2x Jumper Wire
Breadboard Setup
Hook up your circuit as pictured below:
Be sure to insert the TMP36 in the correct orientation. It is polarized and will not work if inserted incorrectly.
Once you are sure orientation is correct, you can place the remaining jumper wires.
MicroView Arduino Code
language:c
#include <MicroView.h> // include MicroView library
MicroViewWidget *widget; // declare widget pointer
int sensorPin = A0; // select the input pin for the temperature sensor
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(sensorPin,INPUT); // set sensor pin as INPUT
uView.begin(); // start MicroView
uView.clear(PAGE); // clear page
widget = new MicroViewGauge(32,24,0,255,WIDGETSTYLE1); // declare as gauge widget
uView.drawChar(47,33,67); // Character C is ASCII code 67
}
void loop() {
sensorValue= analogRead(sensorPin); // read sensor pin value
float voltage = sensorValue * 5.0; // voltage at pin in volt
voltage /= 1024.0; // voltage = sensorValue x (5/1024)
float temperatureC = (voltage - 0.5) * 100 ; // C = (voltage - 0.5) x 100
widget->setValue(temperatureC); // set temperature value to the gauge
uView.display(); // display gauge tick
}
What You Should See
As you warm and cool your temperature sensor, you should be able to see the gauge on your MicroView's display go up or down.
Troubleshooting
Temperature Value is Unchanging
Try pinching the sensor with your fingers to heat it up or pressing a bag of ice against it to cool it down.
Still No Success?
A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: TechSupport@sparkfun.com