How To Use An Ultrasonic Sensor With An Arduino

How To Use An Ultrasonic Sensor With An Arduino

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

  • 15,229 views
  • 1 comment
  • 8 respects

Components and supplies

Apps and online services

About this project

This is how to read the value on a ultrasonic sensor so you can make more complicated things.

Code

the codeC/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);
}

Schematics

guyaeruh_E5BKYd6QZN.PNG
if you have the echo pin connect that to digital pin 7
Guyaeruh e5bkyd6qzn

Comments

Similar projects you might like

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,645 views
  • 7 comments
  • 19 respects

IOT - Smart Jar Using ESP8266, Arduino and Ultrasonic Sensor

Project tutorial by Team Smazee

  • 6,212 views
  • 4 comments
  • 12 respects

Door Alarm With Ultrasonic Sensor

Project showcase by MattG

  • 7,116 views
  • 3 comments
  • 10 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 2,811 views
  • 0 comments
  • 15 respects
Add projectSign up / Login