Invisible Tape Measure With UWB Modules
by taste_the_code in Circuits > Sensors
430 Views, 1 Favorites, 0 Comments
Invisible Tape Measure With UWB Modules
In this Instructable, I'll explore distance measurement using Ultra-Wideband (UWB) technology. In previous tutorials, we dabbled with measuring distances using sound (ultrasonic sensors) and light (laser modules). While those methods were effective for short ranges—up to 2 meters with the ultrasonic module and 1.2 meters with the laser module—today's setup can measure up to an impressive 100 meters!
The star of this show is the Reyax RYUW122 module, which leverages Ultra-Wideband frequencies to transmit and receive signals. By calculating the time it takes for the signal to travel between the modules, we can measure the distance with an accuracy of up to 10 centimeters.
This project will walk you through setting up the modules, connecting them to NodeMCU microcontrollers, coding them to communicate, and testing them both indoors and outdoors.
Supplies
RYUW122_Lite website link: https://reyax.com/products/RYUW122_Lite
RYUW122 Amazon link: https://www.amazon.com/dp/B0C68NX1S8?ref=myi_title_dp
RYUW122_Lite Digi-key link: https://www.digikey.com/en/products/detail/reyax/RYUW122-Lite/22206993
Tools and materials used in the video:
- NodeMCU development Board - https://s.click.aliexpress.com/e/_oFMZD4O
- Mini OLED Screen - https://s.click.aliexpress.com/e/_ooTqTEu
- Mini Breadboards - https://s.click.aliexpress.com/e/_oF23CFC
- Dupont jumper wires - https://s.click.aliexpress.com/e/_mNyfSvg
- Multimeter - https://s.click.aliexpress.com/e/_oBvhWkE
- RD6012 Bench Power Supply - https://s.click.aliexpress.com/e/_oChVfR8
Principle of Operation
The core principle behind our distance-measuring project is the use of Ultra-Wideband (UWB) technology, specifically with the RYUW122_Lite module. UWB operates by transmitting and receiving short pulses of radio frequency signals over a broad spectrum of frequencies (6.5 GHz and 8 GHz, in this case). Here's how it works in a nutshell:
- In our setup, we need two RYUW122_Lite modules—one configured as an "anchor" and the other as a "tag". The anchor is a stationary module responsible for sending out the UWB pulses. The tag, which is the mobile unit, receives these pulses and sends a response back to the anchor.
- The anchor sends a UWB signal to the tag, which immediately responds with its own signal. By measuring the time it takes for the signal to travel to the tag and back (known as the Time of Flight), the system can calculate the distance between the two modules. This calculation is highly precise, allowing for an accuracy of up to 10 centimeters.
- Besides measuring distance, these UWB modules can also transmit data between each other. This feature opens up numerous possibilities for communication and data exchange between devices, making UWB a versatile technology for various applications like tracking and localization, especially indoors where GPS signals may falter.
In simple terms, the RYUW122_Lite module sends and receives signals, calculates the time they take to travel back and forth, and thus determines the distance between the two modules.
Connecting the Modules to NodeMCU
To connect the RYUW122_Lite modules to the NodeMCU microcontrollers I'll use a mini breadboard for easy connections.
You'll need to connect the power and ground pins first. Connect the VCC pin of the RYUW122_Lite module to the 3.3V pin on the NodeMCU. It’s crucial to remember that the RYUW122_Lite operates at 3.3V, so ensure you don’t accidentally connect it to a 5V supply, which could damage the module. Next, connect the GND pin of the module to the GND pin on the NodeMCU to complete the power circuit.
For data communication, we use the TX (Transmit) and RX (Receive) pins on the module. Connect the TX pin from the RYUW122_Lite module to the D5 pin (GPIO 14) on the NodeMCU. Similarly, connect the RX pin to the D6 pin (GPIO 12) on the NodeMCU. This setup allows the NodeMCU to send and receive data from the module using serial communication.
One of the boards will also use a mini OLED screen to display the distance, and we can connect it through I2C. Connect the VCC pin of the OLED screen to the 5V pin on the NodeMCU and the GND pin of the OLED to the GND pin on the NodeMCU. The data line (SDA) of the OLED should be connected to the D1 pin (GPIO 5), and the clock line (SCL) should be connected to the D2 pin (GPIO 4).
For the power source, I'm using portable power banks to allow easy mobility, especially during outdoor testing. Connect the NodeMCU boards to the power banks using USB cables. Alternatively, if you are in a lab setting, you can power the NodeMCUs directly via your computer USB ports.
Code
To make everything work, we need to upload code to the NodeMCUs microcontrollers to handle the communication between the RYUW122_Lite modules. The code will enable the anchor module to send signals and the tag module to respond, allowing us to calculate the distance based on the time of flight of these signals.
The core of our setup is the SoftwareSerial library, which allows the NodeMCU to communicate with the UWB modules via serial communication on specific GPIO pins.
We begin by defining the necessary pins and initializing the SoftwareSerial object. For our setup, we use GPIO 14 and GPIO 12 (D5 and D6 on the NodeMCU) for communication with the UWB module. The OLED display, if included, connects via I2C protocol, which typically uses GPIO 5 (D1) for SDA and GPIO 4 (D2) for SCL. Next, in the setup functions we initialize serial communication and configure the UWB modules as an anchor and a tag. The anchor module will be programmed to send a signal, wait for a response from the tag, and extract the time taken for the round trip. This time is directly proportional to the distance between the modules.
In the main loop, we implement the logic for continuous communication and distance calculation. The anchor sends out a signal and waits for the tag's response. Upon receiving the signal, the tag immediately sends back a reply. The anchor then calculates the time difference between sending the signal and receiving the response. This time difference is used to calculate the distance, taking into account the speed of the signal and any necessary calibration constants.
Additionally, for ease of debugging and visualization, the code includes provisions to output the calculated distance to an OLED display or via the serial monitor. This aids in real-time monitoring of the distances being measured by the setup.
The full code is available for download on my website:
https://www.tastethecode.com/electronic-tape-measure-project-using-uwb-modules
Testing the Setup
I initially tested the modules on my bench, ranging from just a few centimeters up to 12 meters through my home, including communication through several walls.
The modules work best at some distance since very short distances and quick round trips of the signal make the calculation a bit sketchy.
For the outdoor test, I used a soccer field nearby that had a diagonal distance of 120 meters. I placed the tag at one corner and I gradually moved away from it to check the measurements. I also brought a 30 meter tape measure so that I could compare the results.
At 12 meters, the distance measured from the module was a bit less than what the tape showed but as I went further, this improved significantly and at 20 and 30 meters mark, the measurement was directly on point.
Once I reached the 99.9 meters, the device stopped outputting any distance so I'm guessing that it might be in a different format or maybe the device detects that we are past the usable distance and stops outputting data. I did not had my laptop with me out in the field, but I might repeat the test later on to confirm what was going on.
In any case, the devices worked through the claimed 100 meters without any issues.
Next Steps
In this project, we explored the use of Ultra-Wideband (UWB) technology to measure distances over a range of up to 100 meters.
This is cool, but what is even better use of the technology is to have more than one anchor module so that we can triangulate the exact position of the tag in 3D space. This can be useful for indoor positioning or asset tracking where other technologies fail short.
If you have any ideas for future projects with the modules, please share them below and check out my other Instructables and my YouTube channel for more interesting projects.