Random Analog Values With Mega And LM35 Sensor Can't Readanalog

Hi Every Body
I have problem With Mega and temperature Sensor lm35 i Can’t Read analog values form any analog provider in this case my sensor lm35
this my code used

int readValue;
float temperature ;
float temperatureF ;
void setup() {
  // put your setup code here, to run once:
void loop() {
  // put your main code here, to run repeatedly:
readValue = analogRead(A0);
temperature = (readValue * 0.0049);
temperature = temperature * 100;
temperature =(temperature/2)+0.5;
temperatureF = (temperature * 1.8) + 32;
Serial.println("Temperature: ");

what ever formula not true
but i mast get fixed value
not random value in the attache u can see my result & connected method

Try this code.

int t=0; int vcc=A2; // sets analog input A0 as +5V source for LM35 int sensor=A3; // sets A1 as the sensor input int gnd=A4; // sets analog input A2 as ground for LM35 float temp; float tempc; float tempf; void setup() { pinMode(vcc,OUTPUT); pinMode(gnd,OUTPUT); pinMode(sensor,INPUT); digitalWrite(vcc,HIGH); // sets analog input A0 HIGH digitalWrite(gnd,LOW); // sets analog input A2 LOW Serial.begin(9600); // sets the baud rate at 9600 pinMode(13, OUTPUT);

} void loop() { delay(1000); // calls a 2 second delay t=t+1; // increments the time by 2 every two seconds temp=analogRead(sensor); // reads the LM35 output tempc=(temp*5)/10; // converts the digital value into temperature degree C Serial.println("..............."); Serial.println("Temperature logger"); Serial.print("Time in sec = "); // prints the time on serial monitor window Serial.println(t); Serial.print("Temperature in deg C = "); // prints the temperature in degreeC Serial.println(tempc); if (tempc>281.00){ digitalWrite(13,HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } }

There have been problems with LM35 sensors from ebay.

This simple sketch should work. It uses the Mega's internal 2.56volt Aref (as in the sketch from OP). 1.1volt Aref could be better though (2.5x better resolution). Leo..

float tempC;
float tempF;

void setup() {
  analogReference(INTERNAL2V56); // Mega only

void loop() {
  tempC = analogRead(A0) * 0.25; // for 2.56volt Aref only
  tempF = (tempC * 1.8) + 32.0; // Celcius to Fahrenheit
  Serial.print("Celcius: ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print("  Fahrenheit: ");
  Serial.println(tempF, 1);
  delay(1000); // print delay

thanks sorry my English so bad i think i have bad sensor