Wednesday, June 24, 2009

Temperature display

Switching from Solar to "simple" control stuff. I have been having a hard time getting things to perform. Today I found out one of the reasons why. I bought 4 temperature sensors that I hoped to connect up to the arduino via a prototyping board that slots into the top. I tried everything I could think of and googled my brains out to find out why I wasn't getting proper readings from the LM61CIZ sensor. In the end by a happy accident I found the problem. I had the sensor connected to analog pin 2, but in my little program I had it marked as being on pin 3. Strangely it was working there, giving numbers that went up and down with changes in temperature. I thought perhaps I had misunderstood the numbering of the pins, but experiments proved that not to be the case, then I whipped the shield off and looked at the pins underneath thinking I would try connecting up directly. There was the answer, the pins on the protoshield from Sparkfun were marked o12345, on the Arduino the pins are 543210.
I am afraid my comments on the Sparkfun website may have been a little ratty after my wasted hours of trial and error. They were very quick to respond and have now offered to ship out two new and correctly labeled boards, which was very nice of them seeing that it was just a labeling problem. The boards will come in handy as I get nearer to a final controller for the solar system.
A long way off being that the system itself does not exist yet, but I reached a small milestone in getting the temperature to display properly in degrees C and to display "Low" when under 25 and "High" when above. The next step was getting some little lights to work on the same switch and my next goal is to control a relay.
The sensor produces what it likes, the board interprets that in its way and I have to get that into something I understand. "reading0" is the boards interpretation of a number of millivolts produced by the sensor. Those have to be multiplied by 4.883 to get them back to what they were before the boards computer translated them. The sensor produces 600 millivolts at zero degrees, so that is subtracted to give the temperature. The sensor produces 10 millivolts per degree, so finally divide by ten to give something centigrade lovers can drink up. That integer value is popped into a bit of memory called "Sensor0temp".

int Sensor0temp = ((reading0 * 4.883)-600)/10

One of the stupid challenges in getting the display to work was figuring out how to display degrees properly. For the arduinauts among you here are the two lines to display just that.
First put the cursor at the right spot, then print the temperature number we just made; Then print the character for the degree sign; Then print a C
lcd.setCursor(7, 0);
lcd.print(Sensor0temp);lcd.print((char)223);lcd.print("C");