how to compare value on arduino

void setup()

{

  Serial.begin(9600);          //  setup serial
 
}

void loop() {
  
  float a;
  Serial.println("This is Degree setting level");
  Serial.print("Input Degree value you want: ");
  while(Serial.available() == 0) {}
  a = Serial.parseInt();
  Serial.print("Your input is ");
  Serial.println(a);
  while(Serial.available() == 0) {}
  Serial.println(" ");

  
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float resistance = sensorValue * 977.517106549;
  // print out the value you read:
  float voltage = resistance * ( 5.0 / 1000000.0);
  float degree = (voltage * 360) -900 ;
  
    Serial.print("Degree= "); // print the text "Degree= "
    Serial.print(degree);
    Serial.println();

  while( a == degree){
      Serial.print(degree);
      if( a ==  degree){
        Serial.println("End");
        break;}
    }
  delay(1000);

    
  
}

i have to check potentiometer's value.
so i wanna make a code.
first. i type a value what i want and then start checking pot's value untill two values be same

finally. if two values are same. the serial connect will done.

how can i do? please...sorry

arduinoareyouknow:

float a;

while(Serial.available() == 0) {}
a = Serial.parseInt();

parseInt() method returns integer value and not float; but, you are assigning the return value of parseInt() into float variable a.. Use Serial.parseFloat() instead.

  while( a == degree){
      Serial.print(degree);
      if( a ==  degree){
        Serial.println("End");
        break;}
    }

This is dumb. The body of the while statement will be executed if a and degree hold identical values. If they do, you test that they hold identical values. Why do you need to do that? Useless code (the if statement) removed, this looks like:

  while( a == degree){
      Serial.print(degree);
        Serial.println("End");
        break;
    }

Where you iterate at most once, just like an if statement would do. So, why are you using a while statement?

If you want to match the value from a potentiometer to a number then it will be much easier if you use integers rather than floating point variables. It is never a good idea to try to match two floats with == because even a tiny difference will cause that to fail.

analogRead() returns a value between 0 and 1023 so just get the user to enter a number in that range.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R