bigone5500
- Apr 9, 2014
- 712
- Joined
- Apr 9, 2014
- Messages
- 712
I have an UNO with a temperature sketch which displays the current temp in F. I'm using an LM35CAZ. When the display reaches 87.8 degrees, it starts showing negative readings.
Any ideas?
Here's the sketch:
Any ideas?
Here's the sketch:
Code:
#include <Wire.h> // Include the Wire library.
#include <LiquidCrystal_I2C.h> // Include the Liquid Crystal I2C library.
#define sensor 0 // Define the A0 pin as “sensor”. This can be changed as needed.
int Vin; // Variable to read the value from the Arduino’s pin
float Temperature; // Variable that receives the converted voltage value to temperature
float TF; // Variable to receive the converted value from ºC to ºF
LiquidCrystal_I2C lcd(0x27, 16, 2); // Sets the I2C address of the LCD and declares 16 columns, 2 rows.
void setup()
{
lcd.begin();
lcd.setBacklight(1); // Turns on the backlight of the LCD. Probably not needed but here anyway.
lcd.setCursor(2, 0); // Sets the cursor to column 2, row 0.
lcd.print("Temp: "); // Send the text 'Temp:' to the screen of the display.
Serial.begin(9600); // Sets the baud rate for the serial monitor.
}
void loop()
{
Vin = analogRead (sensor); // Tells the Arduino to read the pin and stores the value in “Vin”.
Temperature=(500*Vin)/1023; // Converts the voltage value into temperature and stores it into the “Temperature” variable (in ºC)
TF = ((9*Temperature)/5)+32; // Converts ºC to ºF and stores the result in the variable 'TF'.
lcd.setCursor(4, 1); // Sets the cursor to column 4, row 1.
lcd.print(TF); // Exhibits the value of the temperature on the display.
lcd.print(" F"); // Writes “F” to indicate that it is in Fahrenheit scale.
Serial.print(TF); // Prints the value 'TF' to the serial monitor
Serial.println(" F"); // Prints the 'F' designation and inserts a space after 'TF'. 'println' causes a new line carriage return.
delay(1000); // Waits for 1 second to read the pin again.
}
Attachments
Last edited: