/*This program test the ultrasonic sensor and show distances
Serial monitor*/
#include <NewPing.h> //Include newping library in this sketch
/*CONFIGURE SENSOR PINS*/
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
//Creates class NewPing object
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
}
void loop() {
// Waits 1 second to do measures
delay(1000);
// Obtains sound travel time measure and store the value in uS
int uS = sonar.ping_median();
// Print "distance" to serial monitor
Serial.print("Distancia: ");
// Calculate the distance with a constant base
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println("cm");
}