『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 9111|回复: 21

记录一个魔改的只剩外壳的电风扇折腾过程 (完结,2021.8.6)

[复制链接]

11

主题

222

帖子

2190

积分

论坛DIY达人

积分
2190
金钱
1958
HASS币
40
发表于 2021-7-18 23:06:33 | 显示全部楼层 |阅读模式
本帖最后由 花落花空 于 2021-8-6 15:46 编辑

前言:前段时间在某宝头脑一热买了个自带驱动的直流无刷风扇电机,PWM调速,几天后巧不巧在楼梯间看到邻居家放了个坏电扇,橙色还灰常不错,就说了声拎回家了。然后折腾就开始了。

已实现:全低压直流工作,6串18650满电压工作功率31瓦左右,个人感觉明显比60w的交流风扇风大。可使用升压模块将电压稳定在25.2v电机最高输入电压30v,实现一直满功率运转(实测在保护板断电前,风速没有明显降低,就拆掉了)加装旋转编码器实现无级调速。接入hass。
未实现:原有主板led由于8266的io口不够,未做支持,买的直流摇头电机还没到。暂无摇头为了保留led换成了esp32....

满功率1.2A多的电流,一个2600mah的电池组足够干2个小时了,加续航就多并嘛,我最终在底盘上装了3并6串的电池。。。容量满速转了5个小时多一些。
下图为内部电路(早期,打板前),从视频截图,依稀看的到一个控制摇头电机的mos管,旁边的3.3v稳压模块,左边悬在空中的8266模块,右下硕大的一个自动升降稳压模块(有点奢侈,但刚好有就用上了)

                               
登录/注册后可看大图


最终电路

                               
登录/注册后可看大图



电机长这个样子
Screenshot_2021-07-18-22-43-08-168_com.taobao.tao.jpg
安装效果,我锯掉了后面的轴,因为这种电机比一般风扇短2cm,所以我用两个m4的铜柱延长一下(有短的摇头杆卖,但我铜柱是现成的)

                               
登录/注册后可看大图


电池先背在背上吧。。。。计划装在底盘下面,但管子不通得打孔(不想线在外面),暂时没找到长钻头。。。   
电池线从支撑杆中间走,完美

                               
登录/注册后可看大图



完美

                               
登录/注册后可看大图

程序方面使用ESPHome,参(chao)考(xi)了@trz0332 的荣事达风扇的代码(定时啊,固定速度调节啊)
代码如下:
globals:
   - id: led_flag  #全局变量 ,用于标记是否开启led
     type: int
     restore_value: no
     initial_value: '1'

   - id: sleep_   #全局变量,用于倒计时的参数
     type: int
     restore_value: no
     initial_value: '0b0000'

script:
  - id: timer_
    then:
      - delay:  !lambda return id(sleep_)*1800000;
      - fan.turn_off: dc_fan
      - lambda: |-
         id(sleep_) = 0;
      #- switch.turn_on: update_fan_speed
      - switch.turn_off: Template_timer_led
      - switch.turn_off: Template_close_led
      #- switch.turn_on: update_fan_speed
switch: 
  - platform: gpio  #摇头led   
    pin: 21
    name: "led_sw"
    id: led_sw
    restore_mode: ALWAYS_OFF 
    internal: True
  - platform: gpio  #低档led
    pin: 27
    name: "led_L"
    id: led_L
    restore_mode: ALWAYS_OFF 
    internal: True    
    interlock: &interlock_group [led_L, led_M,led_H]
    interlock_wait_time: 100ms
  - platform: gpio  #中档led
    pin: 13
    name: "led_M"   
    id: led_M
    restore_mode: ALWAYS_OFF 
    internal: True
    interlock: *interlock_group
    interlock_wait_time: 100ms
  - platform: gpio  #高档led
    pin: 15
    restore_mode: ALWAYS_OFF 
    name: "led_H"
    id: led_H
    internal: True
    interlock: *interlock_group
    interlock_wait_time: 100ms    
#  - platform: gpio   #状态led
#    pin: 4
#    name: "led"
#    id: led
#    internal: True
  - platform: gpio  #定时显示4#led
    pin: 22
    restore_mode: ALWAYS_OFF 
    name: "led_4h"
    id: led_4h
    internal: True
  - platform: gpio  #定时显示3#led
    pin: 12
    name: "led_3h"
    id: led_3h
    restore_mode: ALWAYS_OFF 
    internal: True
  - platform: gpio  #定时显示2#led
    pin: 26
    name: "led_2h"
    id: led_2h
    restore_mode: ALWAYS_OFF 
    internal: True
  - platform: gpio   #定时显示1#led
    pin: 33
    name: "led_1h"
    id: led_1h
    restore_mode: ALWAYS_OFF 
    internal: True
  - platform: template    #模板开关 定时
    name: "${device_name}_timer_switch"
    id: Template_timer_switch
    lambda: |-
      if (id(sleep_) !=0 ) {
        return true;
      } else {
        return false;
      }

    turn_on_action: 
      then:
        - lambda: |-
            if (id(sleep_) >=15 ) {
               id(sleep_)=0;
            } else {
               id(sleep_)+=1;
            }
        - if :
            condition:
              - lambda: |-
                  return id(sleep_) ==0 ;
            then:
              - script.stop: timer_
            else:
              - script.stop: timer_
              - script.execute: timer_
        - switch.turn_on: Template_timer_led
    turn_off_action: 
      then:
        - lambda: |-
            id(sleep_)=0;
        - switch.turn_off: Template_timer_led
        - script.stop: timer_
  - platform: template    #模板开关 定时led
    name: "${device_name}_timer_led"
    internal: True
    id: Template_timer_led
    lambda: |-
      if (id(sleep_) !=0 ) {
        return true;
      } else {
        return false;
      }

    turn_on_action: 
      then:
        - if:
            condition:
              - lambda: |-
                  return id(sleep_) ==0 ;
            then:   
              - switch.turn_off: led_4h
              - switch.turn_off: led_3h
              - switch.turn_off: led_2h
              - switch.turn_off: led_1h
        - if:
            condition:
              - lambda: |-
                  return id(sleep_) & 0b1000  ;
            then:
              - switch.turn_on: led_4h
            else:
              - switch.turn_off: led_4h
        - if:
            condition:
              - lambda: |-
                  return id(sleep_) & 0b0100  ;
            then:
              - switch.turn_on: led_3h
            else:
              - switch.turn_off: led_3h
        - if:
            condition:
              - lambda: |-
                  return id(sleep_) & 0b0010  ;
            then:
              - switch.turn_on: led_2h
            else:
              - switch.turn_off: led_2h
        - if:
            condition:
              - lambda: |-
                  return id(sleep_) & 0b0001 ;
            then:
              - switch.turn_on: led_1h
            else:
              - switch.turn_off: led_1h
    turn_off_action: 
      then:
        - switch.turn_off: led_4h
        - switch.turn_off: led_3h
        - switch.turn_off: led_2h
        - switch.turn_off: led_1h
  - platform: template    #模板开关-------关闭所有灯
    name: "${device_name}_close_led"
    id: Template_close_led
    lambda: |-

        return id(led_flag);

    turn_on_action: 
      then:
        - lambda: |-
            if (id(dc_fan).state and id(dc_fan).oscillating){
              id(led_sw).turn_on();
            }
            else {id(led_sw).turn_off();}
            id(led_flag)=1;

        - lambda: |-
            if (id(dc_fan).state){
            if (id(dc_fan).speed == 0){
              id(led_L).turn_on();
              id(led_M).turn_off();
              id(led_H).turn_off();
            } else if (id(dc_fan).speed == 1){
              id(led_L).turn_off();
              id(led_M).turn_on();
              id(led_H).turn_off();
            }else if (id(dc_fan).speed == 2){
              id(led_L).turn_off();
              id(led_M).turn_off();
              id(led_H).turn_on();
            }
            }else{
              id(led_L).turn_off();
              id(led_M).turn_off();
              id(led_H).turn_off();
            }
        - if:
            condition:
              - script.is_running: timer_
            then:
              - switch.turn_on: Template_timer_led
    turn_off_action:
      then:
      #- switch.turn_off: led
        - lambda: |-
            id(led_flag)=0;
        - switch.turn_off: led_sw
        - switch.turn_off: led_L
        - switch.turn_off: led_M
        - switch.turn_off: led_H
        - switch.turn_off: Template_timer_led     

  - platform: template #模板开关,风速低
    id: fan_low
    turn_on_action:
      - fan.turn_on:
          id: dc_fan
          speed: 35
          
  - platform: template #模板开关,风速中
    id: fan_med
    turn_on_action:
      - fan.turn_on:
          id: dc_fan
          speed: 50
          
  - platform: template #模板开关,风速中高
    id: fan_medhigh
    turn_on_action:
      - fan.turn_on:
          id: dc_fan
          speed: 75
  - platform: template #模板开关,风速高
    id: fan_high
    turn_on_action:
      - fan.turn_on:
          id: dc_fan
          speed: 99  
#  - platform: template #模板开关,摇头低
#    id: ytdj_low
#    turn_on_action:
#      - fan.turn_on:
#          id: ytdj
#          speed: 50 
#  - platform: template #模板开关,摇头中
#    id: ytdj_med
#    turn_on_action:
#      - fan.turn_on:
#          id: ytdj
#          speed: 65          
#  - platform: template #模板开关,摇头高
#    id: ytdj_high
#    turn_on_action:
#      - fan.turn_on:
#          id: ytdj
#          speed: 100           
#  - platform: template #模板开关,摇头关
#    id: ytdj_off
#    turn_on_action:
#      - fan.turn_off:
#          id: ytdj
  - platform: template   #模板开关------摇头
    name: "${device_name}_Template_sw"
    id: Template_Switch
    lambda: |-
      if ( id(dc_fan).oscillating ) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      then:
        - if:
            condition:
              - lambda: |-
                  return id(dc_fan).state ==1 ;
            then:   
              - fan.turn_on:
                  id: dc_fan
                  oscillating: true 
              - switch.turn_on: led_sw     
    turn_off_action:
      then:
        - if:
            condition:
              - lambda: |-
                  return id(dc_fan).state ==1 ;
            then:   
              - fan.turn_on:
                  id: dc_fan
                  oscillating: false  
              - switch.turn_off: led_sw     
fan:
  - platform: speed
    output: output_1
    name: "DC Move Fan"
    id: dc_fan
    oscillation_output: yaotou
  
    on_turn_off:
      then:   
        - switch.turn_off: Template_close_led

                       
        # - fan.turn_off: ytdj    
  # - platform: speed
    # output: yaotou
    # name: "yaotou"
    # id: ytdj
    # on_turn_on:
      # then:    
        # - fan.turn_on:
           # id: ytdj
           # speed: 65
        # - switch.turn_on: led_sw
    # on_turn_off:
      # then:    
        # - switch.turn_off: led_sw

output:
  - platform: ledc
    pin: 2
    frequency: 1000 Hz
    id: output_1
  - platform: ledc
    pin: 32
    frequency: 1000 Hz
    id: yaotou
    max_power: 0.65
binary_sensor:
  - platform: gpio #四档固定风速切换
    pin:
      number: 17
      mode: INPUT_PULLUP
      inverted: True
    name: "speed"
    on_press:
      then:
        - fan.turn_on: dc_fan    
        - lambda: |-
            if (id(dc_fan).state) {
              if (id(dc_fan).speed == 35) {
                id(fan_med).turn_on();
              } else if (id(dc_fan).speed == 50){
                  id(fan_medhigh).turn_on();
                } else if (id(dc_fan).speed == 75){
                  id(fan_high).turn_on();
                } else {
                id(fan_low).turn_on();
              }
              }
#        - lambda: |-
#            if (id(dc_fan).state) {
#              if (id(dc_fan).speed == 35) {
#                id(led_M).turn_on();
#              } else if (id(dc_fan).speed == 50){
#                  id(led_M).turn_on();
#                } else if (id(dc_fan).speed == 75){
#                  id(led_H).turn_on();
#                } else {
#                id(led_L).turn_on();
#              }
#              }                  
  - platform: gpio #摇头按钮
    pin:
      number: 16
      mode: INPUT_PULLUP
      inverted: True
    name: "direction"
    on_press:
      then:
        - switch.toggle: Template_Switch      
#        - fan.toggle: 
#           id: ytdj
        
  - platform: gpio #关闭按钮
    pin:
      number: 19
      mode: INPUT_PULLUP
      inverted: True
    name: "off"
    on_press:
      then:
      - fan.turn_off: dc_fan
#      - fan.turn_off: ytdj

  - platform: gpio #编码器按钮
    pin:
      number: 0
      mode: INPUT_PULLUP
      inverted: True
    name: "off"
    on_press: 
      - fan.toggle: dc_fan    
#      - fan.toggle: ytdj
  - platform: gpio    #定时按钮
    internal: True
    pin: 18
    name: "${device_name}_timer_button"
    device_class: window
    on_press:
      then:
        - if:                                             
            condition:
              and:
                - lambda: |-
                   return id(dc_fan).state == 1;
            then:
              - switch.turn_on: Template_timer_switch          

sensor:
  - platform: duty_cycle #通过占空比的变动来切换风速指示灯
    pin: 2
    name: fan speed Sensor
    id: fan_speed
    update_interval: 1s
    on_value:
      then:      
        - lambda: |-
            if (id(dc_fan).state) {
              if (id(dc_fan).speed < 51) {
                id(led_L).turn_on();
              } else if (id(dc_fan).speed < 76){
                  id(led_M).turn_on();
                } else {
                id(led_H).turn_on();
              }
              }         
  - platform: rotary_encoder #无极调速编码器
    name: "dc fan Encoder"
    pin_a: 5
    pin_b: 4
    min_value: 10
    max_value: 100
    resolution: 1
    id: ec11
    on_value:
      then:
         - fan.turn_on:
            id: dc_fan
            speed: !lambda |-
              return  id(ec11).state/1.0;   

 
             


评分

参与人数 2金钱 +22 HASS币 +20 收起 理由
+ 20 + 20 感谢楼主分享!
cym9007 + 2 感谢楼主分享!

查看全部评分

回复

使用道具 举报

11

主题

222

帖子

2190

积分

论坛DIY达人

积分
2190
金钱
1958
HASS币
40
 楼主| 发表于 2021-7-18 23:19:38 | 显示全部楼层
本帖最后由 花落花空 于 2021-7-18 23:21 编辑

不会写c++,无极调速的代码虽然能用,但上电后第一次转动是从1开始,但电机带扇叶后速度为10以下启动不起来。。。。且想实现在当前速度的基础上进行调速,比如我通过按键跳到了中(50),编码器的上次值是13,这时我转动编码器就会再从13开始。。。感觉不是很好。。。希望有大佬指点
回复

使用道具 举报

123

主题

4626

帖子

1万

积分

管理员

囧死

Rank: 9Rank: 9Rank: 9

积分
16009
金钱
11298
HASS币
45
发表于 2021-7-19 13:08:35 | 显示全部楼层
厉害了word楼主!
回复

使用道具 举报

32

主题

1983

帖子

5035

积分

论坛元老

Rank: 8Rank: 8

积分
5035
金钱
3052
HASS币
50
QQ
发表于 2021-7-19 22:37:31 | 显示全部楼层
膜拜大佬。
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

11

主题

222

帖子

2190

积分

论坛DIY达人

积分
2190
金钱
1958
HASS币
40
 楼主| 发表于 2021-7-22 09:40:49 | 显示全部楼层

                               
登录/注册后可看大图


                               
登录/注册后可看大图

想起来捷配可以白嫖长板子,就xjb画了个板。。。。
立创EDA链接:https://oshwhub.com/hlhk/feng-shan-kong-zhi-ban
回复

使用道具 举报

0

主题

27

帖子

26

积分

新手上路

Rank: 1

积分
26
金钱
-1
HASS币
0
发表于 2021-8-1 14:30:21 | 显示全部楼层
oiadsjiowaudaiwojfdioasjdioasd

评分

参与人数 1金钱 -20 收起 理由
XCray -20 灌水可耻

查看全部评分

回复

使用道具 举报

1

主题

27

帖子

332

积分

中级会员

Rank: 3Rank: 3

积分
332
金钱
305
HASS币
0
发表于 2021-8-26 10:23:27 来自手机 | 显示全部楼层
牛逼大佬
回复

使用道具 举报

11

主题

180

帖子

1342

积分

金牌会员

Rank: 6Rank: 6

积分
1342
金钱
1162
HASS币
0
发表于 2021-9-4 13:32:12 来自手机 | 显示全部楼层
Esp输出可以设置档位啊,可以设置从0.14开始到0.98结束。
回复

使用道具 举报

11

主题

180

帖子

1342

积分

金牌会员

Rank: 6Rank: 6

积分
1342
金钱
1162
HASS币
0
发表于 2021-9-4 13:33:16 来自手机 | 显示全部楼层
    pin: 4     frequency: 75 Hz     id: pwm_output #    输出值区间     min_power: 0.14     max_power: 0.98
回复

使用道具 举报

11

主题

180

帖子

1342

积分

金牌会员

Rank: 6Rank: 6

积分
1342
金钱
1162
HASS币
0
发表于 2021-9-4 13:34:23 来自手机 | 显示全部楼层
你Home Assistant里面的风扇卡片是啥?
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-20 16:56 , Processed in 0.109133 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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