Friday, November 2, 2012

Temperature Measurement


I wrote a basic program for the Arduino to increase my knowledge of computer programming. I am studying to become a mechanical engineer so computer programming although not a focus of my studies is very important. A moderate knowledge of computer programming aids in  understanding the programs I may use in industry and will allow a solid foundation if I ever need to create my own program for specialized analysis.

I wrote my program by first researching for programs that are already created so I can analyze others' work for well and poorly designed systems. Then I outlined my goals for my program and then using the knowledge collected from research and from my background I wrote a program that I believe meets my goals. While writing my program I annotated each line of code to better understand what the code is doing for later reference and for other's to understand my code easily.

My Written Arduino Code:

//TMP36 Pin Variables
int temperaturePin = 0; 
//the analog pin the TMP36's Vout (sense) pin is connected to the 
//resolution is 10 mV / degree centigrade (500 mV offset) to make 
//negative temperatures an option

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600); 
  //Start the serial connection with the computer to view the result 
  //open the serial monitor last button beneath the file bar 
  //(looks like a box with an antennae)
}

void loop()        
// run over and over again
{
  static int t;
  // t is a local variable
  t++; 
 // time increases with each loop
  
 float celsius= getVoltage(temperaturePin); 
 //getting the voltage reading from the temperature sensor
 celsius= (celsius- .5) * 100;          
 //converting from 10 mv per degree wit 500 mV offset
 //to degrees ((volatge - 500mV) times 100)   
                  
float fahrenheit= (celsius*9/5)+32;          
//converting the read temperature from celsius to fahrenheit 

 Serial.println("Time [s]");              
 // prints the label for time 
 Serial.println(t);       
 // prints the time elapsed 

 Serial.println("Temperature [F] and [C], respectively");     
 // prints the label temperature converted and read
 Serial.println(fahrenheit);       
 // printing the temperature in fahrenheit
 Serial.println(celsius);    
 // printing the temperature in celsius 

 Serial.println(" ");            
 // prints a space between each loop to help organize the serial monitor

 delay(993); 
 // delays 1 sec minus the error of approx 7 millisec per loop from the 
 //arduino processing and looping, (error calculated experimentally)

 }

/*
 * getVoltage() - returns the voltage on the analog input defined by
 * pin
 */
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); 
 //converting from a 0 to 1023 digital range to 0 to 5 volts 
 //(each 1 reading equals ~ 5 millivolts
}

My code in action:

Ice on 1/8in Aluminum (only 60 sec intervals displayed)

Time [s]
1
Temperature [F] and [C], respectively
72.96
22.75

Time [s]
60
Temperature [F] and [C], respectively
71.20
21.78


Time [s]
120
Temperature [F] and [C], respectively
68.56
20.31

Time [s]
180
Temperature [F] and [C], respectively
67.68
19.82




Hot tap water poured into plastic bottle:

Time [s]
1
Temperature [F] and [C], respectively
77.35
25.20

Time [s]
2
Temperature [F] and [C], respectively
77.35
25.20

Time [s]
3
Temperature [F] and [C], respectively
77.35
25.20

Time [s]
4
Temperature [F] and [C], respectively
78.23
25.68

Time [s]
5
Temperature [F] and [C], respectively
79.11
26.17

Time [s]
6
Temperature [F] and [C], respectively
79.11
26.17

Time [s]
7
Temperature [F] and [C], respectively
79.99
26.66

Time [s]
8
Temperature [F] and [C], respectively
80.87
27.15

Time [s]
9
Temperature [F] and [C], respectively
80.87
27.15

Time [s]
10
Temperature [F] and [C], respectively
81.75
27.64



My code is based off of the code found at http://www.oomlout.com/oom.php/products/ardx/circ-10. However, I modified the code to be easier to read in the serial monitor output by including the time at which data was collected and labeling the data. I also included measurements in both Celsius and Fahrenheit to save time if conversion was needed. Lastly, I let my program run for an hour so I could calculate the error in the time reading caused by the Arduino looping the program and processing data. I then corrected the delay time to take into account the error for accurate data collection.


Tuesday, October 30, 2012

Blog Purpose

The purpose of this blog is to begin the creation of a professional portfolio for future application to jobs and internships related to engineering.