找回密码
 立即注册

微信扫码登录

搜索
查看: 312|回复: 15

[技术探讨] 帮我看看我这个代码哪里出了问题用pwm信号控制12V的mos管

[复制链接]

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
发表于 2025-10-13 17:55:30 | 显示全部楼层 |阅读模式

esphome:
  name: water-control
  friendly_name: 非接触液位传感器实现自动供水系统
esp8266:
  board: nodemcuv2

logger:

# Enable Home Assistant API
api:
  encryption:
    key: "**********
ota:
  - platform: esphome
    password: "2**********
wifi:
  ssid: "*****" #你家wifi的ssid名
  password: "1**********611" #你家wifi密码
  
  ap:
    ssid: "Water-Control Fallback Hotspot"
    password: "88888888"

web_server:
  port: 80 # web端口


substitutions:
  config_version: 'v2022.01.23.001'
  #设备名称
  device_name: water control
  #如果SSID是隐藏的,设置为true


  # Enable fallback hotspot (captive portal) in case wifi connection fails
captive_portal:

########################################################################
uart:
  id: ld2410_uart
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 256000
  parity: NONE
  stop_bits: 1
ld2410:
  uart_id: ld2410_uart
  id: ld2410_comp

output:
  - platform: esp8266_pwm
    pin: GPIO2
    frequency: 2000Hz
    id: led_onboard
    inverted: True
  - platform: esp8266_pwm
    pin: D1
    frequency: 15000 Hz
    id: pwm_output
  - platform: esp8266_pwm
    pin: D2
    frequency: 15000 Hz
    id: pwm_output1
  - platform: esp8266_pwm
    pin: D3
    frequency: 15000 Hz
    id: pwm_output2
  - platform: esp8266_pwm
    pin: D8
    frequency: 15000 Hz
    id: pwm_output3
        

########################---------灯---------############################

light:
  - platform: monochromatic
    name: "LED On Board"
    output: led_onboard

########################-------传感器-------############################

binary_sensor:
  - platform: gpio      #水位传感器---低
    pin:
      number: D5
      mode: INPUT_PULLUP
      inverted: True
    id: water_low
    name: "${device_name} Low"

#----------------------------------------------------------------------#  
  - platform: gpio      #水位传感器-高
    pin:
      number: D6
      mode: INPUT_PULLUP
      inverted: true
    id: water_high
    name: "${device_name} High"
   
  - platform: ld2410
    has_target:
      name: Presence
    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
    g0:
      move_threshold:
        name: g0 move threshold
      still_threshold:
        name: g0 still threshold
    g1:
      move_threshold:
        name: g1 move threshold
      still_threshold:
        name: g1 still threshold
    g2:
      move_threshold:
        name: g2 move threshold
      still_threshold:
        name: g2 still threshold
    g3:
      move_threshold:
        name: g3 move threshold
      still_threshold:
        name: g3 still threshold
    g4:
      move_threshold:
        name: g4 move threshold
      still_threshold:
        name: g4 still threshold
    g5:
      move_threshold:
        name: g5 move threshold
      still_threshold:
        name: g5 still threshold
    g6:
      move_threshold:
        name: g6 move threshold
      still_threshold:
        name: g6 still threshold
    g7:
      move_threshold:
        name: g7 move threshold
      still_threshold:
        name: g7 still threshold
    g8:
      move_threshold:
        name: g8 move threshold
      still_threshold:
        name: g8 still threshold  

text_sensor:
  - platform: wifi_info
    ssid:
      name: Connected SSID
      icon: "mdi:signal-variant"
    ip_address:
      name: IP Address
      icon: "mdi:ip-network"
    mac_address:
      name: Mac Address
      icon: "mdi:wifi-marker"



button:
  - platform: ld2410
    factory_reset:
      name: "factory reset"
    restart:
      name: "restart"
    query_params:
      name: query params

select:
  - platform: ld2410
    distance_resolution:
      name: "distance resolution"
    baud_rate:
      name: "baud rate"
    light_function:
      name: light function
    out_pin_level:
      name: out pin level  
   
sensor:
  - platform: dht
    pin: D7
    temperature:
      name: ${device_name} temperature
      filters:
        - filter_out: nan
        - heartbeat: 15s
        - sliding_window_moving_average:
            window_size: 2
            send_every: 2
            send_first_at: 1
        - lambda: return x * (9.0/5.0) + 32.0; # report temperature in Fahrenheit
      unit_of_measurement: "°F"
    humidity:
      name: ${device_name} humidity
      filters:
        - filter_out: nan
        - heartbeat: 15s
        - sliding_window_moving_average:
            window_size: 2
            send_every: 2
            send_first_at: 1
      accuracy_decimals: 1 # humidity gets 0 decimals by default
    model: DHT11
    update_interval: 15s
      
  - platform: ld2410
    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
    g0:
      move_energy:
        name: g0 move energy
      still_energy:
        name: g0 still energy
    g1:
      move_energy:
        name: g1 move energy
      still_energy:
        name: g1 still energy
    g2:
      move_energy:
        name: g2 move energy
      still_energy:
        name: g2 still energy
    g3:
      move_energy:
        name: g3 move energy
      still_energy:
        name: g3 still energy
    g4:
      move_energy:
        name: g4 move energy
      still_energy:
        name: g4 still energy
    g5:
      move_energy:
        name: g5 move energy
      still_energy:
        name: g5 still energy
    g6:
      move_energy:
        name: g6 move energy
      still_energy:
        name: g6 still energy
    g7:
      move_energy:
        name: g7 move energy
      still_energy:
        name: g7 still energy
    g8:
      move_energy:
        name: g8 move energy
      still_energy:
        name: g8 still energy

fan:
  - platform: speed
    output: pwm_output
    name: valve_switch
    icon: mdi:water-pump
  - platform: speed
    output: pwm_output1
    name: water_switch
    icon: mdi:water-pump
  - platform: speed
    output: pwm_output2
    name: Air_switch
    icon: mdi:water-pump
  - platform: speed
    output: pwm_output3
    name: Light_switch
    icon: mdi:water-pump
switch:
  - platform: ld2410
    engineering_mode:
      name: "engineering mode"


回复

使用道具 举报

ZDZX 手机认证

6

主题

117

回帖

799

积分

高级会员

积分
799
金钱
676
HASS币
0
发表于 7 天前 | 显示全部楼层
出了什么问题?代码不能跑还是实现不了预期功能?前者有没有报错贴图?后者电路表现怎么样?有没有原理图?单帖一段代码实在是爱莫能助
回复

使用道具 举报

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
 楼主| 发表于 7 天前 | 显示全部楼层
ZDZX 发表于 2025-10-14 09:22
出了什么问题?代码不能跑还是实现不了预期功能?前者有没有报错贴图?后者电路表现怎么样?有没有原理图? ...

不晓得是不是mos板子有问题。信号输出电压有3.3V,板子上的信号灯通断有指示,但是指示灯的亮度很暗,就像没有电那种,控制输出的电流部分指示不亮,没有电
回复

使用道具 举报

ZDZX 手机认证

6

主题

117

回帖

799

积分

高级会员

积分
799
金钱
676
HASS币
0
发表于 7 天前 | 显示全部楼层
tanbobo 发表于 2025-10-14 13:50
不晓得是不是mos板子有问题。信号输出电压有3.3V,板子上的信号灯通断有指示,但是指示灯的亮度很暗,就 ...

有原理图或者MOS型号吗?感觉像是MOS管选型错误
回复

使用道具 举报

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
 楼主| 发表于 7 天前 | 显示全部楼层
ZDZX 发表于 2025-10-14 16:04
有原理图或者MOS型号吗?感觉像是MOS管选型错误

就是这个 以前 买了一个 但是不是在一家店铺买的都是484的mos管,那个是用esp32-c3作为控制的,能正常使用,现在就是esp32-c3编译失败所以用8266来控制。同样的接线方式,这个就不能正常控制
-10-14 163507.jpg
63536.jpg
屏幕截图 2025-10-14 163258.jpg
屏幕截图 2025-10-14 163352.jpg
回复

使用道具 举报

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
 楼主| 发表于 7 天前 | 显示全部楼层
这个是以前做的用esp32-c3作为控制 一切正常
微信图片_20251014164218_2_72.jpg
回复

使用道具 举报

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
 楼主| 发表于 7 天前 | 显示全部楼层
本帖最后由 tanbobo 于 2025-10-14 16:48 编辑

这个是这次做的 用的8266作为控制,电源输出灯不亮,信号控制灯有相应,但是光线很暗淡,就像没有电那种,控制的话,灯还是有反应。

输入电源是焊接在pcb版 dc in 上面的,照片上面看不见
微信图片_20251014164219_3_72.jpg
回复

使用道具 举报

62

主题

416

回帖

2027

积分

金牌会员

积分
2027
金钱
1549
HASS币
50
 楼主| 发表于 7 天前 | 显示全部楼层
感觉控制电路这里不一样 是不是 这个问题引起。
微信图片_20251014164218_2_72.jpg
微信图片_20251014164219_3_72.jpg
回复

使用道具 举报

ZDZX 手机认证

6

主题

117

回帖

799

积分

高级会员

积分
799
金钱
676
HASS币
0
发表于 7 天前 | 显示全部楼层
去淘宝搜了下,长相一样的板子有不一样的输入电压规格,其中你发的火火电子那家的板子输入信号要求是4-20V,PWM频率要求是0-200Hz。因此怀疑有以下问题:1、ESP系列3.3V的输出能力无法完全激活输出;2、PWM频率过高,超出板子响应能力
回复

使用道具 举报

ZDZX 手机认证

6

主题

117

回帖

799

积分

高级会员

积分
799
金钱
676
HASS币
0
发表于 7 天前 | 显示全部楼层
ZDZX 发表于 2025-10-14 18:45
去淘宝搜了下,长相一样的板子有不一样的输入电压规格,其中你发的火火电子那家的板子输入信号要求是4-20V ...

其中1可以通过直接将3.3V引脚与5V引脚分别直接接到MOS板PWM输入上,看MOS板是否正常工作来验证是否有该问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-10-21 04:07 , Processed in 0.217186 second(s), 9 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表