本帖最后由 bugensui 于 2024-9-7 21:41 编辑
最近在玩面包板,买了个esp32开发版,存储够大,可以接很多组件,关键是免焊接,适合我这样的手残党,刚好电视柜上有副画,我就直接粘贴在画后面,这样什么都看不到。
可以实现:壁画音响(放音乐、tts播报,我主要是做tts播报,音乐就听个响)、雷达人体存在,温度和湿度监测,万能红外发射(控制电视和回音壁开关机等),以后还想接个麦克风,可以做语音控制,甚至接个rgb灯带,做识别特效用,效果如下:
总计成本大概在100元内(不含画的费用):需要esp32开发版、洞洞板2块,hlk2410C,DHT20温湿度传感器、红外发射管940nmled(发射),红外遥控接收1838 38khz(接收学习),MAX98357音频放大器,4欧3w小喇叭一个,三极管S8050 直插 NPN型(放大红外发射信号用),部分电阻。
参考代码如下:
esphome:
name: esp32kf
friendly_name: esp32kf
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "eD***********"
ota:
password: "6c277*******************5"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32Kf"
password: ""
captive_portal:
i2c:
sda: GPIO21
scl: GPIO22
scan: True
uart:
id: ld2410_uart
tx_pin: GPIO1
rx_pin: GPIO3
# baud_rate: 9600
baud_rate: 256000
parity: NONE
stop_bits: 1
ld2410:
uart_id: ld2410_uart #指定ld2410B使用的串口
switch:
- platform: ld2410
engineering_mode:
name: "engineering mode"
bluetooth:
name: "control bluetooth"
sensor:
- platform: internal_temperature
name: "esp32 Temperature"
- platform: uptime
id: uptime_s
update_interval: 5s
- platform: ld2410
light:
name: light
moving_distance:
name : Moving Distance
still_distance:
name: Still Distance
moving_energy:
name: Move Energy
still_energy:
name: Still Energy
detection_distance:
name: Detection Distance
- platform: aht10
variant: AHT20
temperature:
name: "Room Temperature"
humidity:
name: "Room Humidity"
update_interval: 60s
binary_sensor:
- platform: status
name: "esp32kf Status"
- platform: ld2410
has_target:
name: Occupancy
icon: mdi:home #自定义图标
has_moving_target:
name: Moving Target
has_still_target:
name: Still Target
out_pin_presence_status:
name: out pin presence status
number:
- platform: ld2410
timeout:
name: timeout
max_move_distance_gate:
name: max move distance gate
max_still_distance_gate:
name: max still distance gate
button:
- platform: ld2410
#海凌科2410c恢复出厂设置 factory_reset:
#海凌科2410c恢复出厂设置 name: "factory reset"
restart:
name: "restart"
query_params:
name: query params
- platform: template
name: "hisense power"
icon: "mdi:power-standby"
on_press:
- remote_transmitter.transmit_lg:
data: 0x00FDB04F
nbits: 32
- platform: template
name: "hisense voice+"
icon: "mdi:volume-plus"
on_press:
- remote_transmitter.transmit_lg:
data: 0x00FD22DD
nbits: 32
- platform: template
name: "hisense voice-"
icon: "mdi:volume-minus"
on_press:
- remote_transmitter.transmit_lg:
data: 0x00FDC23D
nbits: 32
text_sensor:
- platform: version
name: version
- platform: wifi_info
ip_address:
name: "esp32kf ip"
icon: mdi:ip
ssid:
name: ssid
icon: mdi:wifi
- platform: template
name: "Uptime"
lambda: |-
int seconds = (id(uptime_s).state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
icon: mdi:clock-start
update_interval: 5s
- platform: ld2410
version:
name: "hlk2410c version"
mac_address:
name: "hlk2410c mac"
select:
- platform: ld2410
distance_resolution:
name: "distance resolution"
remote_receiver:
pin:
number: GPIO33
inverted: true
mode: INPUT_PULLUP
dump: all
idle: 80ms
remote_transmitter:
pin: GPIO32
carrier_duty_percent: 50%
i2s_audio:
i2s_lrclk_pin: GPIO26
i2s_bclk_pin: GPIO27
# Example configuration entry
media_player:
- platform: i2s_audio
name: Esp32 Media Player
dac_type: external
i2s_dout_pin: GPIO25
mode: mono
总结,esp32开发版内置的dac,直接接小喇叭,也可以的,但是声音很小,要贴着耳朵听,但是用上了MAX98357放大模块后,那声音就放大了几十倍,音乐能勉强凑合听,不过我主要是为了tts服务的,红外发射模块用红外发射管,发射的话,要用三极管和电阻放大发射信号,不然红外发射距离只有1米,不实用,增加后,可以在5米左右,都可以,这样改造好后,既美观,又实用,一物多用,之前家里买的zigbee温湿度传感器,有的时候不可用,有的时候更新也慢,玩的心累,换成esphome后,很省心。
|