Basic Ultrasonic Tutorial

Basic Ultrasonic Tutorial © GPL3+

A simple tutorial on getting readings from an ultrasonic sensor

  • 7,636 views
  • 4 comments
  • 35 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

Similar projects you might like

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 10,829 views
  • 4 comments
  • 31 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 10,142 views
  • 7 comments
  • 24 respects

Ultrasonic Sensor with LCD Display Using 433MHz

Project tutorial by mcharrison500

  • 9,223 views
  • 1 comment
  • 24 respects

Ultrasonic Security System

Project tutorial by Ivan

  • 34,638 views
  • 23 comments
  • 80 respects
Add projectSign up / Login