Microwave Doppler Wireless Radar Sensor
The microwave motion sensor is a microwave moving object detector designed based on the Doppler radar principle. Unlike general infrared detectors, microwave sensors detect the motion of objects by detecting the microwaves reflected by the objects. The detected objects are not limited to the human body, but also include many other things. Microwave sensors are not affected by ambient temperature, have a long detection distance and high sensitivity, and are widely used in industrial, transportation, and civil applications, such as vehicle speed measurement, automatic doors, induction lights, parking radar, etc.
Due to the universality of microwave sensor detection objects, in practical life applications, they will be paired with another sensor for targeted detection. For example, a microwave sensor + infrared pyroelectric sensor can effectively determine whether someone is passing by, and will not be interfered with by sunlight or clothing color, nor will it react to other objects.
Module Source
Purchase link: https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-19589090137.12.706136b40EmwBc&id=643727489100
Materials download link: https://pan.baidu.com/s/110NZE7hM3ifS1ho53fxmoA Extraction code: 2cz6
US-016 Voltage-Type Ultrasonic Ranging Sensor
The US-016 is the only ultrasonic ranging module on the market with an analog output. The output analog voltage is proportional to the distance value, and it can be easily connected to other systems. The US-016 works stably and reliably.
The US-016 ultrasonic ranging module can achieve non-contact ranging from 2cm to 3m, with a supply voltage of 5V, an operating current of 3.8mA, and supports analog voltage output. It works stably and reliably. This module can be set to different ranges according to different application scenarios (maximum measurement distances are 1m and 3m respectively); when the Range pin is floating, the range is 3m. The US-016 can convert the measured distance into an analog voltage output, and the output voltage value is proportional to the measured distance.
Module Source
Purchase link: Materials download link: http://pan.baidu.com/s/1c08JuBQ
Specifications
Operating voltage: 3.3V-5V Operating current: 3.8MA Sensing angle: less than 15 degrees Detection distance: 2CM-300CM Detection precision: 0.3CM+1% Output method: Analog voltage Number of pins: 4 Pin
Analysis
After the module is powered on, the system first determines the input level of the Range pin, and sets different ranges according to the input level state. When the Range pin is at high level, the range is 3m; when the Range pin is at low level, the range is 1m. Then, the system starts continuous ranging, and outputs the ranging result as analog voltage on the Out pin at the same time. When the distance changes, the analog voltage will also change accordingly. The analog voltage is proportional to the measured distance, and the output range of the analog voltage is 0~Vcc.
- When the system range is 1m, the measured distance is: L = 1024*Vout/Vcc (mm). When the output voltage is 0V, the corresponding distance is 0m, and when output is Vcc, the corresponding distance is 1.024m.
- When the system range is 3m, the measured distance is: L = 3096*Vout/Vcc (mm). When the output voltage is 0V, the corresponding distance is 0m, and when output is Vcc, the corresponding distance is 3.072m.
Porting Process
Pin Selection
Port to Project
Our goal is to port the example to the ESP32-S3 dev board. Complete driver code has been provided for you. Follow the steps below to complete the porting. For detailed instructions on creating folders and new .c and .h files, refer to section 1.4.2 in the [DHT11 Temperature and Humidity Sensor] chapter; we will not repeat it here. However, here we change the file names bsp_dht11.c and bsp_dht11.h to bsp_US016.c and bsp_US016.h, and change the folder name to US016.
Write Code
In the bsp_US016.c file, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-02 LCKFB-lp first version
*/
#include "bsp_US016.h"
#include "stdio.h"
esp_adc_cal_characteristics_t *adc_chars;
void delay_ms(unsigned int ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
}
void delay_us(unsigned int us)
{
ets_delay_us(us);
}
// Ultrasonic range: Range connected to GND -> range is 1; Range connected to VCC -> range is 3; Range floating -> range is 3
// During testing, Range is floating, so the range is 3
#define RANGE 0 // =0 means range is 3 meters; =1 means range is 1 meter
/******************************************************************
* Function Name: US016_GPIO_Init
* Function Description: US016 ultrasonic module pin initialization
* Function Parameters: None
* Function Return: None
* Author: LC
* Notes:
******************************************************************/
void US016_GPIO_Init(void)
{
adc1_config_width(width);// 12-bit resolution
// ADC_ATTEN_DB_0: indicates reference voltage is 1.1V
// ADC_ATTEN_DB_2_5: indicates reference voltage is 1.5V
// ADC_ATTEN_DB_6: indicates reference voltage is 2.2V
// ADC_ATTEN_DB_11: indicates reference voltage is 3.3V
adc1_config_channel_atten( channel,atten);// Set channel 0 and 3.3V reference voltage
// Allocate memory
adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
// Initialize ADC characteristics so that it can correctly calculate conversion results and compensation factors
esp_adc_cal_characterize(unit, atten, width, DEFAULT_VREF, adc_chars);
}
/******************************************************************
* Function Name: Get_ADC_Value
* Function Description: Output after averaging the ADC value
* Function Parameters: num - number of acquisitions
* Function Return: The corresponding scanned ADC value
* Author: LC
* Notes: None
******************************************************************/
unsigned int Get_ADC_Value(unsigned int num)
{
unsigned int Data=0;
int i = 0;
for( i = 0; i < num; i++ )
{
/* Read ADC regular group data register */
Data += adc1_get_raw(channel);
delay_ms(1);
}
Data = Data/num;
return Data;
}
/******************************************************************
* Function Name: Get_distance
* Function Description: Read the measured distance
* Function Parameters: None
* Function Return: Floating-point measured distance
* Author: LC
* Notes:
When the range is 3 meters, the distance formula is: L = (A*3072/4096)*(Vref/Vcc)
When the range is 1 meter, the distance formula is: L = (A*1024/4096)*(Vref/Vcc)
Vref is the ADC reference voltage, Vcc is the US-016 power supply voltage
******************************************************************/
float Get_distance(void)
{
float distance = 0;
unsigned int d = Get_ADC_Value(30);
#if !RANGE
distance = d * 0.75;
#else
distance = d * 0.25;
#endif
return distance;
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
In the bsp_US016.h file, write the following code.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-02 LCKFB-lp first version
*/
#ifndef _BSP_US016_H_
#define _BSP_US016_H_
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_rom_sys.h"
#include "esp_timer.h"
#include "driver/uart.h"
#include "rom/ets_sys.h"
#include "esp_system.h"
#include "driver/gptimer.h"
#include "esp_log.h"
#include "freertos/queue.h"
#include "driver/spi_master.h"
#include "nvs_flash.h"
#include "esp_adc/adc_cali_scheme.h"
#include "esp_adc/adc_cali.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"
#define DEFAULT_VREF 1100 // Default reference voltage, unit mV
#define PIN_OUT 1
#define channel ADC_CHANNEL_0 // ADC measurement channel
#define width ADC_WIDTH_BIT_12 // ADC resolution
#define atten ADC_ATTEN_DB_11 // ADC attenuation
#define unit ADC_UNIT_1 // ADC1
void delay_us(unsigned int us);
void delay_ms(unsigned int ms);
void US016_GPIO_Init(void);
float Get_distance(void);
#endif2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Porting Verification
In the main function of your own project, write the following.
/*
* LCSC-Openkits (LCKFB) software and hardware materials and related expansion board software and hardware materials are all open source on the official website.
* Dev board official website: www.lckfb.com
* Technical support resides on the forum; any technical questions are welcome for exchange and learning at any time.
* LCKFB Forum: club.szlcsc.com
* Follow our Bilibili account: [LCSC-Openkits (LCKFB)] to keep up with our latest updates!
* We do not make money by selling boards; we take cultivating engineers as our mission.
* Change Logs:
* Date Author Notes
* 2024-01-02 LCKFB-lp first version
*/
#include <stdio.h>
#include "bsp_US016.h"
void app_main(void)
{
US016_GPIO_Init();
printf("demo start\r\n");
while(1)
{
printf("L = %.2f\r\n",Get_distance() );
delay_ms(100);
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Power-on effect (place an obstacle at a distance of 20cm):
Driver code:
File Download
📌 Materials Download Center (click to jump)
📌 In the Materials Download Center -> Module Porting Materials Download, inside the compressed package of this chapter.