Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to display data from an ultrasonic distance-measurement sensor on an OLED

By Ashutosh Bhatt April 11, 2022

In Part 1 of this series, we learned how to interface an organic light-emitting diode (OLED) display, using analog voltage (a potentiometer), with Arduino.

In Part 2, we covered how to present data from an analog sensor — specifically, a light-dependent resistor (LDR) and soil moisture sensor — on an OLED display.

In Part 3, we explained how to present data from the digital sensor DHT11, which is for temperature and humidity, also on an OLED display.

In Part 4, this final article of this series, we’ll continue to present data on an OLED display. This time, we’ll use the ultrasonic distance-measurement (UDM) sensor, HC-SR04. It measures the distance between it and an object using ultrasonic pulses.

Refer to Part I to review the basics on how to interface an OLED with Arduino for the below project.

The ultrasonic distance measurement (UDM) sensor, HC-SR04.

The UDM sensor is extensively used for short or medium-range distance measurement. It’s also used as a proximity sensor for object detection. It works on the principle of RADAR (radio detection and ranging), a detection system that uses radio waves to determine distance.

This sensor transmits tracks pulses of ultrasonic sound, detecting reflected pulses from any object. It calculates the distance by measuring the total time taken by pulses to reflect from a given object.

How the UDM sensor operates.

The sensor generates a pulse-width modulation (PWM) output. PWM is a way to control analog devices with a digital output. In this case, the output pulse width varies based on the distance of the object.

So, to measure the distance from a given object, the host device (a microcontroller) measures the width of the output pulse from the sensor.

The UDM sensor at work.

The UDM sensor has one trigger (Tr) input pin and one Echo (E) output pin. The trigger pin is given a short duration trigger pulse (10 us). When the trigger is activated, the transmitter projects eight pulses of an ultrasonic sound of about 40 kHz. 

These pulses will hit any object in range (as shown in the above diagram, which reflects them. The reflected pulses are detected by the receiver and, as per the time duration (pulse transmitted and pulse received), the sensor provides a PWM output via the Echo (E) pin. 

These are the features of the UDM sensor, HC SR04:

  1. Operates on an ultrasonic frequency of 40 kHz
  2. Distance measuring range – 1 to 400 cm
  3. Resolution – 1 cm
  4. Object detection aperture angle – 30o (-15o to +15o on either side)

The UDM sensor pins and pin functions

To interface the HC SR04 with Arduino, it’s only necessary to connect the trigger and Echo pins.

Circuit diagram:

Circuit connections:
This circuit is built using three components: an Arduino NANO board, an OLED display, and the HC-SR04 sensor. 

  • The HC-SR04 sensor has four pins: the VCC, GND, Tr, and Echo pins. The VCC and GND pins are connected with Arduino’s +5 V and GND pins. The Tr pin is connected to Arduino’s digital pin 13 and the Echo pin is connected to Arduino’s digital pin 12.
  • The OLED has four interfacing pins (as discussed in Part 1): the VCC, GND, SDA, and SCL pins. The VCC and GND pins are connected with Arduino’s +5 V and GND pins, providing the power supply to the display. The SDA and SCL pins are connected with Arduino’s A4 (SDA) and A5 (SCL) pins for data communication.
  • Arduino receives its power supply from a computer’s USB port. The onboard voltage regulator chip provides a 5V supply to the HC-SR04 and OLED display. 

Circuit operation:

  • Arduino continuously sends trigger pulses to the HC-SR04 sensor after each (1) second. As a result, the sensor continuously transmits 40 kHz of ultrasonic pulses.
  • Whenever an object is in front of the sensor, these pulses are reflected off the object and detected by the receiver.
  • The sensor provides a PWM output to Arduino.
  • Arduino measures the width of the pulse and converts it into a distance, displaying the measured distance on the OLED.

The formula Arduino uses:

Distance (in cm) = pulse width (in us)/ 29 / 2

Software program
The Arduino board microcontroller (ATMega328) performs these tasks because of the below program:

1. Provides the trigger pulse input to the HC-SR04 sensor to begin operation.
2. Measures the pulse width output from the HC-SR04 sensor.
3. Converts the pulse width into the distance.
4. Displays the distance on the OLED

This program is written in C/C++ language using Arduino IDE’s software. It’s also compiled and uploaded to Arduino’s microcontroller using the same software.

The program…

This was the final article of the sensor and OLED series. We selected commonly used sensors for these projects, but you can try others — such as the LM35, MQ2 (gas sensor), IR proximity sensor, etc. Essentially, any sensor data can be presented on an OLED display.

Video 

You may also like:


  • Insight – Learn the Working of Ultrasonic Sensors

  • What are the top open-source software systems for home automation?

  • How to use a DHT sensor to show humidity and…

  • How to display LDR and soil-moisture sensor values using an…

  • How to program an OLED display with Arduino
  • ultrasonic sensors
    An introduction to ultrasonic sensors

Filed Under: Electronic Projects, Sensors
Tagged With: arduin, diode, distance, oled, organiclightemittingdiode, sensors, udm, ultrasonicdistancemeasurement
 

Next Article

← Previous Article
Next Article →

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • Checking line impedance
  • Why do I hear whistling sounds in my vents?
  • What is the purpose of using a VCVS?
  • Mains inverter with switching node going out on the mains cable!?

RSS Electro-Tech-Online.com Discussions

  • Failure of polypropylene motor-run capacitors
  • a point I can't understand about the sinc expression
  • Quick advice on remote car starter?
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz
  • how can we detect a stack overflow

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection
  • Convection-cooled power controller integrates EtherCat connectivity

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe