Display Fahrenheit

On our ovens, we don't usually display temperatures in celsius, but instead use degrees fahrenheit. So, let's change our code so that instead of displaying celsius, we show fahrenheit.

In order to calculate fahrenheit, you take the temperature in celsius and multiply it by 9, then divide by 5. Then add 32 to that value. Below is the equation to use:

fahrenheit = (celsius * 9/5) + 32

We'll change the code by writing a function that performs this calculation.

// include the library code
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);

// initialize our variables
int sensorPin = 0;
int tempC, tempF;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

void loop() {  
  tempC = get_temperature(sensorPin);
  tempF = celsius_to_fahrenheit(tempC);
  lcd.print(tempF); lcd.print(" "); lcd.print((char)223); lcd.print("F");
int get_temperature(int pin) {
  // We need to tell the function which pin the sensor is hooked up to. We're using
  // the variable pin for that above
  // Read the value on that pin
  int temperature = analogRead(pin);
  // Calculate the temperature based on the reading and send that value back
  float voltage = temperature * 5.0;
  voltage = voltage / 1024.0;
  return ((voltage - 0.5) * 100);

int celsius_to_fahrenheit(int temp) {
  return (temp * 9 / 5) + 32;

You should now see the temperature in fahrenheit on your lcd screen.

Next: Hook up a light sensor