Last class, we made an initial exploration of the mmwave presence sensor. In this class, we will conduct an in-depth study of it and use its speed detection function—the door will open automatically if and only if a person is detected approaching and their distance from the detection point is less than a specific value, so as to build the automatic door opening detector.
Project Objectives
Knowledge Objectives
1.Understand the I2C protocol
2.Learn the speed measurement principle of the mmwave presence sensor
3.Learn the differences between the mmwave presence sensor, ultrasonic sensors and infrared sensors
Practical Objective
Build the automatic door opening detector: If a person is detected walking vertically and approaching, and the distance to the automatic door is less than 2 meters, the screen displays the door is open automatically; otherwise, and the screen displays the door is closed.
Materials List

Preparations
Hardware
(1) Set the dip switches on the back of the mmwave presence sensor to the I2C and 0x2A positions respectively.

Note: Knowledge about the I2C Protocol (or IIC Protocol) can be found in the Knowledge Base.
(2) Connect the mmwave presence sensor to the I2C interface of the UNIHIKER K10 via a module cable, then connect the UNIHIKER K10 to a computer with a USB cable.

Software
Open Mind+ v2, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

Hands-on Practice
Next, we will build the automatic door opening detector.
Task 1: Movement Speed Detection
Use the mmwave presence sensor's speed measurement function to detect the radial movement speed of a person in front of and output it via the serial port.
Task 2: Build the Automatic Door Opening Detector
Combine the sensor's speed and distance measurement functions to auto-identify a vertically walking and approaching person, and build the automatic door opening detector.
Task 1: Movement Speed Detection
Code
1.Loading and Parameter Configuration of the Mmwave Presence Sensor
STEP1:Load the mmwave radar sensor
Click "Extension", enter "Module" to search for and add the "Millimeter Wave Radar Sensor" to complete the loading of the corresponding module.

STEP2:Parameter Configuration
Use the relevant blocks under the "setmodel" module of the mmwave radar sensor to perform initial configuration for the communication address, detection mode, range and sensitivity, as shown in the figure below:

The complete program code is shown below:

2.Movement Speed Detection
First, to detect movement speed, we use“get Target (Number)”block under the “getdata”module of the mmwave radar sensor, as follows:

Note: The mmwave presence sensor must first confirm "a target exists in front", then calculate the target speed based on the "frequency change after mmwave reflection". If there is no target in front, the mmwave cannot be reflected, and the sensor's "default speed is 0" — this "0" does not mean "the target's speed is 0", but "no speed measurement target found".
Finally, output the speed measurement result via the serial port.
Note: See the Knowledge Base for the speed measurement principle of the mmwave presence sensor.
The complete program code is shown below:

Run the Code
Click the“Upload”button. After upload completion, open the serial port, move toward the mmwave presence sensor from far to near or from near to far, and observe the serial port output and the positive/negative values of speed.

Code Review
Category | Blocks | Function |
![]() | Collect and obtain the basic key information of detected targets via the mmwave presence sensor: read the number of detected target objects, measure the moving speed of target objects, calculate the distance between target objects and the sensor, and sense the signal energy reflected by target objects. |
Task 2: Build the Automatic Door Opening Detector
From the operation results of Task 1, the speed detection result is negative when a person approaches the mmwave radar sensor, and positive otherwise. Therefore, we determine whether to open the door by combining the positive/negative value, magnitude of the speed, and the distance between the person and the automatic door. The thinking is as follows:

- * -0.6 m/s is selected as the target speed judgment condition, derived from the operation data of Task 1 and the need to prevent pedestrians from only wandering (walking horizontally) in front of the door without actually entering.
* The door opens only when the distance between the person and the door is less than 2 meters, because opening it when the pedestrian is too far not only wastes energy, but also may hinder other pedestrians' passage due to an overly long door opening time.
The complete program code is shown below:

Run the Code
Click the“Upload”button.After the upload is complete, approach, move away from, or wander in front of the automatic door, and observe whether the door opens or closes.
Knowledge Base
Next, let's learn and summarize the hardware knowledge used in this lesson.
Summary of the Mmwave Presence Sensor Functions
In the previous lesson, we gained a basic understanding of the millimeter-wave sensor. Next, let’s analyze how the functions applied in this lesson differ from those introduced in the previous lesson.
Comparison Dimension | Automatic Induction Billboard | Automatic Door Opening Detector |
working mode | Existence Detection | Speed Measurement |
detection result form | Binary output: "1" for person exist, "0" for no person | Specific numerical output: target count, moving speed, distance from the sensor, etc. |
conditions for realizing detection function | No special conditions | Target count detected is not 0 |
core detection objective | Stably judge the existence or absence of personnel, avoid missed detection and false detection | Identify the state of personnel walking vertically and approaching, achieve the expected door opening and closing effect |
Speed Measurement Principle of Mmwave Presence Sensor
1.Core Foundation of Speed Measurement
The core of speed measurement for sensors is FMCW (Linear Frequency Modulated Continuous Wave)+Doppler effect: Transmit FMCW signals and calculate the target's radial moving speed by utilizing the Doppler frequency shift generated by target motion.
(1) FMCW: Millimeter wave signal with frequency varying linearly over time.
(2) Doppler Effect: When there is relative motion between the wave source and the observer, the frequency of the wave received by the observer deviates from the transmitted frequency of the wave source.
2.Specific Working Process

(1)Transmit the linear frequency modulated signal
The sensor transmits a millimeter wave signal whose frequency varies linearly with time:
* In each frequency sweep cycle T, the frequency variation of the signal is the frequency sweep bandwidth Δf (corresponding to the red-marked interval in the figure);
* The frequency modulation slope of the signal is k=Δf/T (i.e., the frequency change rate per unit time).
(2)Target motion generates a Doppler frequency shift
When there is radial motion between the target and the sensor, the target acts as both a moving signal receiver and a moving signal reflector, thus generating a frequency shift fd superimposed by two Doppler effects (Doppler frequency shift, as shown in the figure):
* The frequency shift formula is fd = 2vr / λ (vr is the radial velocity and λ is the mmwave wavelength);
* The wavelength λ is calculated from the mmwave carrier frequency f0 and the speed of light c: λ=c/f0;
(3)Frequency mixing to extract the total frequency difference signal
The sensor superimposes the transmitted signal and the received signal reflected by the target via a mixer, and outputs their total frequency difference signal after frequency mixing; this signal contains two parts of information:
* The beat frequency B related to the target distance (B = k·td, where td is the time delay of the received signal relative to the transmitted signal);
* The Doppler frequency shift fd related to the target velocity (corresponding to the frequency offset of the received signal in the figure).
(4)Calculate the target radial velocity
Extract the Doppler frequency shift fd from the total frequency difference signal and substitute it into the formula to calculate the radial velocity:
*Velocity formula: vr = fd* λ/2;
* Velocity direction rule:The radial velocity is negative when the target approaches the sensor, and positive when it moves away from the sensor.
Differences of Millimeter Wave, Ultrasonic and Infrared Sensors
We have a basic understanding of the functions and principles of mmwave sensors, so what are their advantages and characteristics compared with the more common infrared and ultrasonic sensors in daily life?
Comparison Dimension | Millimeter Wave Sensor | Ultrasonic Sensor | Active Infrared Sensor | Passive Infrared Sensor (PIR) |
Working Principle | Transmits 30GHz–300GHz millimeter waves, acquires target distance/ velocity/angle and other information via reflected signals + Doppler effect | Transmits ultrasonic waves above 20kHz, converts to target distance by calculating signal propagation time | Transmits infrared beams (850nm/940nm), measures distance by receiving reflected light
| Does not transmit signals, only detects target infrared radiation (8–14μm) to judge target presence |
Detection Range | 0.1m–50m (100m for industrial grade) | 0.02m–5m (10m at limit) | 0.1m–10m | 1m–10m (only detects presenc/absence, no definite distance measurement) |
Measurement Accuracy | Distance measurement ±1cm, velocity measurement ±0.1m/s | Distance measurement ±2–5mm | Distance measurement ±1–3cm | No distance measurement accuracy, only senses target presence |
Detectable Parameters | Distance, velocity, angle, multi-target discrimination | Distance only | Distance only | Target presence/movement, temperature difference between environment and target |
Anti-interference Performance | Resists dust, smoke and thin obstructions | Interfered by temperature, humidity and turbulence, unable to penetrate solids | Susceptible to strong light/dust/obstructions | Interfered by ambient temperature and heat sources (e.g., heating, sunlight) |
Typical Applications | Autonomous driving (ACC/AEB), industrial long-distance ranging, security perimeter radar | Reverse parking radar, liquid level detection, sweeping robot obstacle avoidance, waterproof detection | Mobile phone face recognition assistance, infrared range finder, smart door lock induction | Human body induction switch, forehead thermometer, automatic sleep mode for home appliances, security probe |
Challenge Task
Prevent kids from knocking over flower pots near the windowsill with a simple safe distance reminder. It monitors the distance between kids and pots in real time, gives a clear alert and flashes the LED when the distance is too close, so parents and kids can clearly know the safe range.
Tip: Connect an external LED light to the UNIHIKER K10, and use the high/low level of the P0 to control the LED light's on/off status.
Reference code below:











