Problem changing the led L status based on voltage variation

Hi everyone, I'm getting started with Arduino to build a laser harp and I'm doing some tests to check the functioning of the components and my programming skills.

What I wanted to do is to turn on and off a led on Arduino Uno using a range sensor. When it gives 1,5 V or more the led L should be on, if the sensor gives less than 1,5 V the led should switch off.

The problem is that the led remains on regardless of the voltage immitted. It shouldn't be an hardware problem, because i checked with a multimeter and the voltage reaches the board with the right variation, so i checked the program many times... but I can't get the mistake.

Here's the code:

int sens = A0;
int led = 13;

void setup()
{
pinMode(sens, INPUT);
pinMode(led, OUTPUT);
}

void loop()
{
if (analogRead(sens) >= 1,5)
{
digitalWrite(led, HIGH);
}
if (analogRead(sens) < 1,5)
{
digitalWrite(led, LOW);
}
}

  if (analogRead(sens) >= 1,5)

This isn't doing what you think it is.

analogRead of 1.5V will yield 1.5/5 * 1023 = ~306.

So change your comparisons:

if (analogRead(sens) >=306({
// action for 306 or more
}
else{
// other action for < 306
}

CrossRoads:
analogRead of 1.5V will yield 1.5/5 * 1023 = ~306.

So change your comparisons:

if (analogRead(sens) >=306({

// action for 306 or more
}
else{
// other action for < 306
}

Oh, so everytime I analogRead Volts i should divide the result by 5 and multiply 1023?

Oh, so everytime I analogRead Volts i should divide the result by 5 and multiply 1023?

Why? The relationship between voltage and analogRead()'s output is a constant. If the idea is to toggle an LED, converting the analogRead() output to a voltage is not necessary. Use the actual reading in the if statement.

ProteusInvincibile:
Oh, so everytime I analogRead Volts i should divide the result by 5 and multiply 1023?

analogRead() returns ADC codes, not volts.

ProteusInvincibile:
Oh, so everytime I analogRead Volts i should divide the result by 5 and multiply 1023?

Wouldn't you divide by 1023 and multiply by 5? (maybe in the other order to not lose precision).