Temp measurement using LM35 sensor and logging on EEPROM

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.

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

}

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?

talofer99:
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

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/

#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

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?

april:
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.

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.

talofer99:
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.

no worries .... I was not that clear ... english is not my native langauge :slight_smile:
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.

Double post -Please remove

april:

talofer99:
no worries .... I was not that clear ... english is not my native langauge :slight_smile:
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

sure ... I really don't mind.
the yoghurt is on its way :wink:

talofer99:
no worries .... I was not that clear ... english is not my native langauge :slight_smile:
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

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

talofer99:
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...

Hi everybody :slight_smile:

This is very interesting. How do you then read out the EEPROM or dump it somewhere to use it ?

Thanks.

Have you considered using an external EEPROM e.g. using I2C -> 24LC256 /24LC512 which has 32/64 KB of memory?
See - I2C EEPROM Class on playground - Libraries - Arduino Forum - for a lib.
with these external EEPROM you can store far more data than in the internal EEPROM of the Arduino.