MCP9700 Linear Temperature Sensor
MTM06 (Make Tokyo Meeting 06) was held in Nov 20 and 21. In this event, Nakamura-san handed out MCP 9700 temperature sensor to mbed fans who purchased Starboad Orange (Base board) during the event. Thanks Nakamura-san!
The followings are sample program to measure temperature with MCP9700.
How to measure temperature
This sensor generate output voltage in proportion to temperature. Output voltage is given with the following formula:
Vout = Tc x Ta + V0
where:
- Vout = Sensor output voltage
- Tc = Constant value that increase output voltage in every 1.0°C (10mV)
- Ta = Ambient temperature
- V0 = Sensor Output Voltage at 0°C (500mV)
Therefore, temperature can be calculated from the following formula:
Ta = (Vout - V0) / Tc
That's say, measuring Vout using ADC (Analog Input) let you know ambient temperature. This formula is applicable for another linear temperature sensor - such as National Semiconductor LM35 - by modifying parameters. In addition to MCP9700, this class support MCP9701 and LM35 by specifying sensor type in constructor.
Connection to mbed
Sensor Pin | mbed Pin | Notes |
Vdd | VOUT (3.3V) | Red |
Vout | p20 | Blue |
GND | GND | Black |
Cods
Sensor handling is provided by LinearTempSensor class. This object accumulates N times of sample (default 10) and calculate average temperature using sampled data. Average is used to stabilize temperature readout.
The following is main routine to use this object. Text LCD class is also used to display measured data.
#include "mbed.h" #include "TextLCD.h" #include "LinearTempSensor.h" TextLCD lcd(p24, p26, p27, p28, p29, p30, TextLCD::LCD16x2); // RS, E, DB4, DB5, DB6, DB7 LinearTempSensor sensor(p20); // With default parameters //LinearTempSensor sensor(p20, 5, LinearTempSensor::MCP9700); // With option parameters int main() { float Vout, Tav, To; lcd.cls(); lcd.printf("TEMP:"); while(true) { Vout = sensor.Sense(); // Sample data (read sensor) Tav = sensor.GetAverageTemp(); // Calculate average temperature from N samples To = sensor.GetLatestTemp(); // Calculate temperature from the latest sample lcd.locate(5, 0); lcd.printf("%4.1f", Tav); printf("Vout:%f Tav:%f To:%f\n\r", Vout, Tav, To); // Debug print wait(2.0); } }
Program code with LinearTempSensor class : TempSensor
0 comments
You need to log in to post a comment