Jake nussbaumer
Published

How To Use An Ultrasonic Sensor With An Arduino

Using an ultrasonic sensor with an Arduino to measure distance in CM.

BeginnerProtip6 minutes30,112
How To Use An Ultrasonic Sensor With An Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×4
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

guyaeruh_E5BKYd6QZN.PNG

if you have the echo pin connect that to digital pin 7

Code

the code

C/C++
wirings:
Vcc-5V
Grd-Ground
Trig-8
Echo-7
#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(8, 7);

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

Jake nussbaumer

Jake nussbaumer

2 projects • 1 follower

Comments