LCD second row not working

I want to display Temperature in row 1 and distance in row 2.
This is my code. I used lcd.setCursor(0, 1); but it just puts everything in line one. (the distance is in row 1 and temperatue isn´t there at all)

#include <LiquidCrystal.h>

int Temp = 0;
int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

int echo=8;
int trig=9;
long duration;
int distance;

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

void setup() {
Serial.begin(9600);
pinMode(6,OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}

void loop() {

  Vo = analogRead(Temp);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  T = T - 273.15;

  digitalWrite(trig, LOW);
  delay(0.02);
  digitalWrite(trig, HIGH);
  delay(0.01);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = duration * 0.034 / 2;


  lcd.begin(0, 0);
  lcd.print("Temper=");
  lcd.print(T);   
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Entfernung=");
  lcd.print(distance);   
  lcd.print("cm");
  
  delay(500);            
  lcd.clear();

  if (T>32){
  digitalWrite(6, HIGH);
  }
  else if (T<30){
    digitalWrite(6,LOW);
  }
  Serial.println(digitalRead(6));
}

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

lcd.begin(0, 0);

Can you please explain the 2 parameters in this function call and why you call begin() in loop()

the first 0 is for segment 1 and the second 0 is for row 1
i tried this, but doesn´t work either

 lcd.setCursor(0, 0);
  lcd.print("Temper=");
  lcd.print(T);   
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Entfernung=");
  lcd.print(distance);   
  lcd.print("cm");

No

The first parameter is the number of columns and the second is the number of rows that the LCD has

Do you see a problem ?

no, sorry i don´t.
shouldn´t it start in collum 0 ?

See https://www.arduino.cc/en/Reference/LiquidCrystalBegin

lcd.begin(16, 1)
so like this?

because that is still the same for me

No

How many rows does the LCD have ?
Is it 1 ?

@qiopoto, your topic has been moved to a more suitable location on the forum.

1 Like

Thanks a lot.
lcd.begin(16, 2);
i have two
thought 2 is 1 in lcd begin because in lcd.setCursor 2 is 1 because of the 0

The begin() function takes the number of columns and rows on the LCD not the highest column and row number

1 Like