Wednesday, October 26, 2011

Temperature (CIRC-10)

Purpose
The purpose of this lab is to analyze how a temperature sensor works. Here we are reporting information instead of controlling something.


Equipment

  • 1 x Temperature Sensor (TMP36)
  • 5 x Wires
  • 1 x Breadboard & reference sheet
  • 1 x Arduino Uno
Program Details

     Assembling this circuit takes up to 5 minutes, usually less. It is important to wire the temperature sensor correctly, it is often overlooked. See the assembled circuit below.




     The program starts by introducing the only variable component attached to a pin, the temperature sensor. In the setup the program establishes a 'serial' connection with the computer so that later we can print the results. There is a button beside upload, a box with an antenna which opens the screen to display the output. The number in the brackets is the transmitting speed.  Since this program looks at a different overall function, displaying output on the computer, the program is a little different, but not necessarily hard. The main loop starts by branching off into the function 'getVoltage'. This function reads the temperature, converts it to a readable code and then returns the value. This value, 'temperature' is then converted to an actual temperature reading. Finally, 'Serial.println(temperature0' displays the temperature.

Results

      Due to the malfunction of our temperature sensor, the outputs that were printed on the screen were unreliable. The temperature was constantly fluctuating from numbers as low as -40, to numbers as high as 300, and then numbers close to 0. We tried another sensor, but none of them worked properly (same problem).Afraid of the sensor catching on fire, we were advised to detach the temperature sensor. Below is a screen shot of the outputs we were getting:




Tips

     The most important precaution is not to touch the temperature sensor with your hands, while and right after it is unplugged. This is because there is a risk of malfunction, you can burn yourself and the sensor can even catch on fire. As soon as you notice that the temperatures are drastically incorrect, unplug the Arduino from the computer. Also while assembling, make sure the temperature sensor is pugged in correctly before uploading the program.

Next Steps & Associated Program Modifications

     The output of this program is so basic, there are only small possible modifications. For example, the serial speed at the beginning can be changed. We can also display the temperature in another way, farenheit! This can be done by simply changing the line that calculates the temperature. See the code below.





int temperaturePin = 0; //the temperature sensor is connected to analog pin 0


void setup()
{
  Serial.begin(9600);  //in the setup we are starting a connection with the computer in order
  //to later print the information
}


void loop()                    
{
float temperature = getVoltage(temperaturePin);  //gets the digital reading from the temperature
                                                  //sensor by running the function getVoltage (see bottom)
temperature = (((temperature – .5) * 100)*1.8) +32;          //converts the digital number to the appropriate
                                                  //temperature in farenheit
Serial.println(temperature);                     //prints the temperature
delay(1000);                                     //pause for a second before repeating
}


float getVoltage(int pin)
{
return (analogRead(pin) * .004882814); //gets the appropriate temperature reading (analog),
                                        //converts it to a number in the digital range,
                                        //and returns it to float(temperature)
}


Reference: Spark Fun Inventor's Guide

No comments:

Post a Comment