Equipment:
- Arduino x 1
- Breadboard x 1
- Arduino Holder x 1
- CIRC-10 Breadboard Sheet x 1
- TMP36 Temperature Sensor x 1
- Wire x 5
References:
- http://www.oomlout.com/a/products/ardx/circ-10
- http://ardx.org/src/circ/CIRC10-sheet-SPAR.pdf
- http://ardx.org/src/circ/CIRC10-code.txt
Program Details:
Once again, a new piece of hardware is introduced in this circuit. It is the temperature sensor, and it looks exactly like the transistor. To tell them apart you must read the label on the head. If it says TMP36, then its a temperature sensor, otherwise, its a transistor. The temperature sensor requires 3 connections. One is connected to power (in this case 5v), one connected to ground and one connected to an analog pin for input. What the temperature sensor does is sense the temperature in the room and convert it into electricity and then sends it to the computer through the analog pin. Then using the program, we convert the electricity into numbers and use the program to display it.
Many new things are introduced in terms of programming. First up, a pre-made class named Serial. The purpose of Serial is to create a connection between the computer and arduino. It is also used to display the temperature inputted by the arduino through the line Serial.println();. Serial.begin(); is used to determine the speed at which the information is begin transferred back and forth. The other new concept introduced in this program is a method which has a data type. The method float getVoltage(int pin);, returns a value at the end of the method of type float. Float is a number with decimals between -3.40 and 3.40. The returned value is then used by the line of code that called the method, so now float temperature is equal to the value returned by the method.
Time to Complete: 5 mins to assemble
10 mins to code
Results: The circuit and the program both ran perfectly the first time. However, what the temperature sensor was displaying was wrong or out of range at first. After 30 seconds or so, it started becoming close to room temperature (around 18 - 25 degrees Celsius).
Pictures:
Tips:
- Make sure you are using TMP36 temperature sensor and not the Transistor, they both look the same
- If the temperature sensor is displaying temperatures above 35 degrees Celsius, then disconnect the wire from the computer, it may be over-heating.
- Don't forget to click on Serial Monitor in the arduino program menu after uploading the program to display the values.
Further Work: I will convert the temperature from Celsius to Fahrenheit by using simple math. I will also test what happens when I change the serial speed and what the optimal serial speed for the arduino is.
Program Modifications: The program is very similar to the one in the link below. However we did change one thing. We changed the delay speed to make the program display the temperature faster. Rather than displaying it every second, we made it display the temperature every half second or every quarter second.
Program:
int temperaturePin = 0; // The temperature senosor is connected to Analog Pin 0
void setup()
{
Serial.begin(9600); // A serial connection between the arduino and computer is made
}
void loop()
{
float temperature = getVoltage(temperaturePin); // Stores the voltage from temperaturePin into variable temperature
temperature = (temperature - .5) * 100; // Converts from 10 mv per degree to degrees Celsius
Serial.println(temperature); // Prints the results in the serial monitor
delay(500); // Delays 500 milliseconds
}
float getVoltage(int pin) // Returns the voltage from the analog pin
{
return (analogRead(pin) * .004882814); // Converting from a 0 to 1024 digital range
}
No comments:
Post a Comment