IAN LANG ELECTRONICS

Here's the code then:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte deg [8] ={B00000,B00111,B00101,B00111,B00000,B00000,B00000,B00000};

long centtemp;

long fahrtemp;

void setup(){

lcd.createChar(0, deg);

lcd.begin (16,2);

}

void loop(){

delay(2000);

lcd.clear();

centtemp = map(centtemp,0, 1023, -50, 460.8);

lcd.setCursor (4,0);

lcd.write(0);

lcd.print ("C is ");

lcd.print (centtemp);

centtemp=centtemp*1.8;

fahrtemp=centtemp+32;

lcd.setCursor (4,1);

lcd.write(0);

lcd.print ("F is ");

lcd.print (fahrtemp);

}//close of loop

Well, as you can see in the first few lines, we're setting up the LCD display, declaring our variables and creating a glyph. That glyph is actually the little degree symbol that appears befor the F and the C on your display. In the loop, we wait two seconds (it stops annoying flickering on the subsequent runs), clear the display and then come to this:

This line will read the analogue voltage at the pin A0 but it won't return an anologue result. Oh no. That would be easy. What it does do is package the result up in neat little parcels of 4.8828125 mV and give them a number according to the nearest multiple of 4.8828125 . So, if it was 4.88281254, that would be 0. If it were 9.765429, that would be 1 and so on right up to 1023. These little parcels are discrete digital steps. Now, each step is just short of 5mV, and each increase in degrees centigrade is represented by the IC by an output of 10mV. This is in technical terms known as an "embuggerance"  and it is further complicated by the fact that the IC has an offset of 500mV to enable it to read sub-zero temperatures. This then becomes a "complete embuggerance".

Except it doesn't when you've got a microcontroller. Swivel your peepers over the next line:

centtemp = map(centtemp,0, 1023, -50, 460.8);

Yes, we can actually remap the  received data to a range that is more convenient for us.

The way we do it is like this:

There's nothing to stop the return and considered variables being the same one and indeed

that's exactly the situation here. In our case the digital steps of the analogue read fed to

centtemp will have the range 0 to 1023, and so that's the range of the considered value.

If there's a 500 mV offset and 10mV = 1 degree centigrade the absolute lowest readable voltage is 0mV and  therefore 0V and this will produce -50 degrees on the display. (Actually it won't, because the rest of the device will have stopped working long before that, but mathematically it will.) So, the counterpart for the lowest part of the old range is the lowest part of the new range and that is -50. Similarly 5000 millivolts minus the offset of 500 gives 4500 and if you divide that by 4.8828125  you get 921.6. But the IC puts out 10mV per degree centigrade, so you need half that total, which is 460.8, and that's the top of the new range. (Again, if anything you measure is getting as hot as that, the device will probably melt first, but mathematically it is the top of the new range and so in it goes.)

The old range now gets spread evenly over the new range and we can use the value of the new range to directly output to the LCD:

lcd.setCursor (4,0);

lcd.write(0);

lcd.print ("C is ");

lcd.print (centtemp);

Just like the meerkat said.

Now, Grandad will come along and look at this and say:

"I fought in Europe/ The Far East/ Korea/ Suez/ Aden/ Ireland/ The Falklands/ Iraq (delete as applicable) and I didn't need any of this centigrade rubbish. Show me a proper temperature, in Fahrenheit. You young people today, you don't know you're born what with your Ipods and your facebooks and your Sky televisions. In my day there were only three channels and they were in black and white."

There will follow half-an-hour about what's wrong with the country. There doesn't need to be, because what is actually wrong with the country is a. Cheryl-bloody-Cole b. Radio 1 c.BBC Three d. a lack of discipline and genuine expertise in our schools which produces more Cheryl-bloody-Cole clones and e. an instable and insufficient judiciary and Police force. But Grandads can spin this out for ages, so to forestall them we display the Fahrenheit in tandem. To get F from C you multiply C by 1.8 and then add 32, and so:

centtemp=centtemp*1.8;

fahrtemp=centtemp+32;

and then it's just a matter of displaying it just like before:

lcd.setCursor (4,1);

lcd.write(0);

lcd.print ("F is ");

lcd.print (fahrtemp);

}//close of loop

Voila, as they say in Calais. A very practical and useful device with a minimum of fuss. Magnifique!

Ian Lang October 2011

# A Digital Thermometer

Go Back

This is another piece of work in which your LCD display gets a chance to shine, though by using shift registers you could in theory use some LED segment displays to display the output from this device; the problem would be that of portability.

We're going to be using one other component with this device which is the TMP 36 IC that, if you bought the Oomlout ARDX, came supplied, and if you didn't you can get them from Oomlout at a quite reasonable price; click on the logo on the sidebar at the left for the details.

The IC which looks rather like a transistor, is simplicity itself to wire up. Pin 1 is given  a 5V supply, pin 2 goes to pin A0 of your Arduino Board and pin 3 to GND.

Hmm. I might have made a better job of this photo of my breadboard construction because you can't see what's on the display for the light shining into the camera. Meh.

For the record it's showing the temperature in the ambient surroundings in both Centigrade and Farhenheit and, checking it against a mercury thermometer, it's doing a very good job. The only problem with the IC is that it is much slower to record drops in temperature than it is to record rises. I have no real idea why this is but I suspect that it may have something to do with self-heating. Still, it's good and quick enough for ambient monitoring.

return variable = map(considered variable, cvLOW,cvHIGH, newrangeLOW,newrange HIGH)

An optional move is to put an AC bypass capacitor between the Vs and GND terminals- it may improve transition.