#define TRIG 25
#define ECHO 27
#define sigSV 19
#include <ESP32Servo.h>

Servo mysv;

void setup() {
  Serial.begin(115200);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  mysv.attach(sigSV);
}

void loop() {
  float dist = distance();
    Serial.println(dist);
  if(dist >= 200 && dist <= 300){
    mysv.write(255);
  }else{
    mysv.write(0);
  }
}

float distance(void){
  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  int dt = pulseIn(ECHO,HIGH);

  return (dt/58);
}