Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[Arduino] LM35 temperature sensor

Status
Not open for further replies.

guitarnoob123

Junior Member level 1
Joined
Aug 18, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
148
I want to display the LM35 temperature reading in both serial and the LCD.
I used a soldering iron to heat up the surroundings near the sensor to test my setup.
After displaying 31.75 degrees celcius, further exposure to heat produces a negative output on the LCD and the serial monitor.
The sensor is not at fault since I replaced it 3 times already only to get the same result as the first sensor.
Same data is recorded in both output devices (LCD serial) - no problem there perhaps?
I also observed proper pinouts for the sensor. Vs - 5V, Gnd - Gnd, Vout - A0 of Arduino

What could be the problem?

Here is the code

Code:
#include <LiquidCrystal.h>
#define tempSensor 0 
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);  //RS, Enable, D4, D5, D6, D7

int Vin; // Variable to read the value from the Arduino’s pin A0
float TC; // Variable that receives the converted voltage value to ºC temperature

void setup()  
{
lcd.begin(16, 2);
delay(2000);
lcd.clear();
Serial.begin(9600); 
}
void loop() 
{

Vin = analogRead (tempSensor); // Tells the Arduino to read A0 and stores the value in “Vin” 
TC=(5*100*Vin)/1024.0; // Converts the voltage value into temperature and stores it into the “TC” variable (in ºC)

lcd.setCursor(0, 0); // Moves the cursor of the display to the next line
lcd.print (TC);
lcd.print((char)223);// degree symbol
lcd.print("C"); 

Serial.print("DATA,TIME,"); Serial.println(TC); 

delay(1000); 
}
 

I think it is because your analog reading is an int type. It is in two's complement format so the most significant bit of your analog reading is the sign bit. As the output of the lm35 increases, the adc reading also increases but is in twos complement format so you see a negative reading as it gets higher. Try using unsigned int for Vin:

unsiged int Vin;
 
I reached 50 degrees celcius. I think that's it! Thanks
 

I think your problem has got solved..Please mark your thread has solved. So that it will be useful anyone who comes with same problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top