Make It Better

Writing to the second line

If we want to write to the second line, we can use lcd.setCursor(COLUMN, LINE) such that the column is 0 and the line is 1:

     lcd.setCursor(0,1);

Download: file
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
Do NOT take apart this CIRC yet, CIRC15 uses the LCD and you don't want to wire it up again.

Writing the light sensor to the LCD

Let's try writing the output of the light sensor to the character LCD.

This will require an extra part:

Wiring

The wiring for this Make It Better is the same for both the Metro and Metro Express. Make sure the rail is connected to 5V.

Note: While the rail is connected to 5V, the light sensor is connected to 3V. 

Code

Copy and paste the code below into the Arduino editor. Then, compile and upload it to your board.

Download: file
/* CIRC14 - Make It Better
 * Character LCD + TMP36
 *  
 *  by Brent Rubell for Adafruit Industries.   Support Open Source, buy Adafruit!
 */
 
// include the library code:
#include <LiquidCrystal.h>

// modified wiring for Metro Explorers Guide
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// photo light sensor
int lightPin = A0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // print to the first line of the LCD
  lcd.print("Light Value:");
}

void loop() {
  // read the light level
  int lightLevel = analogRead(lightPin);
  // map and constrain the light sensor values
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // write lightLevel to the LCD
  lcd.print(lightLevel);
}

What's next?

The Thermometer (CIRC15) gets into the nitty-gritty of the character LCD. You'll learn how to display custom characters, full strings of text, and multi-line data output!

This guide was first published on Aug 18, 2017. It was last updated on Aug 18, 2017. This page (Make It Better) was last updated on Mar 01, 2020.