1

I have an arduino pro mini and I have attached a 16x2 character LCD and an LM35 analog temperature sensor. When I upload a sketch using only the sensor and send the readings to serial monitor, the readings are OK. When I upload a sketch that displays the readings to the LCD the readings are about 130°C in room temperature. Where is the problem and how can I solve it. Thanks in advance

Code with lcd:

#include <LiquidCrystal.h>
byte smiley[8] = {
  B00000,
  B01110,
  B01010,
  B01110,
  B00000,
  B00000,
  B00000,
};
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);
  analogReference(INTERNAL);
  // Print a message to the LCD.
  lcd.print(analogRead(0)/1024.0 * 500);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0, 2);
  lcd.print("21");
  lcd.write(byte(0));
  lcd.print("C");

}

void loop() {
  // Turn off the cursor:
  lcd.print((analogRead(0)/1024.0)*500);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0, 2);
  delay(5000);
  lcd.clear();
}

Only sensor code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(analogRead(0)/1024.0*500);
  delay(500);
}
  • 1
    Adding your code would be helpful. – Gerben Nov 27 '15 at 21:07
  • I think adding code is essential... – CharlieHanson Nov 28 '15 at 14:22
  • I just added it sorry for the delay. – Christos Mitsis Nov 28 '15 at 14:46
1

Firstly you do not keep your code consistent between you temperature test and your LCD test code. The problem lies in your use of the internal analog reference, that reference is 1.1V and that is giving you 130°C.

Temp = 260*0.5= 130

The 260 is the ADC reading worked back from the 130°C you gave

To use Internal reference-

Internal ref = 1.1÷1024=0.001074219 That multiplied by one hundred to account for the mV reading of the lm35 gives 0.107 that will give you the correct temp when using the internal reference

Analog reference from the arduino site.

If you want to use the analog reading *0.5 comment out the analogReference()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.