Why doesn't my Arduino 'secret thermometer' print to LCD?


I've had my Arduino a few days now and have found this code:


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);
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.begin(16, 2);

void loop(){

lcd.setCursor(3, 0);
lcd.setCursor(0, 0);
lcd.print(temp); // is this where the problem is?

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


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.

Picture of Why doesn't my Arduino 'secret thermometer' print to LCD?
sort by: active | newest | oldest
Grathio7 years ago
Does it successfully print "Thermuino" at the start of the application?  If not then there's something wrong with your LCD setup.

Also you'll probably want to move the "int temp=readTemp()...." line into loop() so it updates with the current temperature.  
Yes, unless Arduinos automagically send the 4 initialisation  bytes to the display, you won't see anything. And the unused dataline should be tied low AFAIR.
mathews7 years ago
How far off is it? I noticed a small error on the ADC as a result of a discrepancy in the power supply, 4.73 instead of 5v.

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

Does it change at all ?
Is your wiring spec correct ? It certainly doesn't LOOK wired 7, 6, 5, 4, 3, 2

Not sure that the LCD.clear is necessary or correct before the LCD.begin line ?

mathews7 years ago
I have been using a LCD screen for the first time recently, and found that the setup can be a pain. If you are using pre-built libraries ( I assume LiquidCrystal), have you got the LCD connected to the pins it is expecting? Have you instructed the LCD what format to display the data in? I had both these problems.

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.