Pages: [1] 2   Go Down
Author Topic: Temp measurement using LM35 sensor and logging on EEPROM  (Read 4114 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I wanted to make a very basic Temperature logger using the standard Uno board and the LM35 sensor. Wanted to see how i could do data logging in the EEPROM vs a SD card etc. This code is the one i am currently using.

Code:
// Sketch to store 170 hours of temperature reading on internal EEPROM @ one reading every 10 mins

#include <EEPROM.h>

//declare variables

float tempC;
int tempPin = 0; // Analog pin used for measusing LM35 output
int EEPROMLOC = 0; // starting location for EEPROM write

#define aref_voltage 1.1  // reference voltage given to LM35, Using basic config of LM35 this is for 2-150 C @ 0mv + 10mv per degree centigrade

void setup()
{
  Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{


  analogReference(INTERNAL);  // sets ref voltage for conversion to 1.1 vs the default 5 V
  // This gives much better accuracy since the 10 bit ADC is spread over 1.1V vs the default 5V

  int sensorReading = analogRead(tempPin);           //read the value from the sensor i.e. 0-1023 after a ADC conversion

    Serial.print("Sensor Reading = ");
  Serial.println (sensorReading);

  float voltage = (sensorReading * aref_voltage * 1000) / 1024.0;  // Convert sensor

  // print out the voltage
  Serial.print(" Voltage from sensor :  ");
  Serial.print(voltage);

  Serial.println(" milli volts");

  float tempC = (voltage * 100.0);   //convert the analog data to temperature

  Serial.print(" Temperature :  ");
  Serial.print(tempC/1000);             //send the data to the computer
  Serial.println(" C ");


  //since the EEPROM can store only 0-255, need to get the value in range hence subtracting 150

  int EEPROMWriteInt = sensorReading-150;

  if (EEPROMLOC < 1024 )
  {

    Serial.print (" EEPROM Write at location ");
    Serial.print(EEPROMLOC);
    Serial.print (" value ");
    Serial.println(EEPROMWriteInt);             //send the data to the computer
    Serial.println("");  //blankline
    EEPROM.write(EEPROMLOC, EEPROMWriteInt);
    EEPROMLOC ++;

  }

  delay(600000);                           //wait 10mins; 900000 for a 15 min delay, 300000 for 5 mins and 600000 for 10 mins

}

Logged

Thailand
Offline Offline
Newbie
*
Karma: 1
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I did a project with lm35 as well. I outputted the temp to the serial interface and kept on getting VERY unbalanced reads up to 1-1.5C difference. From read to read
I even tried to aref it to 3.3 and it did not make it any better.
The end solution was to make an average of several reads over x amount of time.
My question to you is, If you to do a constant read will you get balanced read from the unit?  I'm couriers if that’s the reason you are supplying it with 1.1Volts?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I did a project with lm35 as well. I outputted the temp to the serial interface and kept on getting VERY unbalanced reads up to 1-1.5C difference. From read to read
I even tried to aref it to 3.3 and it did not make it any better.
The end solution was to make an average of several reads over x amount of time.
My question to you is, If you to do a constant read will you get balanced read from the unit?  I'm couriers if that’s the reason you are supplying it with 1.1Volts?



I am not getting unbalanced reads, graph of a of a 10 hour interval with samples every 5 mins is attached



On the question of why 1.1 volts :-
1. In am not supplying 1.1V, actually am using the 3.3 V output to drive the IC.
2. Am specifying 1.1 as the max voltage of the ADC. Normally the ADC use 5 V as the max voltage therefore as reading of 1024 = 5V, therefore the resolution / accuracy is ~ 5 mv. Now the accuracy increases 5 times to approx 1mv


* temp graph.jpg (129.45 KB, 1914x886 - viewed 59 times.)
« Last Edit: May 07, 2012, 05:40:44 am by sundeepgoel » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A more refined version with
1. Default LED attached to pin 13 - switched off to save power
2. Same LED set to blink for 200ms when data is written to the EEPROM

is available at : http://fotohobbist.com/blog/2012/05/07/temperature-measurement-using-lm35-sensor-and-logging-on-eeprom-with-arduino-uno/
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
#define aref_voltage 1.1  // reference voltage given to LM35, Using basic config of LM35 this is for 2-150 C @ 0mv + 10mv per degree centigrade
 
  analogReference(INTERNAL);  // sets ref voltage for conversion to 1.1 vs the default 5 V
  // This gives much better accuracy since the 10 bit ADC is spread over 1.1V vs the default 5V

float voltage = (sensorReading * aref_voltage * 1000) / 1024.0;  // Convert sensor

There is something strange about this . I'm looking into it
https://tronixstuff.wordpress.com/2010/12/07/tutorial-arduino-and-the-aref-pin/
Quote
Interestingly enough, our Arduino boards already have some internal reference voltages to make use of. Boards with an ATmega328 microcontroller also have a 1.1V internal reference voltage. If you have a Mega (!), you also have available reference voltages of 1.1 and 2.56V. At the time of writing the lowest workable reference voltage would be 1.1V.

So how do we tell our Arduinos to use AREF? Simple. Use the function analogReference(type); in the following ways:

For Duemilanove and compatibles with ATmega328 microcontrollers:

    analogReference(INTERNAL); – selects the internal 1.1V reference voltage
    analogReference(EXTERNAL); – selects the voltage on the AREF pin (that must be between zero and five volts DC)
    And to return to the internal 5V reference voltage – use analogReference(DEFAULT);

If you have a Mega:

    analogReference(INTERNAL1V1); – selects the internal 1.1V reference voltage
    analogReference(INTERNAL2V56); – selects the internal 2.56V reference voltage
    analogReference(EXTERNAL); – selects the voltage on the AREF pin (that must be between zero and five volts DC)
    And to return to the internal 5V reference voltage – use analogReference(DEFAULT)

Now that is really interesting -Thank You
Your range is 148 degrees C
I'm thinking then that if your temps fall between -20 and + 30C say that range of 50 C only being used over the 1.1V could increase the accuracy even further?
« Last Edit: May 08, 2012, 04:52:45 am by april » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


There is something strange about this . I'm looking into it

Now that is really interesting -Thank You
Your range is 148 degrees C
I'm thinking then that if your temps fall between -20 and + 30C say that range of 50 C only being used over the 1.1V could increase the accuracy even further?

I think you have got part of it, to clarify :-
1. The range is whatever is the range of LM35 sensor itself. Note : The LM35 sensor DC output varies in relation from 0-1V DC based on temp itself, NOT its input voltage
2. Because of the above, setting the max reference range of the ADC of the Uno board to 1.1V allow us to use almost the entire 1024 (entire cause 1.1 = 1024, whereas the max we'll get is 1.0). If we had used 5 V, and the sensor output varied from 0-1.0 V, effectively you would have used only 1/5th the range of the ADC. i.e. you would not have got a reading of more that ~ 204 (vs approx 900-920 now, i.e. whatever the 1.0v corresponds to) , makes sense ?
3. Since the Reference range (using internal Uno reference) cannot be set below 1.1V, this is the max you can get the sensitivity to be.
4. however, if you decide to use an external reference source of say 0.5V, then what you are saying is possible.
« Last Edit: May 08, 2012, 08:28:00 am by sundeepgoel » Logged

Thailand
Offline Offline
Newbie
*
Karma: 1
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the info on the 1.1  ..
but what I asked is ... lets say u do a read every 0.5sec .... hoiw would that graph looks like ?
One would except it to be some what balaced ... I wondered how it will look on your setup ..
with reeads every 0.5 I got diffrence of up to 2C .....
was wondering what your system will output.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the info on the 1.1  ..
but what I asked is ... lets say u do a read every 0.5sec .... hoiw would that graph looks like ?
One would except it to be some what balaced ... I wondered how it will look on your setup ..
with reeads every 0.5 I got diffrence of up to 2C .....
was wondering what your system will output.



oh, sorry, got your question wrong. Will try it and post soon, as of now have got it reading temp every 10mins for a week.
Logged

Thailand
Offline Offline
Newbie
*
Karma: 1
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no worries .... I was not that clear ... english is not my native langauge smiley
I would love to see the resaults you will get ...
this is the project I did with one :
http://www.facebook.com/media/set/?set=a.10150172887516174.295470.732646173&type=3&l=f139410948

And I need it to as accurate as I can ... or at LEAST stable  ... to control the cut ON/OFF temp.
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Double post -Please remove
« Last Edit: May 11, 2012, 04:06:08 pm by april » Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no worries .... I was not that clear ... english is not my native langauge smiley
I would love to see the resaults you will get ...
this is the project I did with one :
http://www.facebook.com/media/set/?set=a.10150172887516174.295470.732646173&type=3&l=f139410948
And I need it to as accurate as I can ... or at LEAST stable  ... to control the cut ON/OFF temp.
Could not paste on Facebook but for your english on the page  I revised yours for this -hope you won't mind


I have approached learning electronics several times in my life without much success since I had no real motivation. A few months ago I came across a post on the Arduino Board (http://www.arduino.cc/), and when more then 3-4 times we had to get  up in the middle of the night to switch off the yogurt incubator, it clicked …Why not build a time controlled incubator?

So in a spending spree  that lasted 2 weeks I ordered over 15 packages with all the basic things, including an Arduino set with LCD and IR receiver/transmitter and even a remote. Now that most of the things have arrived I finally did a test run of 10 min … And it worked like a charm. It also has a temp probe as you can see in the photos.

I'm still waiting on some parts. Like a PCB board to assemble all the parts on.
 The end product will include an SD card  to log each run, temp wise.
 The temp for now is only output, but its going to be utilised to controlling the power to the incubator as well.
 
I will post more photos, once I find the right casing which will be a bit difficult here. I might have to build one, mainly due to the BIG computer power supply that powers the show.


Just a quart of yoghurt will do as a fee
Logged

Thailand
Offline Offline
Newbie
*
Karma: 1
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sure ... I really don't mind.
the yoghurt is on its way smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

no worries .... I was not that clear ... english is not my native langauge smiley
I would love to see the resaults you will get ...
this is the project I did with one :
http://www.facebook.com/media/set/?set=a.10150172887516174.295470.732646173&type=3&l=f139410948

And I need it to as accurate as I can ... or at LEAST stable  ... to control the cut ON/OFF temp.


did a sample run of 500 readings, one every 0.5 secs. Pretty stable output, readings as per attached image / screenshot


* temp graph.jpg (59.38 KB, 1470x666 - viewed 49 times.)
Logged

Thailand
Offline Offline
Newbie
*
Karma: 1
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for that.
I might give it another go .. this time I will just take your code ....  I got a nother lm35  ....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for that.
I might give it another go .. this time I will just take your code ....  I got a nother lm35  ....


all the best...
Logged

Pages: [1] 2   Go Up
Jump to: