http://starter-kit.nettigo.eu/2010/how-to-measure-temperature-with-arduino-and-mcp9700/
https://www.sparkfun.com/datasheets/DevTools/LilyPad/MCP9700.pdf
How to measure temperature with Arduino and MCP9700
Posted: September 13th, 2010 | Author: markal | Filed under: arduino, For beginners, howto | Tags: arduino, starter-kit, temperature | 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: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:
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 appears1024.0
and thanks to this entry, the compiler will treat the dividing as floating point operation.temp = temp - 0.5;
Calibrating to 0°C – the difference between voltage read from the sensor and 500 mV is linearily dependent on temperature.temp = temp / 0.01;
This difference is divided by 10mV/step and now we have temperature
No hay comentarios:
Publicar un comentario