New User/Adding 'If/Then' Statements to LCD screen

Hello everyone! Coming back after years so very unfamiliar with this. Just copying and pasting and learning how to use codes again. Copied a code courtesy of Zaidi Mat Nawi from YouTube that prints out potentiometer values onto an lcd screen. I am trying to change the top (0,0) lcd screen to print out 'if/then' statements.

Example, if the potentiometer reads 300 < ohms, LCD prints 'low', if 301-600 ohms - LCD prints 'Medium', and if 601 > ohms, LCD prints 'high'.

Any help/steps would be greatly appreciated!

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int val = 0;
void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.clear();
}

void loop()
{
  val = analogRead(A0);
  lcd.setCursor(0,0); 
  lcd.print("Potentiometer: ");
  lcd.setCursor(0,1);
  lcd.print(val);
  delay(100);
  lcd.clear();

}

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.


if(someVal < 300)
{
...
}
else if (someVal <601)
{
...
}
else
{
...
}

You can fill in the dots :wink:

The in between value;

if(val > 301 && val < 600)
{
     lcd.print("     medium");
     // other stuff
}

Thank you!

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