Skip to content

Instantly share code, notes, and snippets.

@cmoz
Last active March 23, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoz/36ed19d292ff80f73bc1cfa4b5f26b71 to your computer and use it in GitHub Desktop.
Save cmoz/36ed19d292ff80f73bc1cfa4b5f26b71 to your computer and use it in GitHub Desktop.
Ultrasonic Sensor
#include <HCSR04.h>
UltraSonicDistanceSensor distanceSensor(13, 12); // Initialize sensor that uses digital pins 13 and 12.
void setup () {
Serial.begin(9600); // We initialize serial connection so that we could print values from sensor.
}
void loop () {
// Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters.
Serial.println(distanceSensor.measureDistanceCm());
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment