Why doesn't my Arduino 'secret thermometer' print to LCD?
I've had my Arduino a few days now and have found this code:
code.google.com/p/tinkerit/wiki/SecretThermometer.
I have tried modifying it with a few basic LCD commands, which I have had working with a 16x2 LCD.
I want it to print the temperature from "readTemp()", divide by 10000 (to get it in degrees C) and print to the LCD (with the "C" character after it).
This is what I have so far:
#include LiquidCrystal
lcd(7, 6, 5, 4, 3, 2);
long readTemp() {
long result;
ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = (result - 125) * 1075;
return result;
}
int temp = (readTemp()/10000, DEC);
void setup(){
lcd.clear();
lcd.begin(16, 2);
lcd.print("Thermuino");
delay(2000);
lcd.clear();
}
void loop(){
lcd.setCursor(3, 0);
lcd.print("C");
lcd.setCursor(0, 0);
lcd.print(temp); // is this where the problem is?
delay(1000);
}
But it does not work, I have checked all I/O lines, different code etc. and they all work fine. So It must be a mistake in my programming.
All I get is row 0 of the LCD full black all characters along it.
I hope I have provided enough information for you to help :-D
[EDIT]
After removing the "int temp = (readTemp()/10000, DEC);" section and changing "lcd.print(temp);" to "lcd.print(readTemp()/10000);" it now works! :-D
It prints a correct temperature to the LCD and refreshes it.
14
answers
|
Answer it!
|
Also you'll probably want to move the "int temp=readTemp()...." line into loop() so it updates with the current temperature.
Thank you, not working yet but it's progress! :-D
You might also want to reduce the size of the calculations on the ADC result that are being made. That is to say:
voltage = (result * 625 ) / 1024
has become
voltage = (reading * 5 ) / 4; //Calculate actual voltage
voltage = (voltage * 5 ) / 4; //in stages to keep accuraccy but not
voltage = ((voltage * 5 ) / 8 ) * 5; //out of upper integer range
Also is this C? You may need to open with:
#include <LiquidCrystal.h>
Do you also need an additional library for the ADC.
Have you tried working up in steps? 1) Display something. 2) Display numbers. 3) Read ADC and display raw. 4) Make calculation.
The LCD is where it should be, the original temp code works fine via serial printing.
Steve
Steve
![]() |


































