My code is getting stuck in the first IF statement

Hello,
I'm having issues with my code, apparently is getting stuck in the first IF statement.
I will appreciate any guidance to eliminate this problem.

Here is that portion of the code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

String UVIndex;
int sensorValue;

void setup()

{
  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("UV Ind = ");
}

void loop()

{

  lcd.setCursor(9, 0);

  if (sensorValue < 10)
  {
    lcd.println("0   LOW");
    delay(1000);
    lcd.println("\n");
  }

  else if (sensorValue > 10 && sensorValue <= 12)

  {
    lcd.println("0   LOW");
    delay(1000);
    lcd.println("\n");
  }

  else  if (sensorValue > 12 && sensorValue <= 15)

  {
    lcd.println("1   LOW");
    delay(1000);
    lcd.println("\n");
  }

  else  if (sensorValue > 15 && sensorValue <= 20)

  {
    lcd.println("2   MED");
    delay(1000);
    lcd.println("\n");
  }

  else if (sensorValue > 20 && sensorValue <= 50)

  {
    lcd.println("3  HIGH");
    delay(1000);
    lcd.println("\n");
  }

Welcome to the forum

Does sensorValue ever change its value in your sketch or is it always zero ?

Looks like sensorValue is never set to anything so it is always zero... ?

What is the sensor? How is it connected to the mystery Arduino? Why don't you read the sensor?

Thank you for posting code properly. Very few new members bother to read the guidelines. Good job!

:+1:

LCD's don't generally respond to newline characters and require explicit positioning of the cursor. You should probably not be using "println()" with an LCD (use "print()") and you should not have explicit newline characters ("\n") in your LCD output.

Your lcd library might have something like

lcd.setCursor(x,y);

After that lcd.print() will print from the set position.

Try this guy's project. I think you will find success there.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.