1602 LCD Not Writing to Second Line

Hello. I have an LCD (16x2) connected to my Arduino with the sketch below loaded onto it. The LCD displays text, but only on the first line. When I tell it to move the cursor to the second line, it seems to ignore it. There isn’t even boxes on the second line when its at full contrast, its like its only one line but it says 1602 LCD on the back and I can see faint boxes if I look really close. I’m assuming this is a code issue, so any help is appreciated.

The Code:

#include <LiquidCrystal.h>

const int greenLed = 6;
const int redLed = 7;
const int buzzer = 8;
const int controlPot = A0;
const int controlRelay = 9;
const int tempSensor = A1;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // put your setup code here, to run once:

  if (Serial) //if the Arduino is plugged into a serial port
  {
    SerialSetup(); //set up serial comm. and display info.
  }

  PinSetup(); //set up all the pins
}


void loop() {
  // put your main code here, to run repeatedly:
  float threshold = GetThreshold(controlPot, 0, 255); //read the pot
  
  float temperature = GetTemperature(tempSensor); //read the sensor
  
  int tempStatus = CompareTemps(threshold, temperature); //compare the two values
  
  DisplayLcd(threshold, tempStatus, temperature); //display some information

  if (Serial)
  {
    DisplaySerial(threshold, tempStatus, temperature);
  }

  delay(500); //keep things under control
}


float GetThreshold(int pinNum, int minVal, int maxVal)
{
  //return a threshold value
  pinMode(pinNum, INPUT); //make sure its an input

  float reading = analogRead(pinNum); //get the raw number

  reading = map(reading, 0, 1023, minVal, maxVal); //map it

  return reading; //return it to the program
}


float GetTemperature(int pinNum)
{
  //return a temperature in Celsius
  pinMode(pinNum, INPUT); //make sure its an input

  float reading = analogRead(pinNum);

  reading = reading * 5.0; //make the reading into Celsius
  reading = reading / 1024.0;

  return reading;
}


int CompareTemps(float threshold, float temperature)
{
  //return a 0 if the temp is lower than threshold, return a 1 if the temp is higher
  if (temperature >= threshold)
  {
    ThermostatOn(); //activate the relay
    return 1;
  }

  if (temperature < threshold)
  {
    ThermostatOff(); //de-activate the relay
    return 0;
  }
}


void DisplaySerial(float threshold, int tempStatus, float temperature)
{
  Serial.begin(9600);
    Serial.println("CONNECTED DURING READING");

    Serial.print("SET: ");
    Serial.println(threshold);

    Serial.print("CURRENT: ");
    Serial.println(temperature);

    if (tempStatus == 0)
    {
      Serial.println("STATUS: NOT ACTIVE");
    }

    if (tempStatus == 1)
    {
      Serial.println("STATUS: ACTIVE");
    }
}


void ThermostatOn()
{
  digitalWrite(greenLed, HIGH); //change the status LEDs
  digitalWrite(redLed, LOW);

  digitalWrite(controlRelay, HIGH); //power on the relay

  if (Serial)
  {
    UpdateSerial(1); //tell UpdateSerial that the relay is HIGH
  }
}


void ThermostatOff()
{
  digitalWrite(greenLed, LOW); //change the status LEDs
  digitalWrite(redLed, HIGH);

  digitalWrite(controlRelay, LOW); //power off the relay

  if (Serial)
  {
    UpdateSerial(0); //tell UpdateSerial that the relay is LOW
  }
}


void UpdateSerial(int tempStatus)
{
  //A 0 means the relay is low, a 1 means high
    if (tempStatus == 0)
    {
      Serial.println("STATUS UPDATE: NOT ACTIVE");
    }

    if (tempStatus == 1)
    {
      Serial.println("STATUS UPDATE: ACTIVE");
    }
}


void DisplayLcd(float threshold, int tempStatus, float temperature)
{
  lcd.clear();
  
  lcd.setCursor(0, 0);
  
  lcd.print("SET: ");
  lcd.print(threshold);
  lcd.print(" C");

  lcd.setCursor(0, 1);

  lcd.print("CUR.: ");
  lcd.print(temperature);
  lcd.print(" C");

  lcd.setCursor(13, 1);

  if (tempStatus == 0)
  {
    lcd.print("OFF");
  }

  if (tempStatus == 1)
  {
    lcd.print("ON");
  }
}


void SerialSetup()
{
  Serial.begin(9600);
    Serial.println("CONNECTED");
  Serial.end();
}


void PinSetup()
{
  pinMode(greenLed, OUTPUT); //set the pin mode for all
  pinMode(redLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(controlPot, INPUT);
  pinMode(controlRelay, OUTPUT);
  pinMode(tempSensor, INPUT);

  digitalWrite(redLed, HIGH); //make sure only the red LED
  digitalWrite(greenLed, LOW);//is on

  tone(buzzer, 440, 250); //440Hz on the buzzer for 250 millis
                          //to tell the user that setup is
                          //complete.
  digitalWrite(controlRelay, LOW); //make sure the relay is off
}

Necessary Information:

  • There is only text written to the lcd in the function 'DisplayLcd()" so if its a code problem then it’s going to be in there (or maybe the lcd setup at the top)
  • The output on the lcd with the code above running(exactly what I’m seeing): CUR.: 0.75 C OFF

Try adding lcd.begin(16,2) to set up.

Oops! I forgot to init. the LCD! Yeah that might help...

Oops! I forgot to init. the LCD! Yeah that might help...

Not exactly - but the result is the same. It was initialized using the default values which for some unfathomable reason tell the controller that you wish to use only one line of internal memory rather than the two lines required by virtually every LCD in common use, even most 16x1 displays.

Don