EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: bob21 on September 06, 2020, 11:08:57 am

Title: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 06, 2020, 11:08:57 am
I am really hoping this is the right forum to ask this, because it's related more to controlling a fan via PWM than anything else, I think.

I recently got one of those small cheapo USB desk fans, which I want to control via Home Assistant. It's a small 5V unit with it's own board, and a surface mount button than cycles through the speeds: low > med > high > off : https://www.ebay.co.uk/itm/Portable-Mini-USB-Fan-Powerful-Air-Circulator-Desk-Fan-Ultra-high-Wind-UK/353171305721 (https://www.ebay.co.uk/itm/Portable-Mini-USB-Fan-Powerful-Air-Circulator-Desk-Fan-Ultra-high-Wind-UK/353171305721)

I originally thought of using an ESP to bridge the button and simulate a press, but I would have no way of knowing what state the fan was in. After some recommendations, I decided to use an ESP8266 board with integrated MOSFET, namely the Sinilink XY-WFMS: https://tech.scargill.net/sinilink-xy-wfms-esp8266-board-with-mosfet/ (https://tech.scargill.net/sinilink-xy-wfms-esp8266-board-with-mosfet/)

I have flashed this with the Tasmota firmware (compiled without the 4KHz limit), and configured the template. After changing GPIO04 from relay to PWM, I am able to turn the fan on and off and control its speed (to some degree).

The problem I am having is that PWM is totally perplexing me. I understand in general how it works, but the fine tuning aspect of it is not something I seem to be able to get right. I have read on several sources that you want a PWM frequency of at least 20KHz for a fan to avoid whining at lower speeds. If I do this, however, I don't seem to be able to control speed. If I take it down to about 12KHz, I get some very minor amount of speed control at one end of the slider, but it's whiny as hell at lower speeds. Below that, it's extremely audible.

So the major issue here is speed control without whining - I don't seem to be able to get both at once! If I understand correctly, speed is related to the duty cycle, not the frequency, but there is no duty cycle option in this firmware... I thought that it might be 'pwmrange' option relates to but I have tried playing with that to no avail. I first tried asking for help with the Tasmota guys, but whilst they are very helpful with the firmware side of things, they seemed to know less about the PWM side of things - ie. they were suprised I would want to run PWM at 20KHz. I think the usual use is things like LEDs. I am hoping someone with knowledge of Tasmota will be able to assist here.

Because I wondered if this was a Tasmota issue, I also tried using ESPhome, but had similar results. I set the frequency to 20KHz, and even tried different integers for the speed settings. Similarly to the Tasmota guys, the ESPhome guys were helpful, but I never managed to figure out how to solve it.

Here is an example of my ESPhome config:

Code: [Select]
output:
  - platform: esp8266_pwm
    pin: GPIO04
    frequency: 20000 Hz
    id: fan_pwm
   
fan:
  - platform: speed
    output: fan_pwm
    name: "Test Fan"
    speed:
      low: 0.50
      medium: 0.75
      high: 1

Presumably, the above speed setting integers affect the duty cycle? But on 20KHz, even with a value of 0.01, it doesn't slow the fan down.

One thing to note is that the ESP8266 uses software PWM, not hardware PWM like the ESP32. Although the ESP8266's software PWM has improved greatly, could this be the cause of the issues? Is using an ESP8266 a dead loss for this application? Or do I just need to try many different PWM values. If so, what? If I lose speed control at 20K but it's whiny at 12K, what am I doing wrong?

TIA for any help :)

Edit: One thing I have been considering, is if purchasing a budget oscilloscope might be useful, so I can see what frequency the fan's own board is putting out... would this be a good idea?
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 06, 2020, 01:42:56 pm
Edit: One thing I have been considering, is if purchasing a budget oscilloscope might be useful, so I can see what frequency the fan's own board is putting out... would this be a good idea?

Do you have a multimeter? A lot of budget multimeters can measure frequency and duty-cycle.

I'd go back to basics and use a PWM circuit to test your approach to controlling the fan. You can build one using a 555 timer or you can get these cheap modules from ebay/aliexpress and perhaps even amazon -- search for "PWM module", e.g.:

https://www.aliexpress.com/item/4001283129222.html (https://www.aliexpress.com/item/4001283129222.html)


Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 06, 2020, 03:39:23 pm
Hi :-)

Yes I do have a multimeter but I am not sure if it does frequency and duty cycle. It’s a Uni-T 210E clamp meter. I just had a quick look and it claims that it can do “V.F.C function for measuring signal at variable frequency” is this what you mean? If not, I am open to buying a meter that is suitable.

I can certainly grab one of those little boards from Ali, am I right in thinking that it will allow me to play with various outputs so I can ascertain what I need to get the ESP to do?



Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 06, 2020, 05:58:47 pm
Hi :-)

Yes I do have a multimeter but I am not sure if it does frequency and duty cycle. It’s a Uni-T 210E clamp meter. I just had a quick look and it claims that it can do “V.F.C function for measuring signal at variable frequency” is this what you mean? If not, I am open to buying a meter that is suitable.

It's not the same frequency & duty cycle measurement that you want.

The ANENG 8008 is not a bad buy:

https://www.eevblog.com/forum/beginners/best-cheap-pocket-size-multimeter/msg3211800/#msg3211800 (https://www.eevblog.com/forum/beginners/best-cheap-pocket-size-multimeter/msg3211800/#msg3211800)


Quote
I can certainly grab one of those little boards from Ali, am I right in thinking that it will allow me to play with various outputs so I can ascertain what I need to get the ESP to do?

Exactly.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: wraper on September 06, 2020, 06:04:33 pm
You cannot simply PWM two wire fan. You need either linear regulator or buck converter which changes it's output voltage according to PWM. Otherwise you need a fan with PWM input. Though there are some dumbasses who PWM 2 wire brushless DC fan directly, then wonder why the fan emits strange noise, does not last or control circuit suddenly dies.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 06, 2020, 09:35:21 pm
@ledtester I've grabbed the ZK-PP1K. I'll take a look at the Aneng too.  :-+

@wraper thanks for the heads up. This would seem to be a common error. Just a quick Google gets many examples of people using PWM with 2 wires. This included the threads I've been reading through relating to the ESPs. I will make sure I don't make this mistake!

In which case, one option would seem to be getting such a board instead of changing the fan for a true PWM model. Could you recommend a small linear regulator or buck converter that I may use alongside these Sinilink boards?

There is also the option to use just a 'regular' ESP8266 like the Wemos D1 mini (https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/)... if such boards exist that can with used with regular gpio or other pins on the D1, that could also be an option.

Edit: I've seen this board: https://hobbycomponents.com/motor-drivers/661-irf520-mosfet-driver-module used a few times. It would seem to be suitable, the voltage is regulated depending on the signal (pwm) pin. But then is this not the same as the Sinilink board which appears to use the D4184? The datasheet says it can be controlled by PWM?

(https://i.ibb.co/CWVfMsx/Sinilink-ESP-12-F-WIFI-mobile-phone-remote-controller-module-5v-36v-smart-home-phone-APP-XY.jpg) (https://ibb.co/CWVfMsx)
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 07, 2020, 02:33:49 am
It's hard to tell, but I think that hobbycomponents board is just a switch.

Here's something to think about...

if you attach an ESP microcontroller with WIFI you almost certainly will need to power it from mains -- i.e. it will need to be permanently plugged in. Here's a discussion of the ESP8266 power consumption in various modes:

https://diyi0t.com/how-to-reduce-the-esp8266-power-consumption/

The point is... if the fan needs to be permanently plugged in, you don't have to use the particular fan you mentioned in the first post. It opens up the possibility of using a fan that is easier to control.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 07, 2020, 08:46:13 am
It's hard to tell, but I think that hobbycomponents board is just a switch.

Ah ok, I'll drop them and email for clarification.

Here's something to think about...

if you attach an ESP microcontroller with WIFI you almost certainly will need to power it from mains -- i.e. it will need to be permanently plugged in. Here's a discussion of the ESP8266 power consumption in various modes:

https://diyi0t.com/how-to-reduce-the-esp8266-power-consumption/

The point is... if the fan needs to be permanently plugged in, you don't have to use the particular fan you mentioned in the first post. It opens up the possibility of using a fan that is easier to control.

Yes, the plan was always to have the fan plugged in. Once I figured this out, I was going to replicate it and replace a few 240v fans around the house. The main reasons being:

1. Lower power consumption
2. Plugs into existing 5V points all over the house
3. Much smaller footprint

I realise they won't be as powerful as 240v alternatives, but I'm not too fussed about that.

With all that said - I am open to ideas. The main requirement is that they be controllable via my Home Assistant instance, including the speed levels. We've had smart plugs on larger fans for ages, but the fan is just on one speed and the power is supplied/disconnected - this isn't what I'm after.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 07, 2020, 03:47:59 pm
I would disassemble the ebay fan and see if you can determine how it is controlled.

If you detach the fan from the control circuitry you should be able to tell if they are using PWM to control the fan speed.

You might also look at a fan like this:

https://www.amazon.co.uk/ELUTENG-3-Degree-Portable-Powered-Compatible/dp/B06XQWMFDQ/ref=sr_1_8?dchild=1&keywords=5v+fan&qid=1599493495&sr=8-8 (https://www.amazon.co.uk/ELUTENG-3-Degree-Portable-Powered-Compatible/dp/B06XQWMFDQ/ref=sr_1_8?dchild=1&keywords=5v+fan&qid=1599493495&sr=8-8)

to see what the speed control switch does.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 07, 2020, 04:44:21 pm
What is the best way to tell if the fan from eBay uses PWM? I don't have the Aneng yet.

Here is a pic of it:
  (http://imgur.com/E5Q4bXql.png)
 (http://i.imgur.com/E5Q4bXq.png)

Am I right in thinking there should be a mosfet or something on that if it's using PWM?

I have a fan similar to that Amazon link already, I got it to temporarily cool a RasPi. I'll see if I can dig it out.

I got a reply from Hobby Components btw - they said that the little board can output variable voltage depending on PWM signal 0-24V up to 5A. I've ordered one just in case it's what I'm looking for. Should be here in a few days.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 07, 2020, 06:22:56 pm
M1 might be the MOSFET.

Does CON3 go to the fan?

Why did they connect a red wire to GND???

The presence of an inductor (the "220" round thing) suggests voltage control. Then again, if it is voltage controlled, the fan might work on a higher voltage than 5V.

Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 07, 2020, 07:07:00 pm
M1 might be the MOSFET.

Oh right.. I assumed it would be bigger than that.

Does CON3 go to the fan?

Yes, it does. Ground (if you can believe the colour) on the outer edge.

Why did they connect a red wire to GND???

 :-// I checked with a DMM and the black wire does feed to the V+ pin on the USB plug, so the person making up the plug or the person soldering screwed up and they just repeated it  :palm:

The presence of an inductor (the "220" round thing) suggests voltage control. Then again, if it is voltage controlled, the fan might work on a higher voltage than 5V.

It's not the quietest fan.. I dread to think what it would sound like at higher voltages... :P

I guess I'll just wait for the Aneng and MOS board to arrive and see what I can find out when they get here :)

Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 08, 2020, 05:03:33 pm
Just got a message from the seller I bought the Aneng from saying he doesn't have stock of the 8008. He says he has the 870 on offer. It's only ~£6 more than the 8008, is this worth it or is he pulling one? Seems pretty good for £19....
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 08, 2020, 06:17:06 pm
The 870 is fine - but I want to verify that it can measure the frequency and duty-cycle of a PWM signal. Perhaps others on this forum know.

Btw - here is a technical review of it:

https://lygte-info.dk/review/DMMAnengAN870%20UK.html
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 08, 2020, 06:58:50 pm
Here's the deal with the 870 and measuring PWM signals:

(from the maintainer and author of the reviews on lygte-info.dk)

With the 870 you have to note this: Frequency input requires a zero crossing.
This means you cannot measure a PWM signal from 0 to 5V with the minus probe at 0V, you have to place the minus probe somewhere between 0 and 5V for it to work.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: viperidae on September 09, 2020, 07:33:50 am
Can you set the pwm frequency to, say, 10hz?
That's well below audible range and with any luck the inertia of the motor and fan will stabilise the speed.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 09, 2020, 09:33:43 am
Here's the deal with the 870 and measuring PWM signals:

(from the maintainer and author of the reviews on lygte-info.dk)

With the 870 you have to note this: Frequency input requires a zero crossing.
This means you cannot measure a PWM signal from 0 to 5V with the minus probe at 0V, you have to place the minus probe somewhere between 0 and 5V for it to work.

Ok, ditch that. I found another 8008.

Can you set the pwm frequency to, say, 10hz?
That's well below audible range and with any luck the inertia of the motor and fan will stabilise the speed.

You are right! I set the frequency to 10Hz, and low and behold I have speed control with different levels! It was slightly whiny at low speed, so I upped it to 50Hz to test and the problem went away! This is great - thanks :)

Now I am able to test the fan at different speeds with the Sinilink board, I checked the maximum speed at a few different [lower] frequencies and the highest obtainable speed is noticeably less than the fans own board.

Sinilink High Speed = Fan Own Low Speed

I checked the output voltage of the board on each speed setting, and you were right @ledtester, the fan does indeed run at a higher voltage:

Low Speed: 5V
Medium: 6V
High: 7V

I also checked another one (different model) that arrived today:

Low: 6V
Medium: 8.3V
High: 11V

So I checked what output voltages I get from the Sinilink:

Low: 1.78V
Medium: 3.4V
High: 4.9V

I was thinking of something like this: https://uk.banggood.com/DC-Boost-Converter-2A-Power-Supply-Module-2V-24V-To-5V-28V-Adjustable-Regulator-Board-p-1100757.html

But it looks like its output remains fairly stable and is not proportionate to the input. For this to work, I would need something that increases / decreases output along with the Sinilink's input.

Or scrap the Sinilink altogether and go for a a different DC-DC converter that I can control from a D1 mini or the like. Any ideas?

Edit:

One possible option:

(https://i.imgur.com/f7xT7cO.png)

But add something like the little bang good board to the 12V input of the MOS board
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 09, 2020, 03:12:21 pm
Quote
Can you set the pwm frequency to, say, 10hz?

PWM is usually done in the several hundred to several thousand or more Hz.

Quote
But it looks like its output remains fairly stable and is not proportionate to the input. For this to work, I would need something that increases / decreases output along with the Sinilink's input.

Here is the datasheet of a typical boost converter chip:

https://www.nikom.biz/pdf/XL6009.pdf (https://www.nikom.biz/pdf/XL6009.pdf)

The output voltage is set by a voltage divider (R2 and R1 in the typical application circuit). On the banggood/aliexpress/ebay modules a trim pot is used for one of those resistors.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 12, 2020, 11:11:49 am
Sorry for the delay. Really busy couple of days.

Forgive my ignorance, but I’m not sure if I understand how I would go about using that. Can you give me an example of how it might be connected?

I was looking at the spec for the Sinilink, and it seems like the input voltage range is from 5V to 36V. This means that I should be able to power it with something like this: https://www.hobbyrc.co.uk/matek-micro-bec-5v9v-adjustable (https://www.hobbyrc.co.uk/matek-micro-bec-5v9v-adjustable) then adjust the PWM/MOSFET to range from 5-7V. There's a similar one that goes to 12V for the other fan that needs a little higher voltage.

It does mean that there are few different step up / step downs though:

USB plug 5V > boost converter 9V/12V > 1. ESP8266 5V / 2. Fan 5V-7V or 6V-11V

Not sure if this is acceptable or hideously bad practice, but it does seem like the simplest way for me to archive a higher voltage for the fan.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 12, 2020, 04:22:48 pm
I'm beginning to think that a voltage controlled fan is going to be too difficult to use.

If you find a PWM controlled fan you won't need a digitally controlled boost converter. So see if you can find a 5V PWM controlled fan that you like and that will simplify the problem a lot.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 12, 2020, 08:52:03 pm
The problem I have is that most of the 5V cheapo desk fans seem to be voltage controlled. Will have a look and see what I can find.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 12, 2020, 10:56:25 pm
Another option is to use the original control board and have the ESP electronically press the button a person would press.

The ESP can sense the speed of the fan to determine which setting it is on using an led and photo-transistor.

Pressing the control button electronically can be done perhaps by the ESP digital pins directly. If not, definitely by a transistor.

If you want to go this route the first step would be to figure out what pressing the switch does. It will connect one of the pins of the fan control IC to something else -- just have to figure out which pin and what's the something else.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: bob21 on September 14, 2020, 08:36:17 am
I think it might be a bit easier than that, on the reverse side of the board the button is visible. Could the contacts of the button itself not be used? It'll be no problem soldering 2 wires from either side of the button.
Title: Re: PWM fan (2-wire) woes... guidance needed
Post by: ledtester on September 14, 2020, 08:58:52 am
The existing button contacts will be used.

You can use a small relay to replace the button, but if you want to use the ESP GPIO pins directly or if you want to use a transistor you need to know what the button connects when pressed.

So see if you can figure out what the two sides of the button are connected to.