Como exibir dados de um sensor ultrassônico de medição de distância em um OLED

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

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 a soil moisture sensor — on an OLED display.

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

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

See Part I to review the basics on interfacing an OLED with Arduino for the project below.

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

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

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

How the UDM sensor works.

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

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

The UDM sensor in operation.

The UDM sensor has a trigger input pin (Tr) and an echo output pin (E). The trigger pin receives a short duration (10 us) trigger pulse. When the trigger is activated, the transmitter projects eight pulses of 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 according to the time duration (transmitted pulse and received pulse), the sensor provides a PWM output via the Eco pin (E).

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

  1. Operates at an ultrasonic frequency of 40 kHz
  2. Distance measurement range – 1 to 400 cm
  3. Resolution – 1 cm
  4. Object detection opening angle – 30o (-15o to +15o on both sides)

The UDM sensor pins and pin functions

To interface the HC SR04 with the Arduino, you only need 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 to the +5 V and GND pins of the Arduino. The Tr pin is connected to the Arduino digital pin 13 and the Echo pin is connected to the Arduino digital pin 12.
  • The OLED has four interface pins (as discussed in Part 1): the VCC, GND, SDA, and SCL pins. The VCC and GND pins are connected to the +5 V and GND pins on the Arduino, providing power to the display. The SDA and SCL pins are connected to the Arduino pins A4 (SDA) and A5 (SCL) for data communication.
  • The Arduino receives its power supply from a computer's USB port. The integrated voltage regulator chip provides a 5V power supply to the HC-SR04 and OLED display.

Circuit Operation:

  • The Arduino continuously sends trigger pulses to the HC-SR04 sensor after every (1) second. As a result, the sensor continuously transmits 40 kHz 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 the Arduino.
  • The Arduino measures the pulse width and converts it into distance, displaying the measured distance on the OLED.

The formula that Arduino uses:

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

Software program
The Arduino board microcontroller (ATMega328) performs these tasks due to the program below:

1. Provide trigger pulse input to HC-SR04 sensor to start operation.
2. Measures the pulse width output of the HC-SR04 sensor.
3. Converts pulse width to distance.
4. Display distance on OLED

This program was written in C/C++ language using Arduino IDE software. It is also compiled and loaded into the Arduino microcontroller using the same software.

The program…

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

Video

Conteúdo Relacionado

The motor controller is one of the most important...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
A network of sensors is embedded in every vehicle,...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
Quando uma função é formada entre uma amostra de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.