#include<Servo.h>
Servo ioe;
//sensor y servo
int LedPinV1 = 6;
int LedPinV2 = 7;
int LedPinV3 = 8;
int trig = 5;
int echo = 4;
int tiempo;
int distancia;
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(LedPinV1, OUTPUT);
pinMode(LedPinV2, OUTPUT);
pinMode(LedPinV3, OUTPUT);
ioe.attach(12);
}
void loop() {
digitalWrite(trig,HIGH);
delay(500);
digitalWrite(trig, LOW);
tiempo = pulseIn(echo,HIGH);
distancia = tiempo/58.2;
delay(500);
if(distancia <= 10)
{
ioe.write(90);
digitalWrite(LedPinV1, HIGH);
digitalWrite(LedPinV2, HIGH);
digitalWrite(LedPinV3, HIGH);
}
else
{
ioe.write(0);
}
}