A Price
Published © GPL3+

Ultrasonic Testing

Testing the HC-SR04 by pinging an ultrasonic sensor.

BeginnerShowcase (no instructions)30 minutes7,400
Ultrasonic Testing

Things used in this project

Story

Read more

Schematics

images_jNTy96miRy.jpg

Code

Untitled file

C/C++
/*
 * The circuit:
 * * Module HR-SC04 (four pins) or PING))) (and other with
 *   three pins), attached to digital pins as follows:
 * ---------------------    ---------------------
 * | HC-SC04 | Arduino |    | 3 pins  | Arduino |
 * ---------------------    ---------------------
 * |   Vcc   |   5V    |    |   Vcc   |   5V    |
 * |   Trig  |   7    | OR |   SIG   |   13    |
 * |   Echo  |   8    |    |   Gnd   |   GND   |
 |   Gnd   |   GND   |    ---------------------
  ---------------------
 
*/
#include <Ultrasonic.h>

/*
 * Pass as a parameter the trigger and echo pin, respectively,
 * or only the signal pin (for sensors 3 pins), like:
  Ultrasonic ultrasonic(13); */
 ////////////////////////you may need to switch the two numbers below////////////////////////
Ultrasonic ultrasonic(7, 8);

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print("Distance in CM: ");
  // Pass INC as a parameter to get the distance in inches
  Serial.println(ultrasonic.distanceRead());
  delay(1000);
}

Credits

A Price
3 projects • 5 followers
I am the best Okie from Muskogee programmer. (https://www.youtube.com/watch?v=D5K5l89mpV8) i have been doing electronics for 4 years.

Comments