## Using Fahrenheit

We are going to convert the degrees displayed by the example code to in Celsius to Fahrenheit. In loop(), change the following lines:

// Degrees C
//temperature = (temperature - .5) * 100;
// Degrees F
temperature = (((temperature - .5) * 100)*1.8) + 32;

Then, compile and upload the sketch to your metro and observe the number change.

## Printing new text to the LCD

Did you notice that even though the number changed, the *C was still printed to your display? This is because the *C is hard-coded into the display.

To change *C to *F, change the following line:

lcd.print("*C"); ->  lcd.print("*F");

Then, compile and upload to the Metro. Your temperature should display the Fahrenheit unit and temperature symbol.

## Printing to the Second Row

The intro mentioned this LCD was 16x2. It has two rows you can print to, but we are only using one. Let's print the *F symbol to the same spot in the second row. To do this, modify the following code in your loop():

lcd.setCursor(11,1); // instead of (11,0), we are printing to (11,1), the 2nd row
lcd.print("*F");

## Using Custom Characters

The LiquidCrystal library contains a command called createchar() which can create a custom character (a glyph!) for printing to the LCD. Our code uses an asterisk instead of a degrees symbol. Let's complete the thermostat and have a real degrees symbol.

// Custom Degree Symbol
byte degree[8] = {
0x7,
0x5,
0x7,
0x0,
0x0,
0x0,
0x0,
};

In the setup() loop, add the following line:

lcd.createChar(0,degree);

Finally, in the loop(), modify the following lines:

lcd.setCursor(11,1);
lcd.write(byte(0)); // custom degrees character
lcd.setCursor(12,1);
lcd.print("F");

After compiling and uploading, you should see the degree symbol next to the F.

# Making your own Custom Character

If you want to add more custom characters, or different ones, there's a great online generator we like. You can add in your own icons, for whatever you want. Let's learn how to do this:

First, visit the HD44780 graphic generator site. Then, change the character size to 5 by 8

Click the boxes to set pixels. When a pixel is set, it'll turn from green to black. You can un-set pixels by clicking on a black pixel (on) to turn it green (off).

Once you have your custom character, copy the values from "In Hex" and paste them into an Arduino sketch as a byte array:

// smiley face
byte smile[8] = {
0x0,
0x0,
0x8,
0x0,
0x0,
0x0,
0x0,
};

In the setup() loop, add the following line:

lcd.createChar(0,smile);

Then, in loop() add the following to write your custom character to the LCD:

lcd.write(byte(0)); // custom degrees character

This guide was first published on Aug 18, 2017. It was last updated on Jul 20, 2024.

This page (Make It Better) was last updated on Jun 28, 2017.