Radar Sensor BGT60 for Arduino

Supplies and components

  • Infineon BGT60LTR11AIP shield
  • Arduino MKR1000

Online services and applications

Arduino IDE

This project’s description

The BGT60LTR11AIP shield

Our shield detects motion and its direction in a range of 7 metres utilising 60GHz radar technology.
It has a compact form factor of about 20×6.25mm and uses very little power, allowing it to create new and intuitive sensing capabilities for a wide range of applications.

The compact motion sensor incorporates antennae and internally analyses the raw radar signal, allowing the gadget to function without the use of an additional microprocessor.

Interfacing with the shield is super easy using only four pins:

Gnd
Vin (1.5V - 5V)
P out (= motion direction)
T out (= motion detection)

The microcontroller Pins Vcc and GND can be linked to a power source using GND and Vin (1.5V to 5V).

The direction is represented by the phase detect out (P out) pin, while the observed motion is shown by the target detect out (T out) pin.

The BGT60 may be readily inserted into the Arduino MKR1000 Board’s headers (Vcc, GND, T out – A1 and P out – A2).

Arduino Library for Infineon 60GHz

“radar-bgt60” is the name of the library we created for our 60GHz Radar shield.

Install the Radar library in the Arduino IDE by heading to Sketch -> Include library -> Library Manager.

The radar library comes with eight basic API methods that we’ll utilise in various scenarios later.

Bgt60() - Constructor of the Arduino Bgt60 object
~Bgt60() - Destructor of the Arduino Bgt60 object
init() - Initialize the Bgt60 class object
deinit() - Deinitialize the Bgt60 class object
getMotion() - Read out target-detect-pin
getDirection() - Read out phase-detect-pin
enableInterrupt() - Enables the hardware interrupt
disableInterrupt()- Disables the hardware interrupt

You must first choose the desired platform before uploading the sketch to your board.

The Arduino MKR1000 board is used in this example.

To access the Board Manager, go to Tools -> Board -> Board Manager.

You look for your “Arduino MKR1000” and find the “Arduino SAMD Boards” package, which must be installed.

You must now select the appropriate COM-Port in order to submit the drawing.

There is a really simple way to accomplish this.

Unplug your Arduino and go to Tool -> Port to see what COM-Ports are accessible.

Connect your Arduino and double-check the ports.

You should now notice a new one that wasn’t there previously.

This is the correct option; please choose it.

Motion

In the first simple example, we’ll utilise the getMotion() method to detect motion in the sensor’s surroundings.

Take the motionDetection code from File -> Example -> radar-bgt60.

MotionDetection Code

#include <Arduino.h>
/ Include library main header /
#include <bgt60-ino.hpp>
/ Include Arduino platform header /
#include <bgt60-platf-ino.hpp>

/*
* In case no supported platform is defined, the
* PD and TD pin will be set to the values below.
*/
#ifndef TD
#define TD  15
#endif

#ifndef PD
#define PD  16
#endif

/* Create radar object with following arguments:
 *  TD : Target Detect Pin
   PD : Phase Detect Pin /
Bgt60Ino radarShield(TD, PD);

/ Begin setup function - takes care of initializations and executes only once post reset /
void setup()
{
    / Set the baud rate for sending messages to the serial monitor /
    Serial.begin(9600);
    // Configures the GPIO pins to input mode
    Error_t init_status = radarShield.init();
    / Check if the initialization was successful /
    if (OK != init_status) {
        Serial.println("Init failed.");
    }
    else {
        Serial.println("Init successful.");
    }
}

/ Begin loop function - this part of code is executed continuously until external termination /
void loop()
{
    / Initialize the variable to NO_MOTION to be able to record new events /
    Bgt60::Motion_t motion = Bgt60::NO_MOTION;

   /* The getMotion() API does two things:
        1. Returns the success or failure to detect moving object as a message of type Error_t.
           Any value other than OK indicates failure
        2. Sets recent event in "motion" variable. Events can be: NO_MOTION or MOTION */
    Error_t err = radarShield.getMotion(motion);

    / Check if API execution is successful /
    if(err == OK)
    {
        / Cases based on value set in motion variable /
        switch (motion)
        {
            / Variable "motion" is set to MOTION when moving target is detected /
            case Bgt60::MOTION:
                Serial.println("Target in motion detected!");
                break;
            /  Variable "motion" is set to NO_MOTION when moving target is not present /
            case Bgt60::NO_MOTION:
                Serial.println("No target in motion detected.");
                break;
        }
    }
    /  API execution returned error /
    else {
        Serial.println("Error occurred!");
    }

    / Reducing the frequency of the measurements /
    delay(500);
}

Direction Detection Code


#include <Arduino.h>
/ Include library main header /
#include <bgt60-ino.hpp>
/ Include Arduino platform header /
#include <bgt60-platf-ino.hpp>

/*
* In case no supported platform is defined, the
* PD and TD pin are set to the values below.
*/
#ifndef TD
#define TD  15
#endif

#ifndef PD
#define PD  16
#endif

/* Create radar object with following arguments:
 *  TD : Target Detect Pin
   PD : Phase Detect Pin /
Bgt60Ino radarShield(TD, PD);

/ Begin setup function - takes care of initialization and executes only once post reset /
void setup()
{
    / Set the baud rate for sending messages to the serial monitor /
    Serial.begin(9600);
    // Configures the GPIO pins to input mode
    Error_t init_status = radarShield.init();
    / Check if the initialization was successful /
    if (OK != init_status) {
        Serial.println("Init failed.");
    }
    else {
        Serial.println("Init successful.");
    }
}

/ Begin loop function - this part of code is executed continuously until external termination /
void loop()
{
    / Initialize the variable to NO_DIR to be able to record new events /
    Bgt60::Direction_t direction = Bgt60::NO_DIR;

    /* The getDirection() API does two things:
        1. Returns the success or failure to detect direction of object as a message of type Error_t.
           Any value other than OK indicates failure
        2. Sets recent event in "direction" variable. Events can be: APPROACHING, DEPARTING or NO_DIR */
    Error_t err = radarShield.getDirection(direction);

    / Check if API execution is successful /
    if (err == OK)
    {
        / Cases based on value set in direction variable /
        switch (direction)
        {
            / Variable "direction" is set to APPROACHING when target is moving closer to sensor /
            case Bgt60::APPROACHING:
                Serial.println("Target is approaching!");
                break;
            / Variable "direction" is set to DEPARTING when target is moving away from sensor /
            case Bgt60::DEPARTING:
                Serial.println("Target is departing!");
                break;
            / Variable "direction" is set to NO_DIR when no motion was detected /
            case Bgt60::NO_DIR:
                Serial.println("Direction cannot be determined since no motion was detected!");
                break;
        }
    }
    / API execution returned error /
    else{
        Serial.println("Error occurred!");
    }

    / Reducing the frequency of the measurements /
    delay(500);
}

Interrupt Mode Code


#include <Arduino.h>
/ Include library main header /
#include <bgt60-ino.hpp>
/ Include Arduino platform header /
#include <bgt60-platf-ino.hpp>

/*
* In case no supported platform is defined, the
* PD and TD pin will be set to the values below.
*/
#ifndef TD
#define TD  15
#endif

#ifndef PD
#define PD  16
#endif

/* Create radar object with following arguments:
 *  TD : Target Detect Pin
   PD : Phase Detect Pin /
Bgt60Ino radarShield(TD, PD);

/ Definition and initialization of the interrupt active flag /
volatile static bool intActive = false;

/ User defined callback function /
void cBackFunct(void)
{
    if ( ! intActive ) {

        / Set the interrupt active flag to avoid parallel execution of this function multiple times. /
        intActive = true;

        / Create variables to store the state of the motion as well as the direction /
        Bgt60::Motion_t motion = Bgt60::NO_MOTION;
        Bgt60::Direction_t direction = Bgt60::NO_DIR;

        /* Now check what happend, first check if a motion was detected or is
        not detected anymore */
        Error_t err = radarShield.getMotion(motion);

        / Check if API execution is successful /
        if(OK == err)
        {
            / In case motion is detected /
            if(Bgt60::MOTION == motion){
                Serial.println("Target in motion was detected!");

                / Check the direction of the detected motion /
                err = radarShield.getDirection(direction);
                if(OK == err)
                {
                    / In case the target is approaching /
                    if(Bgt60::APPROACHING == direction){
                        Serial.println("The target is approaching!");
                    }
                    / In case the target is departing /
                    else{
                        Serial.println("The target is departing!");
                    }
                }
                / API execution returned error /
                else{
                    Serial.println("Error has occurred during the determination of the direction!");
                }
            }
            / No motion is detected /
            else{
                Serial.println("No target in motion detected!");
            }
        }
        / API execution returned errord /
        else {
            Serial.println("Error has occurred during the determination of the direction!");
        }

        Serial.println("\n--------------------------------------\n");

        / Release the interrupt active flag to allow a new call of this callback function. /
        intActive = false;
    }
}

/ Begin setup function - take care of initializations and executes only once post reset /
void setup()
{
    / Set the baud rate for sending messages to the serial monitor /
    Serial.begin(9600);

    // Configures the GPIO pins to input mode
    Error_t init_status = radarShield.init();

    / Check if the initialization was successful /
    if (OK != init_status) {
        Serial.println("Init failed.");
    }
    else {
        Serial.println("Init successful.");
    }

    / Enable the interrupts /
    init_status = radarShield.enableInterrupt(cBackFunct);
    
    / Check if the interrupt init was successful /
    if (OK != init_status)
        Serial.println("Interrupt init failed.");
    else
        Serial.println("Interrupt init successful.");
}

/ Beginn loop function - this part of code is executed continuously until external termination /
void loop()
{
    // Here you can do something else in parallel while waiting for an interrupt.
    delay(1000);
}

Never chase anything, Be your best

KP

“Enjoy each n every moment of life, Learn – Grow – Improve – Heal – Dance – Have Fun – Travel – Invent” – KP

Without risking something, You can’t achieve precious goals

KP

About the author

pondabrothers

You can download our apps and books for free..
Search - Incognito Inventions

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *