Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.