Introduction: That's Hot
How to use Arduino and 16x2 LCD display room temperature and set a desired temperature.
*You can switch between Fahrenheit and Celsius.
*You can set up your desired temperature.
*When the temperature higher than desired temperature,
the LED will be lighted.
Step 1: What Do You Need?
Arduino UNO
Breadboard
16x2 LCD
Temperature Sensor
Wires
LED
Potentiometer
Button
Resistors
Step 2: How to Do It?
Example Code :
#include
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int buttonPin = 9; // pushbutton pin const int temperaturePin = 0; //Temperature sensor pin float voltage, degreesC, degreesF; int displaysetC, displaysetF; //The value used to display the disired temperature float set; //The Value read from potentiometer const int PotentiometerPin = 1; //PotentiometerPin boolean button; //The button pushed or not int buttonState;//Variables to hold the pushbutton states const int led = 13; // LED pin void setup() { // Set up the pushbutton pins to be an input: pinMode(buttonPin, INPUT); // Set up the LED pin to be an output: pinMode(led, OUTPUT); } void loop() { Potentiometer(); Temperature(set); Button(); LCDdisplay();
} int Potentiometer() //Read the value from potentiometer and return it. { set = analogRead(PotentiometerPin); set = set / 32; //Make the value fit Fahrenheit set = set + 60; return (set); } float Temperature(float set) { voltage = analogRead(temperaturePin) * 0.004882814; degreesC = (voltage - 0.5) * 100.0; degreesF = degreesC * (9.0 / 5.0) + 32.0; int barD = (int) set; //Round the value from potentiometer set = (float) barD; displaysetC = set - 32; //Make the value into 5-33 to fit Celsius displaysetC = displaysetC * 9; displaysetC = displaysetC / 5; displaysetC = displaysetC - 40; displaysetC = displaysetC / 2; displaysetF = set;
} int Button() { // read the current pushbutton states into a variable buttonState = digitalRead(buttonPin); if (buttonState == LOW) { //If the button pressed, switch the state button = !button; } } void LCDdisplay() { int barF = (int) degreesF; //Round the value before display degreesF = (float) barF; int displayF = degreesF; int barC = (int) degreesC; degreesC = (float) barC; int displayC = degreesC; lcd.begin(16, 2); if (button == true) {
lcd.print(displayF); lcd.print(" Fahrenheit"); lcd.setCursor(0, 1); lcd.println(displaysetF); lcd.println("DesiredTemp"); if (displayF > displaysetF) { digitalWrite(led, LOW); } else { digitalWrite(led, HIGH); } } if (button == false) { lcd.print(displayC); lcd.println(" Celsius"); lcd.setCursor(0, 1); lcd.println(displaysetC); lcd.println(" DesiredTemp"); if (displayC > displaysetC) { digitalWrite(led, LOW); } else { digitalWrite(led, HIGH); }
} delay(500); }
Step 3: Important Code
// include the library code:
#include
// initialize the library with the numbers ofthe interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);