LM35 Temperature Sensor - Different Readings Dependent on Pwr Source

Arduino Uno, HLK-RM04 Wifi module and LM35 temperature sensor.
I’m using the below sketch on the Arduino, and when powered with USB cable from PC the temp. readings are correct.

But, when I power all components with a 12v 7Ah battery through a 7805 5V DC regulator, the temp. readings from the LM35 drop approx. 20 degrees F??

I tested the 5v pins on the Arduino that feed the LM35 and they are getting the same 4.78v regardless of USB cable or 12v battery.

I know this battery has not been charged for awhile, would that make a difference?
The battery terminals test out at 12v.

thanks.

//Arduino sketch created by Nikos Georgousis
//Dec 2014
//Based on http://rayshobby.net/?p=9592 example
//Wireless temperature sensor with LM-35 and HlK-RM04


float analogVal;
float temp;
float referenceVoltage;
void setup() {                
  Serial.begin(57600);
  analogReference(INTERNAL);
  referenceVoltage = 2.00; //Set to 5, 3.3, 2.56 or 1.1 depending on analogReference Setting
}

void loop() {
  boolean has_request = false;
  if (Serial.available()) {
    while(Serial.available()) {
      char c = Serial.read();
    }
    has_request = true;
  }
  if (has_request) {
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");  // the connection will be closed after completion of the response
    Serial.println("Refresh: 5");  // refresh the page automatically every 5 sec

    String sr = "<!DOCTYPE HTML>\n";
    sr += "<html>\n";

    analogVal=0;
    temp=0;
    int analogChannel = 1;  // Sensor should be connected to Analog 1
    for(int i = 0; i < 30; i++) { // Get 30 readings from teh sensor to have an acurate result
      analogVal += (analogRead(analogChannel)* 0.48828125);
      delay(5); //Delay each reading for 5 millisecons
    }
    temp=analogVal/30; //Get the average value
    temp =  (referenceVoltage * temp * 100) / 1023; // Caclulate Celsius value correctly 

    sr += "<center>";

    sr += "<h1 style=color:blue>";
    sr +=temp;

    sr+="</h1>";

    sr += "
\n";   
    sr += "Created by Nikos Georgousis\n";  
    sr += "</center>";  

    sr += "</html>";
    Serial.print("Content-Length: ");
    Serial.print(sr.length());
    Serial.print("\r\n\r\n");
    Serial.print(sr);
    has_request = false;
  }
}

When you used “analogReference(INTERNAL);” you use 1.1V as aRef
but you have set your referenceVoltage as 2.0, why?

for(int i = 0; i < 30; i++) { // Get 30 readings from teh sensor to have an acurate result
      analogVal += (analogRead(analogChannel)* 0.48828125);
      delay(5); //Delay each reading for 5 millisecons
    }

your analogRead(analogChannel) have use 1.1V as aRef , but you change it 5V ref, again why?

http://playground.arduino.cc/Main/LM35HigherResolution

//Here's an LM35 example sketch using 1.1 as aRef:


float tempC;
int reading;
int tempPin = 0;

void setup()
{
analogReference(INTERNAL);
Serial.begin(9600);
}

void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;  // 1 / (1.1 *100 /1024)
Serial.println(tempC);
delay(1000);
}

that makes sense, TY.
I'll try the high res. calc. tonight and post back.

go easy on me; I'm very new to hardware... :slight_smile:

we'll start with good news:
The above calc. solved my problems and everything was working great on the 12v 7Ah battery for 6 hours, then I lost communication (assuming battery died, still at work though).

battery problem:
I tried connecting the HLK-RMO4 directly to a 5v output pin on the Arduino and it got unstable and wouldn't fully boot. Lights just flashed and it never pulled an IP or connected to wifi network. Meter said 4.78 volts was being supplied, but for some reason it doesn't like the Arduino 5v output pin when the 12v battery is used.

So, I wired up the Arduino and HLK-RMO4 like in the below diagram and everything worked great for 6 hrs. Any recommendations on how to squeeze more life out of this battery? I'm guessing the 7805 5v reg. is wasting a lot of pwr?

I cannot find any pwr consumption specs for the HLK-RMO4 module, but I'm assuming it's slightly higher then the Arduino, so we'll call all components ~350 mA.

thanks.