Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created January 31, 2014 22:27
Show Gist options
  • Save Gazer/8744520 to your computer and use it in GitHub Desktop.
Save Gazer/8744520 to your computer and use it in GitHub Desktop.
Ejemplo sensor ultrasónico HC-SR04 con Arduino y NewPing
#include <NewPing.h>
#define trigPin 2
#define echoPin 4
NewPing sonar(trigPin, echoPin, 800);
void setup() {
Serial.begin(9600);
}
void loop() {
delay(150);
int uS = sonar.ping();
float cm = uS / US_ROUNDTRIP_CM;
Serial.print("Ping: ");
Serial.print(cm);
Serial.println("cm");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment