Not equal problem

Hi
When I change Voltage on A0, U1 should show same thing but I have all the time zero - 0

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //uno

float V = 0;
int U1;

void setup() {
  pinMode(A0, INPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop() {

  V = analogRead(A0);
  V = V / 1024 * 5.0; 
  
  /////////////////////
  if (V != V)
  {
    U1 = V;
  }
  /////////////////////

  Serial.print("V= ");
  Serial.print(V);
  Serial.print("     U1= ");
  Serial.println(U1);

  lcd.setCursor(6, 1); //Place the cursor at Line 1, Column 6. From here the
  lcd.print(V, 1); //Print the number of val on the LCD
  lcd.print("V");
  delay(100);

}

Analog read return an integer, not a float. Read the documentation!
Paul

You sure about that?

not, that why I marked this part

How can V be not equal to V?

now is working
Thanks
if (currentV != V)
{
U1 = V;
}

See Reply #2. Don't attempt to compare equality or inequality on float variables.

now is working, with this I have all zeros

int V;

Actually, it doesn't work at all. The variable 'currentV' is undefined in the code you posted. So, it doesn't even compile.

I added also

float currentV;

We can't see your code

Like I said.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //uno

float V = 0;
float U1;
float currentV;

void setup() {
  pinMode(A0, INPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop() {

  V = analogRead(A0);
  V = V / 1024 * 5.0; 
  
  /////////////////////
  if (currentV != V)
  {
    U1 = V;
  }
  /////////////////////

  Serial.print("V= ");
  Serial.print(V);
  Serial.print("     U1= ");
  Serial.println(U1);

  lcd.setCursor(6, 1); //Place the cursor at Line 1, Column 6. From here the
  lcd.print(V, 1); //Print the number of val on the LCD
  lcd.print("V");
  delay(100);

}

currentV has the value 0.0, as does U1

here you are

And after that, you never change the value of currentV

when I changing U1 is following V

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