本帖最后由 花落花空 于 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模块,右下硕大的一个自动升降稳压模块(有点奢侈,但刚好有就用上了)
最终电路
电机长这个样子
安装效果,我锯掉了后面的轴,因为这种电机比一般风扇短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;
|