Discovering Arduino and fascinating world of electronics

How to measure temperature with Arduino and MCP9700

Posted: September 13th, 2010 | Author: | Filed under: arduino, For beginners, howto | Tags: , , | 9 Comments »

One of the sensors included in Arduino Starter Kit is a temperature sensor. It’s analog device which doesn’t need any additional elements to work (it’s exactly MCP9700-E/TO). So, briefly speaking, after connecting ground and power supply we are already able to measure temperature. On the sensor’s page in Nettigo shop there is PDF datasheet in Files bookmark. So, let’s begin from terminals:

MCP9700 pinout

MCP9700 pinout

Important – the terminals are showed from the bottom of the sensor. To the first we connect supply voltage (both 3.3V and 5V from Arduino would be OK), ground (GND) goes to the third and the second terminal should be connected to Arduino Analog0 pin. As we can read from the datasheet (first page), sensitivity equals 10 mV/ºC. On the second page we have Output Voltage, 500 mV for 0°C. That’s all we should know to write a simple program:

float temp;

void setup() {
  Serial.begin(57600);
};

void loop () {
  temp = analogRead(0)*5/1024.0;
  temp = temp - 0.5;
  temp = temp / 0.01;
  Serial.println(temp);
  delay(500);
};

The program measures temperature and sends the reading to Serial, from which we can read it using serial port monitor in Arduino IDE. How the temperature is calculated? I divded the whole process in three steps to make it easier to understand:

  1. temp = analogRead(0)*5/1024.0; Reading value from analog input and converting it to voltage. Maximal voltage Arduino is able to measure equals 5V and the A/D converter’s resolution is 10 bits, which means 1024 values, thus voltage value on Analog0 input is the value returned by analogRead multiplied by the voltage equaling one step of A/D converter. You have to remember, that dividing 5 by 1024 would be interpreted by compiler as integer operation and the result in this case will equal 0. Because of this in the code appears 1024.0 and thanks to this entry, the compiler will treat the dividing as floating point operation.
  2. temp = temp - 0.5; Calibrating to 0°C – the difference between voltage read from the sensor and 500 mV is linearily dependent on temperature.
  3. temp = temp / 0.01; This difference is divided by 10mV/step and now we have temperature

As you can see, the MCP9700 sensor is very simple to use and beginners-friendly. Now everyone can measure temperature with Arduino.


9 Comments on “How to measure temperature with Arduino and MCP9700”

  1. 1 JT said at 19:29 on September 22nd, 2010:

    This really helped me out to get the MCP9700 going on my arduino. What do you do to get the readings into the realm of sanity? My readouts bounce around by 5 degrees constantly. I’m thinking I am going to read a bunch of samples to average them together or is there something else I can do to get a more stable readout? Have you gotten any better precision with a different voltage?

  2. 2 nettigo said at 20:41 on September 22nd, 2010:

    I’m using MCP9700 mostly powered with 5V. I have no problems with readout stability, results are repeatable. I was using many (like 10) different sensors bought in few lots so I think it is quite good sample…

  3. 3 Temperature and LCD | Starter Kit said at 23:24 on October 10th, 2010:

    [...] that, in loop we are reading temperature form MCP-9700 (described in this post). Having the temperature already, we are showing Temp: text and the reading, and going back to the [...]

  4. 4 nettigo said at 13:27 on October 12th, 2010:

    Quick note – if You have troubles with readouts stability – verify how Arduino is powered. If via USB – then maybe computer does not give 5V. If You use external power – ground shield well – I had problems with ADC when no ground and external power was used.

    You can read more here http://translate.google.com/translate?js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&sl=pl&tl=en&u=http%3A%2F%2Fstarter-kit.nettigo.pl%2F2010%2F10%2Fco-mierzy-analogread%2F

    At some point this post will be translated and published here, but for now Google Translate has to do work (or if You speak polish :) )

  5. 5 nettigo said at 23:03 on October 20th, 2010:

    http://starter-kit.nettigo.eu/2010/what-analogread-actually-measures/ post mentioned above is now translated to English. Enjoy.

  6. 6 Beaglebone + thermal sensor with ROS | Flesh and machines said at 16:10 on January 14th, 2013:

    [...] http://starter-kit.nettigo.eu/2010/how-to-measure-temperature-with-arduino-and-mcp9700/ [...]

  7. 7 ZeedijkMike said at 19:11 on November 30th, 2013:

    Hi there,

    I have some problems with the accuracy of the temperature read-out.
    If I compare the temperature with a thermo-coupler thermometer, I get large differences at higher temperatures.
    At 25°C the values fit.
    At 100°C, MCP9700 gives 84°C.
    My setup is as follows;
    MCP9700, thermo-coupler and heater (resistor) packet tightly together.
    Anyone else trier to compare their values with an external thermometer?

  8. 8 nettigo said at 22:28 on November 30th, 2013:

    To be honest I have not tested MCP with temperatures over 40 degrees, so hard to say what can be wrong. I’ll try to setup some test env, using DS18B20 as reference, I’m curious what it will show…

  9. 9 Curtis said at 21:24 on December 23rd, 2013:

    I have the Lilypad USB board + the Lilypad Temp version (MCP9700). Very simple code as copied from you. The ref is 3.335, verified using DMM. As you can see, the output is jumping all over the place. I have a SHT11 and DS18B20 right next to it on another board and both are reporting 26 +/- 0.25 C apart from each other. The MCP9700 is jumping all over the place and plus not close. I’ve even used a Temporal Scanner to check the temp and all 3 are close, except the MCP9700. I tried a second one with the same results. Any ideas?

    float temp;

    void setup() {
    Serial.begin(9600);
    };

    void loop () {
    temp = analogRead(2)*3.335/1024.0;
    temp = temp – 0.5;
    temp = temp / 0.01;
    Serial.println(temp);
    delay(1000);
    };

    21.65
    18.72
    17.42
    18.72
    17.42
    20.02
    18.72
    18.72
    21.65
    21.65
    17.42
    23.28
    21.65
    18.72
    17.42


Leave a Reply