Temperature measurement using LM35 with Arduino and EEPROM logging

I wanted to make a very basic Temperature logger using temperature sensor LM35 with Arduino Uno. Also, wanted to see how i could do data logging in the EEPROM vs a SD card etc.

First the board and connections :-

 

Now the code:-

 

// Sketch to store 170 hours of temp 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
int LEDOnInterval = 200;
long tempLoggingInterval = 600000; //wait 10mins; 900000 for a 15 min delay, 300000 for 5 mins and 600000 for 10 mins

#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
  pinMode(13, OUTPUT); // for the onboard LED     
  digitalWrite(13, LOW);    // set the LED off
}

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 ++;
    digitalWrite(13, HIGH);   // set the LED on
    delay(LEDOnInterval);     // wait for a second
    digitalWrite(13, LOW);    // set the LED off

  }

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

}

//------------------------

6 thoughts on “Temperature measurement using LM35 with Arduino and EEPROM logging

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>