#define pinSensor A0 //Define Sensor Pin #define pinLeds 7 //Define Leds pin void setup() { Serial.begin(9600); pinMode(pinLeds , OUTPUT);//Define pineLeds as an output pinMode(pinSensor , INPUT); } void loop() { delay(500); //Read the analog read of pinSensor float voltaje = analogRead(pinSensor) * (5 / 1023.0); float distance =(12.84/voltaje) - 0.42; Serial.print("Distance(cm):"); Serial.println(distance); if (distance < 15 && distance > 4){ digitalWrite(pinLeds , HIGH); } else{ digitalWrite(pinLeds , LOW); } }