Basic Ultrasonic Tutorial

Basic Ultrasonic Tutorial © GPL3+

A simple tutorial on getting readings from an ultrasonic sensor

  • 6,416 views
  • 3 comments
  • 31 respects

Components and supplies

About this project

I am building an Arduino course for my students, and I could not find a tutorial on taking readings from an ultrasonic sensor. I wanted a simple tutorial which shows students how to get information from an ultrasonic sensor, and do something with it. So I decided to make one.

The project simply takes a reading from the ultrasonic sensor and then displays the measurement on a LCD. The code is very simple as its purpose is for explanation.

Code

Ultrasonic sensor introductionArduino
#include <Ultrasonic.h>                   // import ultrasonic library
#include <LiquidCrystal.h>                // import LCD library

Ultrasonic ultrasonic(2,3);               // Register ultrasonic sensor with interface pins trig:2, echo:3
LiquidCrystal lcd(0,1,8,9,10,11);         // Register the LCD with interface pins RS:0, E:1, D4:8, D5:9, D6: 10, D7:11)

void setup() {
  // setup the LCD's number of coulumns and rows
  lcd.begin(16,2);
    
}

void loop() {
  // take a measurement and display it on the LCD
  lcd.clear();                            // Clears the screen in preparation of new measurement    
  lcd.print("Distance in cm:");           // Prints the first line of the display
  lcd.setCursor(0,1);                     // Moves cursor tot he second line of display
  lcd.print(ultrasonic.distanceRead());   // Takes measurement from US and prints it to LCD
  delay(500);                             // waits half a second

}

Schematics

Ultrasonic sensor introduction
Breadboard diagram. The ultrasonic was hard to show as it stand upright. Just make sure the wires line up.
Untrasonic bb2 wffdqc5z9z

Comments

Author

Damomurtagh
Damien Murtagh
  • 1 project
  • 8 followers

Additional contributors

Published on

September 22, 2017

Members who respect this project

Photo1061999Inductor color code   copyDefault12540590 741555235974555 3535889509737692135 n u3tbvajh6hCuqta11899992 678186638978969 6989292847876235549 nVarunjha089

and 23 others

See similar projects
you might like

Similar projects you might like

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 6,670 views
  • 4 comments
  • 23 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 6,125 views
  • 7 comments
  • 21 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 2,811 views
  • 0 comments
  • 15 respects

Ultrasonic Security System

Project tutorial by Ivan

  • 17,283 views
  • 18 comments
  • 50 respects
Add projectSign up / Login