216 views|5 replies

155

Posts

3

Resources
The OP
 

【2024 DigiKey Creative Competition】ESP-32-S3- Entry-level radar detection + voice broadcast [Copy link]

 This post was last edited by Misaka10032 on 2024-10-29 01:09

Introduction

This chapter mainly completes the function of living room entry detection. Specifically, the radar module is used to detect whether there is human movement. If there is human movement, the radar will send a high level to the ESP32S3-devkit, and then this high level signal will be captured by the interrupt, thereby lighting up the red LED and driving the MX98357 module to play audio.

The wiring diagram is as follows:

I would like to thank the group members for providing I2S configuration guidance.

After the help of group friends, I successfully customized and initialized the specific PIN of I2S and played a simple tone. The specific demo is from the figure below.

If your board is wired correctly, you can hear a "beep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" sound.

Now we need to solve a problem, which is how to read the WAV format. There are many ways to play it, such as accessing the audio files saved in the SD card through the network or through the SD card. But since I am detecting the return of the living room personnel, I only need to play a "Welcome Home". So I used the AI voice generation website to generate a "Welcome Home" voice.

I encountered many problems when converting WAV audio. I will not post the unsolved bugs here. I found a good solution. Please refer to this post

The specific steps are: first use Audacity to convert the data into unsigned 8-bit WAV format. Then use Freeware Hex Editor and Disk Editor to open the WAV format data, select all the data and copy it into a C language array.

As shown in the figure below

Modify the original code for playing the tone as shown below (delete the code for playing audio data)

#include <ESP_I2S.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN 38       // Pin connected to the data input of SK68XXMINI-HS
#define NUMPIXELS 1      // Number of LEDs (set to 1 if using a single SK68XXMINI-HS)
#define INTERRUPT_PIN 1  // Pin connected to IO1 for detecting high/low signal

Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

bool ledOn = false;  // LED state

void IRAM_ATTR handleInterrupt() {
  // Toggle LED state based on the level of INTERRUPT_PIN
  ledOn = digitalRead(INTERRUPT_PIN);  // Read the state of the pin (HIGH or LOW)
}

unsigned char rawData[66044] = {
  
};


const size_t wavDataSize = sizeof(rawData) / sizeof(rawData[0]);

i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
i2s_mode_t mode = I2S_MODE_STD;
i2s_slot_mode_t slot = I2S_SLOT_MODE_MONO;

I2SClass i2s;

void setup() {
  Serial.begin(115200);
  Serial.println("I2S playback from array");

  pinMode(INTERRUPT_PIN, INPUT);                                                   // Set INTERRUPT_PIN (IO1) as input
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), handleInterrupt, CHANGE);  // Trigger on any change in level (HIGH or LOW)

  i2s.setPins(41, 42, 40);  // BCLK, LRC, DIN
  // 启动 I2S,设置采样率和每个样本的位宽
  if (!i2s.begin(mode, 30000, bps, slot)) {  // 假设采样率为 48000 Hz
    Serial.println("Failed to initialize I2S!");
    while (1)
      ;  // 不执行任何操作
  }
  pixels.begin();  // 初始化 LED
}

void loop() {
  if (ledOn) {
    // 点亮红色 LED
    pixels.setPixelColor(0, pixels.Color(255, 0, 0));  // 设置为红色
    pixels.show();                                     // 更新 LED 显示

    // 播放 WAV 数据
    for (size_t i = 0; i < wavDataSize; i++) {
      i2s.write(rawData[i]);  // 写入样本到 I2S
    }
  } else {
    // 关闭 LED
    pixels.setPixelColor(0, pixels.Color(0, 0, 0));  // 关闭 LED
    pixels.show();                                   // 更新 LED 显示
  }

  delay(5000);  // 添加一个小延迟,避免过于频繁的读取
}

And put the copied audio array in rawData. At the same time, bind the IO interrupt to read the radar feedback. It should be noted that you may need to adjust the sampling rate manually. When I downloaded this audio file, I checked that the sampling rate should be 48KHZ, but if it is played at 48KHZ, the audio will lose frames. So I adjusted the sampling rate and the delay after playing each array element for a long time. Finally, I got the code above.

The complete code for playing audio is as follows:

music_play.ino (399.74 KB, downloads: 0)

AI generated voice files:

1.wav (128.95 KB, downloads: 0)

Video Demonstration

3993b1d95758a1fe66c5d0ecd9c505e2

This post is from DigiKey Technology Zone

Latest reply

The information you shared is very good and helpful to me. Thank you for sharing such good information!   Details Published on 2024-10-29 12:33
 
 

6742

Posts

2

Resources
2
 

I will also use voice broadcast later, can 16KHz audio be played?

This post is from DigiKey Technology Zone

Comments

I haven't tried it, if your audio is ok then it should be fine.  Details Published on 2024-10-29 13:08
 
 
 

5998

Posts

6

Resources
3
 

In a confined space, can the radar also detect the

This post is from DigiKey Technology Zone

Comments

No, this radar is just a very ordinary radar. Better radars will not have this problem.  Details Published on 2024-10-29 13:08
Personal signature

在爱好的道路上不断前进,在生活的迷雾中播撒光引

 
 
 

8

Posts

0

Resources
4
 

The information you shared is very good and helpful to me. Thank you for sharing such good information!

This post is from DigiKey Technology Zone
 
 
 

155

Posts

3

Resources
5
 
wangerxian posted on 2024-10-29 09:01 I will also use voice broadcasting later. Can 16KHz audio be played?

I haven't tried it, if your audio is ok then it should be fine.

This post is from DigiKey Technology Zone
 
 
 

155

Posts

3

Resources
6
 
Qintianqintian0303 posted on 2024-10-29 09:08 In a confined space, can the radar also detect the reverse direction?

No, this radar is just a very ordinary radar. Better radars will not have this problem.

This post is from DigiKey Technology Zone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Could you please help me see how to filter this switching power supply circuit?

As the title says, the ACDC switching power supply outputs 5V voltage through LDO. How to filter it next? Below is the ...

[Hua Diao DIY] Fast food box cover, a very low-cost experimental platform for building robot walking

This post was last edited by eagler8 on 2021-2-7 17:50 After eating the fast food porridge, in addition to the delicio ...

MS8211 Pen-Type Multimeter Disassembly

This post was last edited by dcexpert on 2022-2-4 16:55 I had nothing to do these few days, and I accidentally found th ...

My own feelings about simulation software

The most annoying thing about using LTspice is that it does not support mixed analog and digital simulation. Although it ...

About the defects of MOS switches

For example, when gs is 0, the current flowing from d to s can be blocked, but due to the presence of the parasitic diod ...

Oscillator Phase Noise and Frequency Stability

This book systematically introduces the theory of phase noise and frequency stability of oscillators, explains in depth ...

[HC32F4A0 development board review] + LED control based on I2C

There are three LED lights on the HC32F4A0 development board that cannot be controlled directly through the GPIO port be ...

Xiaomi responds to "Xiaomi Auto sales continue to decline": Delivery pressure is huge, and we are confident that we will deliver more than 10,000 cars this month

This post was last edited by wklwklwbh on 2024-6-15 09:27 According to Sanyan Technology on June 13, today, the topic # ...

"Time Analysis of Embedded Software" reading activity: 7 Chapter 7 Reading Notes - Software Time in Multi-core and Multi-ECU Environments

This chapter explains some knowledge and issues about software execution under multi-core or multi-ECU. The directory is ...

Practical knowledge! Detailed explanation of PWM control principle and circuit application

PWM (Pulse Width Modulation) is a technology that uses pulses to output analog signals. It modulates the width of a seri ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list