In this guide, we'll be learning how to use this radar sensor in your next Raspberry Pi Pico project. We'll be looking at how it works, what you can expect from it, how to use it with your Pico, and to top it all off, we'll be making a device that measures your running speed and plots it against Usain Bolt's 100-meter world record. Let's get into it.
This is a 24 gigahertz millimeter wave radar sensor, and it's really a testament to where technology is at nowadays. It's an inexpensive device with a lot of things going on under the hood—lots of math, lots of filtering, lots of very high-level engineering stuff—but we just get a simple UI out of it containing some really helpful information. This emits radio waves and listens for the reflections that bounce back to gather information about what it's seeing, kind of like an ultrasonic sensor. However, this sensor is way more advanced.
Not only does it use the time it takes for those radio waves to bounce back to measure the distance to the target—by the way, those radio waves are moving at the speed of light, which, when you think about it, that's not much time to be measuring—it also listens for any shift in frequencies from the Doppler effect to measure how fast the target is moving. Like how when a car drives by, you hear the frequency change; you can actually use that change in frequency to determine the speed of the object. On top of that, it has two receiver antennas on it that are used to detect the angle of the thing that's reflecting it. If you can imagine the reflection coming back at an angle, it's going to hit one of these before it hits the other side.
Very importantly, it only detects people. When it sends out those radio waves, you get a lot of things reflecting it back—your chair, the walls, your fridge, your phone—but with some very advanced signal processing, it can figure out what is actually a human by the patterns of it reflecting back. Long story short, your breathing, the subtle movements in your arm, all the tiny little movements in your body create tiny micro Doppler shifts. These slight shifts create a pattern that's very distinctive, and this radar is basically trained to pick that up and go, "That's a human."
With this sensor, you'll be able to use 24 gigahertz radio waves to detect a person, how far they are away from a sensor up to eight meters, which is the maximum range, what angle they are at from the sensor is 120 degrees of range on that, and how fast the target is moving. Now, that speed is only going to be measuring how fast towards or away from the sensor you're moving. It can't measure side to side, only forwards and backwards.
Also, one more thing: they don't like to move around. We're not entirely sure why, but we think that when you set it up, it does sort of a room calibration. If you move it, it throws that calibration out of whack, and you get some dodgy readings. Just give it a go and see what's up. It's a bit of fun. Now you know how it works and what it does. Let's go ahead and use it.
To follow along, you're going to need this RD03D radar sensor and a way to connect it to your Pico. We're going to use one of these generic cables, which connects to the onboard connector. You're, of course, going to need a Pico as well. We're just going to use the Pico 2 because it's the first one I pulled out of the box, but any variant should work. I'm just going to need some jumper wires and a breadboard to connect it all. As always, you can find links to everything you need in the written guide linked below.
Now, before we begin, the connector cable we're using for this board is generic, so you need to watch out because the colors may not match the actual pins of the board. For example, the red wire isn't power; it's actually the RX pin, and the black wire isn't ground; it's actually the TX pin. Green and yellow are actually the five-volt and ground pins on the cable that I'm using. Just double-check which color corresponds to what pin on the board. Don't trust the coloring convention of the cable.
Start by putting your breadboard in the Pico, and then we're going to power the radar by connecting the VBUS of the Pico to the five-volt pin of the radar and a ground pin of the Pico to the ground pin of the radar. I'm just using male-to-male jumper wires to connect this, and I'm using this as an opportunity to use some more appropriately colored jumper wires. So my green wire here actually becomes red, and my yellow wire becomes brown, which is power and ground.
Now, our radar is going to be outputting its data over UART. So connect the TX pin of the radar to pin one of the Pico, which is an RX pin, and then connect the RX pin of the radar to pin two of the Pico, which is a TX pin. And that's all the connections we need. Let's go ahead and jump into Thonny to code this up.
Alright, if you've never used the Pico with Thonny or you just need a quick refresher, we'll have a quick short guide linked below, which is part of a comprehensive Pico course if you want to check that out. Also linked below is the written version of this guide where you will find the library that we'll be using to decode the information coming from the radar. Download that library, unzip it, and then plug your Pico in and select the right COM port. Ensure that the file view in Thonny is enabled, and then in the top window, navigate to the library you downloaded, right-click on it, and upload it to your Pico. Then go ahead and copy and paste in the demo code that uses this library.
This code is pretty straightforward. We start off by importing all the libraries we need, including the library that we just uploaded to the Pico. Then we go ahead and set up an instance of our radar. This goes ahead and sets up all the UART and everything we need to communicate with the radar on pins zero and one. Another option we have in this setup phase is to set multi-mode to either true or false. This radar can
actually track up to three humans at once. It very reliably tracks one person, but having two or three people, especially pretty close to the sensor, can be a bit hit and miss. Further away, it's a lot better, but we're giving you the option here to try it out. If not, single tracking works really well. Right now, this is false, so it'll be set to tracking one target. We'll just turn this to true to output the data for up to three targets it's detecting.
Then, in our while true loop, we start with this line: if radar.update. So radar.update is something that you can call, and what that does is it tells the library to go ahead and get the latest information from the radar. It then checks if that information is good, and if it is good, it's going to return true. So here we're saying if radar.update, and if it's good information, it's going to be true. We're going to do whatever we put in this if statement here. It's just some really good error handling that kind of condenses it down into only a single line.
Then, to get the information for the first target, we just call .getTarget1, and obviously, we can do that for two and three as well. If it's set to single mode or there isn't anyone else being detected, it's just going to return zeros for targets two and three. The information coming from the radar is just a whole bunch of hex values that encode all the positional and angle and speed data, and the library is basically just grabbing that, unpacking it into a format that we can use, and storing it in the variables that we set here.
To use that information, we just need to call .whatever the information we want there. So here we say target.1Distance, which is just going to get the distance, and we can just scroll across here and see that we can get distance, angle, speed, x, and y. Then we're just going to go ahead and print out all of that information for all three targets. And else, which means that if there isn't a valid reading, which might happen if, I don't know, there's some error in the UART communication or our sensor unplugs, we're just going to do nothing and print that something was wrong.
Alrighty, I'm just going to go ahead and use a bit of BluTack to mount the radar so it's facing me here, and go ahead and run that code, and our radar is working and detecting me. Obviously, there's nobody behind me, hopefully, and it's not saying that anyone is there, but you can see that we have our distance, which is just the straight line distance from you to the sensor. We've also got our angle, and this way is negative if I move a little bit, and if I move the other way, it should go to the positive a bit. Nice.
We've also got our speed, which, remember, is the speed moving away or towards the sensor. So if I move forward, it's going to be negative. If I move back, it's going to be positive, and it's in centimeters a second, so convert to whatever units you need. And of course, if I move left and right, you can see that it's not really picking up any speed. It's forwards or backwards away from the sensor.
We've also got X and Y, which is a bit more tricky. Imagine that right down the middle of the sensor is like a wall. The X is a measurement of how far away you are from this wall. So right now, I'm sitting about in front of it, and we're reading nearly zero. So if I move this way, you can see that it increases as our distance increases from that wall. And if I move the other way, you can see that it should increase positively this time because we're moving positively away from the wall. And Y is a very similar concept, but imagine if that wall was what the radar was mounted on. It's a measurement of how far away you are, like parallel to the sensor. So if I stand smack bang in the middle of the sensor, and I'm about one meter away, I take three steps to the right, I'm still a meter away. I take 20 steps to the left, I'm still a meter away from the wall. So Y will keep reading one meter every time.
Let's now visualize this information with the help of Processing IDE, an awesome open-source program that's an easy way to create visuals like a radar display. This code is essentially going to take the print statements coming from the Pico and display that in a radar visualization, a nice little cool thing to look at. But before that, we're going to need to print out the data from the Pico in a specific format. So go ahead and paste in the second demo code from the written guide. Then we're going to save it to the Pico, and we're going to call it main.py. When the Pico turns on, it's going to look to see if there's a file called main.py, and if it's there, it's going to run it when it starts. This means that we don't need Thonny anymore, and whenever we just plug our Pico into a computer, it's going to start beaming that information to it.
I'm just going to go ahead and run that, and we can see that we're printing out that information. The first one is going to be the angle, the next one is the distance, and the third one is the speed, as you can see. And then it's going to be the exact same thing for targets 2 and 3 if you've got them enabled. This data format isn't a requirement in Processing IDE; we just chose this standard format and wrote our processing code around it.
Alright, let's stop that, and I'm going to go to our Processing IDE code again. Before this, we do need to change a line in here. You can see that here we've set it to use COM port 6, which has a very low chance that you're actually using COM port 6 with your Pico. So let's go to Thonny, see what COM port we're actually using here. While we're doing that, we're going to deselect that COM port because Thonny and Processing IDE can't use the Pico at the same time, or you can close Thonny if you want. Go back to Processing IDE and change this from COM port 6 to whichever COM port you saw down there. I saw 4, so I'm going to change it to 4. And finally, we can go ahead and run our script. And you can see we have our radar visual-
up, move around to the side, you can see that we come up to the maximum of 60 degrees this way and 60 degrees this way, which I probably won't get to. Each one of those rings you see around is a two-meter mark. I can probably walk back, and you can see a ghost popped up, floating around, it's haunting. Now it's gone. See some of the issues with the multi-targeting mode. That's probably just a reflection that's picking up off the back wall or the TV or something around there. That is just such a handy tool to have if you're applying this in a project because humans are a lot better at analyzing visualizations like that than just raw numbers. And of course, it's pretty fun to play around with.
Speaking of fun though, let's build something fun with it before we end. We are going to be using that speed measurement to make a human speedometer. We're going to be moving through this pretty quick, but on the written guide are some more in-depth instructions if you want to go and check it out. I'm going to start by moving everything to a PicoDev board, which lets me plug in my OLED screen with a simple connector. I'm using a PicoDev screen here, but you can also use a generic one if you plug SDA and SCL into pins eight and nine.
In the written guide, you'll find the final demo code, which we're going to go ahead and paste in. From there, you'll also find the two libraries that you need to add to your Pico exactly the same way as before. These are just going to help us operate the OLED screen. Now at the top of your code here, you have two options that you can change. You can set the speed units that you want your speedometer to measure in. You can have it as meters a second, kilometers an hour, or miles per hour. You can also enable or disable Usain Bolt's 100-meter world record as a comparison.
We're going to go ahead and save that to the Pico, and we're going to call it main.py again, which means we can run it without Thonny. Now we should be able to securely mount in place our setup somewhere and power it on. I'm going to be powering it with one of these micro USB AA battery packs. If you start standing next to the radar and move away from it, it will plot your speed in the units you chose and keep track of the maximum speed that it registers in about the six to seven meters that it can accurately do so. If you have Usain Bolt's record enabled in code, it'll also plot the start of his 100-meter world record, which will likely be the top curve. Little do they know it's not Usain Bolt's 100-meter graph. It's my 100-meter graph. It is a good bit of fun to just see how insanely quick off the mark he is. And don't forget, you can even just sprint by the sensor at full speed and see what your top speed is as well.
Well, that about wraps that up. You now know how to add a radar sensor to your Pico and get the location and speed of people in a room, which is pretty impressive for such an inexpensive piece of hardware. If you do use this to make something cool or you need a hand with anything we covered in this video, feel free to head on over to our community maker forums and post about it. We're all makers over there, and we're happy to help. Till next time though, happy making.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.