Created
January 31, 2014 22:27
-
-
Save Gazer/8744520 to your computer and use it in GitHub Desktop.
Ejemplo sensor ultrasónico HC-SR04 con Arduino y NewPing
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
#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