If you watch TV or play video games in general, then the first thing that pops into your mind after reading the Title is probably this:
Green circles, black background, a pointer sweeping around, and a bright green blinking dot kind of pinging around. Well, either that or the speeding tickets you've gathered throughout your driving experience.
But have you ever wondered how it works or ever wanted one yourself?
Well, most likely you've dealt with one of those without noticing because this thing is in more devices than you think e.g. airplanes, cars, traffic control, weather stations, you name it. Nearly anything that's related to object detection, motion detection, distance measurement, and/or speed measurement can involve a radar.
So, wanna know how you can detect whether there is something moving or you're just hallucinating? Get yourself a Radar Shield2Go from Infineon and start programming it with the help of Arduino IDE!
1 Crash Course: RadarRadar is short for "Radio Detection and Ranging", it is a technology that uses radio waves to detect and locate objects in its environment. It works by emitting radio waves in the form of pulses, which travel through space. When these waves encounter an object, they sort of bounce back or reflect toward the radar system. One could e.g. measure the time it takes for the waves to return and determine the distance, speed, and even the size of the object.
Long story short, a radar sends out radio waves and listens for their echoes. By analyzing these echoes, one can figure out where objects are, how far away they are, and how fast they're moving.
Some of you might mistake Radar for Ultrasound. Radar operates in the radiofrequency range with greater penetration capabilities, while ultrasound operates in the ultrasonic frequency range e.g. for imaging. It has limited penetration but higher resolution.
2 Radar Shield2Go SpecsThe Shield2Go offers easy target- and phase detection of an object with basically only two GPIOs. To summarize some specs of the Shield:
- Programmable in Arduino IDE
- Configurable detection range from 0.5m to 7m
- Potentiometers and switches to adjust the settings of the radar (QS1-QS4)
- Very small (about 5cm x 2.5cm) board design.
- 60GHz transceiver BGT60LTR11AIP MMIC with one transmitter and one receiver unit
NOTE:The higher the radar frequency, the more precise and accurate it gets. So it can detect e.g. even smaller objects and measure distance and speed more accurately.
The pinout of the Shield is as shown above. TD and PD are the main characters here, TD stands for Target Detection and PD for Phase Detection.
- TD: Logic HIGH when there has been no Target/Motion detected and logic LOW when there has been a Target/Motion detected.
- PD: If motion has been detected: logic HIGH when a target is approaching the Radar and logic LOW when a target is departing
WARNING: DO NOT TRY TO CONNECT THE SHIELD2GO DIRECTLY TO AN ARDUINO BOARD OR ANY BOARD WITH A 5V OPERATING VOLTAGE. For that, you can either use the MyIot Adapter (Hackster article here) or apply proper level shifting (5V => 3V3).
4 Setup and CodeAs mentioned above, your two best friends are TD and PD, but there are some things you need to set up first to extract the information you want:
- Adjusting the hard-coded parameters (Hardware Setup)
- Programming the Shield2Go with the radar-bgt60 Arduino Library. (Code and Library)
As mentioned before, the radar has some input parameters (QS1-QS4) that are adjustable hardware-wise with two potentiometers and two switches:
One could break these parameters down to:
- QS1: responsible for the mode of the radar; either left for autonomous (advanced) mode or right to enable the SPI mode of the sensor.
NOTE: SPI Mode is currently still in development! Only the autonomous mode is supported for now.
- QS2: adjusts the threshold for the radar, basically the detection range, the lower the value the higher the range.
- QS3: determines the hold time of the TD output. This defines how long the output status will be kept after a target is detected.
- QS4: is a tri-state switch meaning it has 3 options and sets the Radar's operating frequency. The left position equals 61.1 GHz, the middle (floating) position corresponds to 61.2 GHz and the right position is equivalent to 61.4 GHz.
Below is an example of the settings (thesesettings arealso the ones used in the software part):
- QS1 => left
- QS2 => vertical (about 2.48mtarget detection range)
- QS3 => diagonal (about 5 min hold time)
- QS4 => middle
IMPORTANT: Feel free to adjust these Inputs to calibrate your desired behavior, just make sure to adjust the settings while the Board is powered OFF.
4.2 Code and LibraryAfter having configured the Radar Shield2Go, we can go ahead and switch to the software side.
First of all, if you're not familiar with XMC for Arduino, click here to get comfortable with XMC devices and learn how to use them in an Arduino-like way.
Already know your way around? Then go ahead, open the Arduino IDE and download the radar-bgt60 library by Infineon:
You could also download the repo from here and add it to Arduino from the "Add.ZIP" Library option.
Now you can go ahead and mount your Shield2Go on your XMC2Go or MyIoT Adapter and open up Arduino IDE.
Start your code by typing the following:
#include <Arduino.h>
...
#include <bgt60-ino.hpp>
...
#include <bgt60-platf-ino.hpp>
The first library is for using the base functions of Arduino, the 2nd one is for using the main functions of the Radar Shield2Go and the 3rd one is for identifying the platform you're using.
IMPORTANT: If you're using an XMC2Go for your Radar Shield2Go type in:
#ifndef TD
#define TD 4
#endif
#ifndef PD
#define PD 8
#endif
Or generally speaking, if you're using a board other than the following boards:
- Arduino MKR1000
- Arduino MRK WIFI 1010
- Arduino Uno
- XMC1100 Boot Kit
- XMC4700 Relax Kit
then you're gonna need to define the pins connected to TD and PD respectively.
After determining those pins, define a BGT
object and call its constructor with:
Bgt60Ino radarShield(TD, PD);
Now, the main functions of the Radar Shield2Go are:
- Initializing the Radar
- Target detection
- Phase detection (Direction)
Initializing the Radar is pretty simple and belongs in the setup()
- section of your code:
Error_t init_status = radarShield.init();
if (OK != init_status) {
Serial.println("Init failed.");
}
else {
Serial.println("Init successful.");
}
init_status
is a variable of a custom datatype: Error_t,
which stores whether init()
was successful or not.
The Radar Shield2Go is actually pre-programmed to turn its BLUE LED on whenever a target (or motion) is detected. Keep in mind that the essential parameters are already decided by the QS inputs mentioned earlier. It will stay ON for a while, one would have to wait about 4-5 mins (because of QS3) without any motion for the LED to turn off.
To extract this info using Arduino, you need to use the following function in the loop()
-section:
Bgt60::Motion_t motion = Bgt60::NO_MOTION;
...
radarShield.getMotion(motion);
getMotion(motion)
: a method from theBgt60
class in the library. This basically reads the TD pin and determines whether there has beenMOTION
orNO_MOTION
detected and stores it in themotion
variable instantiated above.
Phase detection is pretty much the same concept as Target detection (also pre-programmed) and is also relative to the QS-input settings you're using. There is a REDLED above the QS1 switch that turns on when the radar senses a target departing and turns off when the target is approaching.
To make use of this in your Arduino program type the following in the loop()
-section:
Bgt60::Direction_t direction = Bgt60::NO_DIR;
...
radarShield.getDirection(direction);
getDirection(direction):
determines whether a target isAPPROACHING
,DEPARTING
, or hasNO_DIR
due to no motion and stores the result in thedirection
variable instantiated above.
So, this is the end. You are now a true master of the Radar Shield2Go! Now it's your time to get creative and do something with this knowledge.
You can use this Shield2Go for example to turn on some Arduino-programmable LED Strips when there is someone approaching or when there is generally motion detected in the area. Power it up at Midnight and connect it to an alarm to scare away thieves or maybe stray dogs (depending on your neighborhood).
Make sure to check out the examples in the Attachment section and also some from the library itself! Maybe they'll inspire you to do something great!
Keep making, stay safe, and goodbye!
Comments