Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • 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 →

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

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 feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • LM317 Help in design
  • Everywhere My question is getting deleted...
  • Opamp clamp
  • Failed to create my first project of MS51PC0AE, 8051 family of Nuvoton.
  • VNA Measurement Setup for Twisted-Pair Cable S-Parameter Modeling

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Curiosity is difficult.
  • DBT alternative idea
  • dimmer schematic discussion
  • Funny Images Thread!
  • How Do You Usually Translate Longer Morse Code Messages?

Featured Tutorials

VHDL Series (1-24)

  • VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
    VHDL Tutorial 17: Design a JK flip-flop (with preset and clear) using VHDL
  • VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
    VHDL Tutorial 18: Design a T flip-flop (with enable and an active high reset input) using VHDL
  • VHDL Tutorial – 19: Designing a 4-bit binary counter using VHDL
    VHDL Tutorial – 19: Designing a 4-bit binary counter using VHDL
  • VHDL Tutorial – 20: Designing 4-bit binary-to-gray & gray-to-binary code converters
    VHDL Tutorial – 20: Designing 4-bit binary-to-gray & gray-to-binary code converters
  • VHDL Tutorial – 21: Designing an 8-bit, full-adder circuit using VHDL
    VHDL Tutorial – 21: Designing an 8-bit, full-adder circuit using VHDL
  • VHDL Tutorial – 22: Designing a 1-bit & an 8-bit comparator by using VHDL
    VHDL Tutorial – 22: Designing a 1-bit & an 8-bit comparator by using VHDL
More Tutorials >

Recent Articles

  • Using a joystick with MicroPython and NODEMCU (Part 10)
  • Qorvo four-channel beamformer covers 7.9 to 12 GHz
  • Nuvoton 26-cell monitor integrates EIS diagnostics
  • Nuvoton MPUs combine 650 MHz computing with real-time control
  • Five questions safety and security teams should answer together

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • 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 © 2026 Arrowfly 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 Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertise
  • Subscribe