EDIT1: put the whole code in here as said in the forum rules. Sorry for posting things like a cowboy.
Hi there,
I've been fiddling around with my Arduino Uno board for a couple of weeks now. I went through the standard lessons to blink LED's and such. I also bought an 2x16 LCD display and i thought I'd make myself a fun thermometer. This worked following the tutorials online. The TMP36 temperature sensor works splendid (However i miswired it first and it became very hot, unpluged it after 3 seconds) and i got the display to print "(temperature) °C".
What I tried to do now was to put a message on the second line of my display when temperature exceeds 24° which i did as so:
#include <LiquidCrystal.h>
// Arduino pins used for LCD
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
// initialize the LCD display
lcd.begin(16, 2);
}
void loop() {
float temperature = 0.0; // stores the calculated temperature
int sample; // counts through ADC samples
float ten_samples = 0.0; // stores sum of 10 samples
// take 10 samples from the MCP9700
for (sample = 0; sample < 10; sample++) {
// convert A0 value to temperature
temperature = ((float)analogRead(A0) * 5.0 / 1024.0) - 0.5;
temperature = temperature / 0.01;
// sample every 0.1 seconds
delay(100);
// sum of all samples
ten_samples = ten_samples + temperature;
}
// get the average value of 10 temperatures
temperature = ten_samples / 10.0;
// display the temperature on the LCD
lcd.setCursor(0, 0);
lcd.print(temperature);
lcd.print(" \337C");
ten_samples = 0.0;
lcd.setCursor (0,1);
if (temperature > 24) lcd.print("Hot Hot Hot");
}
Now, even when the temperature drops below 24°c the text remains on the screen. so i tried adding:
if (temperature < 24) lcd.print("ice ice baby');
But this only gives a flickering screen changing quickly from ice ice baby to hot hot hot and vice versa. i tried to reset it and then once above 24°c the text remained Hot Hot Hot even when after the first increase of temp. the temp. dropped back below 24.
How can I solve this? Does it have something to do with the wrong wired TMP36? maybe it does not accurately read the temp. anymore since i almost fried it?