LM35 Temperature Sensor

Hi,

I'm really new to Arduino's, and recently got my Uno R3. Anyways I went ahead and eventually got the LCD and potentiometer working. However I decided to add an LM35 temperature sensor, the thing is that all my pins for 5V and GND have already been used up, so I connected to one of the existing 5V connections from the potentiometer and arduino(I put it one pin above the 5v.) I fired up the code but it displayed 0.00 as the temperature. Here is a picture of the setup, I haven't put in the GND wire from the sensor. Can someone please explain to me how I will be able to share a GND and 5v connection? I'm connected via USB so I don't think power distribution should be an issue.

My 16x2 LCD also has a backlight feature.

Thank You

Okay, so I put the Ground on the - rail on the breadboard and I put the 5v on the + rail on the breadboard so I can distribute and share the connections. I’m still getting 0.00 for temperature. I added a LM35 library.

Heres the code.

#include <LiquidCrystal.h>
#include <LM35.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LM35 sensor1(A0);//PIN A0
double temp = sensor1.read();

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);
 // Print a message to the LCD.
 lcd.print("Temperature:");
}

void loop() {
 lcd.setCursor(0, 1);
 lcd.print(temp);//prints temp
}

Disregard that. I fixed the code.

#include <LiquidCrystal.h>
#include <LM35.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LM35 sensor1(A0);//PIN A0

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);
 // Print a message to the LCD.
 lcd.print("Temperature:");
}

void loop() {
 double temp = sensor1.read();
 lcd.setCursor(0, 1);
 lcd.print(temp);//prints temp
}

Try to read the analog value in A0 with analog.read(A0) and print it into LCD or serial port

Hmm.

When I use this code:(with analogRead)

#include <LiquidCrystal.h>
#include <LM35.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LM35 sensor1(A0);//PIN A0

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Temperature:");
}

void loop() {
  double temp = analogRead(A0);
  lcd.setCursor(0, 1);
  lcd.print(temp);//prints temp
  lcd.print("C");
}

I always get 33.00C which is definitely wrong.

And when I use this code:

#include <LiquidCrystal.h>
#include <LM35.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LM35 sensor1(A0);//PIN A0

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);
 // Print a message to the LCD.
 lcd.print("Temperature:");
}

void loop() {
 double temp = sensor1.read();
 lcd.setCursor(0, 1);
 lcd.print(temp);//prints temp
}

I always get 16.13C or 16.64C, doesn’t matter what time of day. It always stays at either of those two numbers. If I move the pins a bit they will fluctuate. I don’t understand why it isn’t giving me an accurate enough reading.

Your two pieces of code are telling you the same thing.

When you used the code with the analog read you saw a value of 33 which is not a temperature, but is a value from 0 to 1023 which is the analog read of 0 to 5 volts. http://arduino.cc/en/Reference/AnalogRead

Essentially, each count is 4.88mv

When you use the conversion factor for the LM35 of 10mv/C you come up with the math which says to multiply the analog read value by 0.48875855 to get degrees C which is the value used in the library.

33 x the magic number is 16.13 degrees C which is what you are getting in your second sketch which uses the library.

Based on what I see in the LM35 data sheet, there should be a 2 degrees C offset so your temperature would be 18.13C. What do you think the ambient temperature is?

What is not clear to me is why you don't see the temperature value change. Try holding the sensor in your fingers, or blow on it, or somehow get it hotter, and see if you can get it to change.

Nothing seems to change the temperature unless I move the LM35 around a bit then it flickers and changes to either 16.64 or 15.64, but I tried blowing on it, keeping my fingers on the sensor, it still stays the exact same.