Skip to content

Instantly share code, notes, and snippets.

@HectorTorres
Created June 7, 2019 03:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save HectorTorres/5da7a5a21323c86e9bbbc17fb0bb2e9c to your computer and use it in GitHub Desktop.
Sensor ultrasonico-hc-sr04 con Arduino y labVIEW
#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