---
title: "Discussion on \"ESP32 Embedded Rust at the HAL: Timer Ultrasonic Distance Measurement\" | Hashnode"
description: "Discussion on \"ESP32 Embedded Rust at the HAL: Timer Ultrasonic Distance Measurement\". This blog post is the fifth of a multi-part series of posts where I explore various peripherals in the ESP32C3 using embedded Rust at the HAL level. Please be aware that certain concepts in newer post"
url: "https://hashnode.com/posts/esp32-embedded-rust-at-the-hal-timer-ultrasonic-distance-measurement/6465e8f538c36ad305c2c12f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [ESP32 Embedded Rust at the HAL: Timer Ultrasonic Distance Measurement](https://blog.theembeddedrustacean.com/esp32-embedded-rust-at-the-hal-timer-ultrasonic-distance-measurement?utm_source=hashnode&utm_medium=feed)

This blog post is the fifth of a multi-part series of posts where I explore various peripherals in the ESP32C3 using embedded Rust at the HAL level. Please be aware that certain concepts in newer post

May 18, 2023 · 10 min read · blog.theembeddedrustacean.com  
Updated Jul 1  
Read the article

-   [#rust](https://hashnode.com/tag/rust)
-   [#esp32](https://hashnode.com/tag/esp32)
-   [#embedded](https://hashnode.com/tag/embedded)
-   [#tutorial](https://hashnode.com/tag/tutorial)

## Written by

[Omar Hiari](https://hashnode.com/@omarhiari)

@omarhiari

  
[View profile](https://hashnode.com/@omarhiari)

I am an 📟 Embedded Engineer with years of experience in both industry 🏭 and academia 🏫. Passionate Mentor 👨‍💼 and Instructor 👨‍🏫. Rustacean 🦀

## Responses 1

Markdown supported · ⌘↵ to post

[Mariusz Białończyk](https://hashnode.com/@manio)

[Jul 25, 2023](https://hashnode.com/posts/esp32-embedded-rust-at-the-hal-timer-ultrasonic-distance-measurement/6465e8f538c36ad305c2c12f/comment/64bf5564453a851c7eb95de9)

Hi, First of all, much thanks for sharing this! I was planning to use it in my application using pure ESP32 and JSN-SR04T. I found samples/examples but not in Rust - and suddenly I encounter this site! :) A working implementation will help me a lot, thanks!

I have one doubt/question regarding the wiring: You are powering up the sensor from 5V. This means that the internal logic on the ECHO and TRIGGER pins is also 5V, right?

I saw on several applications the same wiring as yours, but isn't it, that the `echo` should go via some level shifter?, eg like here: https :// camo.githubusercontent.com/aef16862dcee3db4696e1d14a25ed97a27f16ed6ada8edf5de1c8b1d06859323/68747470733a2f2f692e696d6775722e636f6d2f384f4a395451432e706e67

I don't know - maybe the ESP32 pins are capable of handling this (if so - it is probably not preferred during long run?), but I am only asking what is the proper way of doing the wiring...

[Omar Hiari](https://hashnode.com/@omarhiari)

[Jul 25, 2023](https://hashnode.com/posts/esp32-embedded-rust-at-the-hal-timer-ultrasonic-distance-measurement/6465e8f538c36ad305c2c12f/comment/64bf5564453a851c7eb95de9#reply-64bf7a50c6ba3a1b3898617a)

Thank you for reading [Mariusz Białończyk](https://hashnode.com/@manio)! Your doubt is in its place. Since I hooked up the sensor to 5V power then the TTL output levels of the ECHO pin will reach 5V. While pins typically have internal protection, this would still expose them to potential damage. No need to mention, it didn't matter in the simulation. As such, there are two options to address this; either a voltage divider like you indicated to shift the 5V range to a 3.3V range or use a 3.3V compatible device. However, for the latter, I think the accuracy is not as good as the 5V sensors. I adjusted the diagram in Wokwi to include the voltage divider.

[Mariusz Białończyk](https://hashnode.com/@manio)

[Jul 25, 2023](https://hashnode.com/posts/esp32-embedded-rust-at-the-hal-timer-ultrasonic-distance-measurement/6465e8f538c36ad305c2c12f/comment/64bf5564453a851c7eb95de9#reply-64bf81c0453a851c7eb965f4)

[Omar Hiari](https://hashnode.com/@omarhiari) Great! Thank you, Omar :)
