Display "Low,Meduim,High" in LCD by potentiometer

Hi, I need the LCD to display "LOW" or "MEduim" or "high" every time the potentiometer goes up or down.

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);

const int potPin = A0; //Pot at Arduino A0 pin
//Variables:
int pot ; //pot from pot

void setup() {
//Start the serial communication
Serial.begin(9600); //Baud rate must be the same as is on xBee module
lcd.begin(16,2);
lcd.clear();
}

void loop() {

//Read the analog pot from pot and store it to "pot" variable
pot = analogRead(A0);
//Map the analog pot to pwm pot
pot = map (pot, 0, 1023, 0, 255);
//Send the message:

  lcd.setCursor(5,0);
  lcd.print(pot);

if ((0<= pot) && (pot>= 85)) {
lcd.setCursor(0,1);
lcd.print("Niv.Ilum: Bajo");
} else if ((86<= pot) && (pot>= 170)){
lcd.setCursor(0,1);
lcd.print("Niv.Ilum: Medio");
}else if ((171<= pot) && (pot <= 255)){
lcd.setCursor(0,1);
lcd.print("Niv.Ilum: Alto");
}

}

Tnks

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

What have you tried and where are you stuck ?
I assume that you want to detect that the pot reading has changed and in which direction. How much change should be regarded as significant ?

sorry for not displaying the code properly...
** What have you tried and where are you stuck ?**

then i will show you a video to understand my problem

Basically I want to show different levels of lighting.
The potentiometer levels are 0-255.
0 to 85 display on LCD "Low"
86 to 170 "Medium"
171 to 255 "High"

As we can see in the video, my problem is that it does not show the other levels, only "low" and it does not change

  if ((0 <= pot) && (pot >= 85))

Expressing comparisons like this always gives me a headache trying to work out the logic. Try the much simpler form

  if (pot < 85)
{
  //code for low
}
else if (pot >= 86 && pot <= 170)
{
  //code for medium
}
else
{
  //code for high
}
1 Like

It´s good. Thank you so much

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