Pages: [1]   Go Down
Author Topic: Time logging function and problem with temperature?  (Read 402 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I am currently working on one of the ARDX projects about temperature.
Basically, it is logging temperature from a TMP36 IC

Here is the code
 
Code:
/*     ---------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code             |
 *     |  CIRC-10 .: Temperature :. (TMP36 Temperature Sensor) |
 *     ---------------------------------------------------------
 *   
 *  A simple program to output the current temperature to the IDE's debug window
 *
 *  For more details on this circuit: http://tinyurl.com/c89tvd
 */

//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 copmuter
                       //to view the result open the serial monitor
                       //last button beneath the file bar (looks like a box with an antenae)
}
 
void loop()                     // run over and over again
{
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the temperature sensor
 temperature = (temperature - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 Serial.println(temperature);                     //printing the result
 delay(1000);                                     //waiting a second
}

/*
 * 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
}

I have 2 questions:
1. I replaced the TMP36 with LM35 because I don't have a TMP36. My readings are in negative values. Is there any reason why it should be?
I edited the code "temperature = (temperature - .5) * 100;" instead of .5 I changed it to 0.05 and it seems to give the right values. However I would like to confirm if I did it right?

2. I am wanting to add a time keeping function just like commercial dataloggers. Meaning, serial will print the temperature and the time since the start of the experiment. How should I code it in?

Thanks guys!
Logged

Germany
Online Online
Faraday Member
**
Karma: 49
Posts: 2748
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. I'm too lazy to search for datasheets to compare LM35 to TMP36 sensors
Quote
However I would like to confirm if I did it right
So read datasheets and check the maths. Do a calibration test with known temperatures over the whole range.

2.
Quote
Add a time keeping function just like commercial dataloggers. Meaning, serial will print the temperature and the time since the start of the experiment.
"commercial dataloggers" would apply RealTime timestamps, which is not available in a standard Arduino.
The "time since start of the experiment" is easier: take millis() and divide by 1000.

Spoonfeeding:  Add
Serial.print ( millis() / 1000); Serial.print (" s : ");
bfore your line
Serial.println(temperature);                     //printing the result

Getting hours/minutes/seconds from the number of seconds is beyond spoonfeeding.
If you're interested in that, give it a try yourself and only ask for help when really stuck.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46204
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to log clock time, you need a clock. The Arduino doesn't have one. It only has a stopwatch with a stop button that doesn't work. RTC (real time clock) chips are cheap and easy to use.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
2. I am wanting to add a time keeping function just like commercial dataloggers. Meaning, serial will print the temperature and the time since the start of the experiment. How should I code it in?

I had the same requirement on an Arduino project last year. I boutght an i2c rtc with integrated li-ion battery. On the Arduino, I used the Time library, which can use as a time source either the millis() function or an external i2c clock. Very convenient and easy to use. Quite heavy, but with lots of features to for time intervals manipulation.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12480
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

check this site - http://www.ladyada.net/make/logshield/ -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 5
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If your Arduino is connected to your PC while logging you can use GoBetwino to do the logging, including a timestamp.
Logged

Pages: [1]   Go Up
Jump to: