Go Down

Topic: lm35 temperature  (Read 223 times) previous topic - next topic

1lararahill

I am trying to read the temperature from the sensor and print on the serial port, however the readings arent correct. seems to be adding values cant seem to spot my error help would be appreciated.
i want the result in degress celsius
const int LM35pin=A1; //LM35 (Temperature)
const int NUM_SAMPLES=50; //

int data[NUM_SAMPLES]; //buffer
long stamps[NUM_SAMPLES];

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 38400 bits per second:
  Serial.begin(38400);
}

// the loop routine runs over and over again forever:
void loop() {
   // this will be the number of samples to measure
  for (auto i= 0; i<NUM_SAMPLES;i++){
  stamps=millis(); //get time-stamp
  data=analogRead(LM35pin); //get sample
  delay(20);//wait 20ms before next measurement
  }
   Serial.println("BLOCK");
  for (auto i=0; i<NUM_SAMPLES; i++) {
    Serial.print(stamps);//output time=stamp
    Serial.print(" "); //followed by
    Serial.print(data); //the sample
    Serial.println(); //one per line
  }

wildbill

How is the sensor wired up?

What values did you get? What did you expect?

AWOL

...and, can you see why we ask you to use code tags when posting code?

marco_c

Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

GolamMostafa

#4
May 03, 2019, 05:28 pm Last Edit: May 03, 2019, 05:30 pm by GolamMostafa
@OP

Can you detect the small adjustments that I have made on your original sketch to make the sketch be compiled and  working?

Code: [Select]
const int LM35pin = A1;     //LM35 (Temperature)
const int NUM_SAMPLES = 50; //

int data[NUM_SAMPLES]; //buffer
unsigned long stamps[NUM_SAMPLES];

// the setup routine runs once when you press reset:
void setup()
{
  // initialize serial communication at 38400 bits per second:
  Serial.begin(38400);
}

// the loop routine runs over and over again forever:
void loop()
{
  // this will be the number of samples to measure
  for (auto i = 0; i < NUM_SAMPLES; i++)
  {
    stamps[i] = millis(); //get time-stamp
    data[i] = analogRead(LM35pin); //get sample
    delay(20);//wait 20ms before next measurement
  }

  Serial.println("BLOCK");
  for (auto i = 0; i < NUM_SAMPLES; i++)
  {
    Serial.print(stamps[i]);//output time=stamp
    Serial.print(" "); //followed by
    Serial.print(data[i]); //the sample
    Serial.println(); //one per line
  }

Go Up