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.
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.