Skip to content

Instantly share code, notes, and snippets.

@krobro
Last active April 27, 2017 19:27
Show Gist options
  • Save krobro/dbe0326b3fa71615b851 to your computer and use it in GitHub Desktop.
Save krobro/dbe0326b3fa71615b851 to your computer and use it in GitHub Desktop.
//
// UltrasoundPingTest
//
// Test the Ultrasound Sensor
//
// We are using port S5 on the Duinobot board
//
// NOTES:
// - Ports S0-S5 are analog input pins
// - S0 is identical to Arduino A0 and so on (S5=A5)
// - To use these ports as Digital pins add 14
//
// we are using the ping library to interact with the sensor
#include <Ping.h>
// setup the sensor on analog A5 (this is also S5)
PingSensor ping(A5); //S5 input.
void setup()
{
Serial.begin(9600);
}
void loop()
{
/* use the ping library command "ping.measureCM()" to get the distance
to the object in centimetres and store it in the variable "distance" */
int distance = ping.measureCM();
// print the distance detected by the sensor
Serial.print("Distance to object (cm): ");
Serial.println(distance);
// pause for 100 msec before we do it all again
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment