Arduino Course – Ultrasonic Distance Measurement (Part 9)

Click the blue text above to follow us

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Video Teaching

Arduino Course - Ultrasonic Distance Measurement (Part 9)
Arduino Course - Ultrasonic Distance Measurement (Part 9)

Lesson 9: Ultrasonic Distance Measurement

1. Course Introduction

This lesson uses the ultrasonic distance sensor as an example to explain the principle of ultrasonic distance measurement and the use of OLED display based on the IIC communication protocol.

Hardware required for this lesson: Arduino UNO, OLED display, ultrasonic distance sensor module.

2. Knowledge Points of This Lesson

Usage of OLED display and ultrasonic distance sensor module.

3. Mind+ Module

OLED Initialization

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Module location: “Display” section.

Module function: Set display type, initialize OLED.

The display type used in the course kit is four lines, with 16 characters per line. 0x3c is the address for the kit used in this course, this OLED LCD screen is based on the third-party IIC protocol, the address remains the default 0x3c and cannot be changed.

LCD Screen Content Display

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Module location: “Display” section.

Module function: Set the content to be displayed and the rows, columns, and coordinates of the content.

Ultrasonic Distance Measurement

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Module location: “Function Module” section.

Module function: Measure the pulse length signal returned by the ultrasonic distance measurement module and convert it to the corresponding distance.

Text Concatenation

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Module location: “Operator” section.

Module function: Concatenate the strings on the left and right sides into one string.

4. Program and Flowchart

Program Diagram

Arduino Course - Ultrasonic Distance Measurement (Part 9)

5. Related Knowledge Explanation

IIC Protocol

IIC is a bus communication protocol developed by Philips, where there is one master device per IIC bus, and a maximum of 127 slave devices can be connected to the 7-bit addressing IIC bus, each device corresponding to its own independent address information. The master and slave communicate via the clock bus and the data bus. The clock bus of the Arduino UNO board is port A5, and the data bus is port A4, which cannot be changed.

Principle of Ultrasonic Distance Measurement

The HC-SR04 ultrasonic distance sensor module used in the kit can measure distances from 2cm to 400cm, with an accuracy of up to 3mm. The measurement process first inputs a high-level signal of 10μs duration to the Trig port, then the signal is pulled low. The distance sensor module emits a set of 8 pulses at 40KHz, and when the pulse signal encounters an obstacle, it reflects back. Once the distance sensor module receives the returned signal, it outputs a pulse signal at the Echo port that is proportional to the measured distance. We obtain the signal length through pulse length detection, multiply it by the speed of sound, and divide by 2 to get the distance value.

Links to AI Arduino series courses:

Introduction to Arduino Basics (Part 1)

Arduino Course – Blinking LED (Part 2)

Free AI Arduino Course – SOS Signal Light (Part 3)

Free AI Arduino Course – Traffic Light (Part 4)

Arduino Course – Analog Input, Value Mapping, and Serial Monitor (Part 5)

AI Arduino Course – Dimming Desk Lamp (Part 6)

AI Arduino Course – Doorbell: Logic Judgment and Digital Input (Part 7)

AI Arduino Course – Button Switch Light (Part 8)

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Scan to Follow

Learn more about software-related information

Long press to recognize the QR code to follow us

Arduino Course - Ultrasonic Distance Measurement (Part 9)

Leave a Comment