Created
June 7, 2019 03:46
-
-
Save HectorTorres/5da7a5a21323c86e9bbbc17fb0bb2e9c to your computer and use it in GitHub Desktop.
Sensor ultrasonico-hc-sr04 con Arduino y labVIEW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define trigPin 12 | |
#define echoPin 13 | |
void setup() { | |
Serial.begin (9600); | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
} | |
void loop() { | |
int duration, distance; | |
digitalWrite(trigPin, HIGH); //Generamos el pulso de trigger | |
delayMicroseconds(1000); | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); //Esperamos el pulso y medimos el tiempo que dura en uS | |
distance = (duration/58); //Dividimos entre 58 segun el fabricante | |
if (distance >= 255 || distance <= 0){ | |
Serial.write(255); | |
} | |
else { | |
Serial.write(distance); | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment