Strange Values in Serial Monitor

Hi, i have a strange situation in my Arduino…

I do this code:

int PinAnalogA1 = 1; 
float valAnalog=0; 
int redPin=11; 
int yellowPin=12; 
int greenPin=13; 

float tempC = 0;
float tensao=0;

void setup()
{
  Serial.begin(9600);  
  
    pinMode(redPin, OUTPUT);  
    pinMode(yellowPin, OUTPUT);  
    pinMode(greenPin, OUTPUT);    
}

void loop () 
{
 
    valAnalog = analogRead(PinAnalogA1); 
    tensao = (valAnalog * 5.0) /1023;

    if(tensao< 2.0)
   {
     Serial.print(tensao, 1);
     Serial.print("\t");
     Serial.println(" Alarme!" );   
      
      digitalWrite(redPin, LOW);   
      digitalWrite(greenPin, LOW);
      digitalWrite(yellowPin, HIGH);
      
   } else if (tensao >4) {
     Serial.print(tensao, 1);
     Serial.print("\t");
     Serial.println(" Alarme!" );   
      
      digitalWrite(redPin, HIGH);  
      digitalWrite(greenPin, LOW);
      digitalWrite(yellowPin, LOW);
   }
    else  { 
     Serial.print(tensao,1);
     Serial.println("\t");
      digitalWrite(redPin, LOW); 
      digitalWrite(greenPin, HIGH);
      digitalWrite(yellowPin, LOW);
}

 delay(1000);
}

In my Serial Monitor i i have this Values:

2.5
5.0 Alarme!
2.6
5.0 Alarme
2.5
5.0 Alarme!
2.7
5.0 Alarme!

I don’t now why 5.0 Alarme! is printing in the Serial Monitor…

anyone now why???

    valAnalog = analogRead(PinAnalogA1);

analogRead() returns an int. Why are you storing it in a float?

Since you are going to print tensao regardless of it's value, it makes sense to do it once. It also makes sense to preface what is printed with some identifier.

It also makes sense to use Tools + Auto Format before posting horribly aligned code.

(deleted)

PaulS:

    valAnalog = analogRead(PinAnalogA1);

analogRead() returns an int. Why are you storing it in a float?

Since you are going to print tensao regardless of it's value, it makes sense to do it once. It also makes sense to preface what is printed with some identifier.

It also makes sense to use Tools + Auto Format before posting horribly aligned code.

Yes, you are right, now i'm storing to a float "PinAnalogA1 = 1;"

I'm printing the Serialprint("\t") because i'm using the processing to readUntil("\t").
I think it's not because that, i'm getting time after time the 5.0 Alarme! that i don't now where it's printing :~

(deleted)

Yes, you are right, now i'm storing to a float "PinAnalogA1 = 1;"

So, now you are storing an integer pin number in a float? Why? That is wrong, as is storing the output of analogRead() in a float.

I', expected only the values 2.3, 2.4, 2.5 or near that.

I don't urderstand why is printing 5.0 V Alarme!

Your analog read and the if statement work just fine, though you should change the following data types:

int PinAnalogA1 = 1; 
int valAnalog=0;

It seems to me that the first time through loop(), you are getting a value that shows no alarm. You change the output pins, presumably to do something to an external circuit that will, in turn, cause the analog voltage to change to 5V. You then get an alarm, and set the pins to a different state, causing the external circuit to return to a value that dos not cause an alarm.

Here's a little tip for your next question. It would probably have resulted in quicker help if you had either explained what the output pins did, or at least told us that the lines with and without "Alarme!" were all happening at 1 second intervals. I think that most programmers reading your post were assuming that the non-alarm and alarm messages were immediately following one another. The more information you provide, the easier it is to help.