Wemos D1+ MQTT pwm fan speed

Arduino function for NodeMCU PWM

  • analogWrite(pin, dutycycle): Enables software PWM on the specified pin. duty cycleis in the range from 0 to PWMRANGE, i.e. 1023 by default.
  • analogWrite(pin, 0): Disables PWM on specified pin.
  • analogWriteRange(new_range): This function is used to change PWM range (duty cycle).
  • analogWriteFreq(new_frequency): PWM frequency is 1kHz by default. Call this function to change it with new frequency.PWM frequency is in the range 1 – 1000Khz.

my bad, sorry. you need to put this in the code also initialize it.

not necessary an LED connect on gpio14 (D5 and GND) : working without pinMode();

connect to cayenne and wifi account + this code :

CAYENNE_IN(10)
{
int currentValue = getValue.asInt();
int pwmLed = map(currentValue, 0, 100, 0, 1023);
Serial.print(“\nGet slide cmd :”); Serial.println(currentValue);
Serial.print(“Set pwm led :”); Serial.println(pwmLed);
analogWrite(14, pwmLed);
}

result on serial and (LED light with different state) :

[11481] Connecting to mqtt.mydevices.com:1883
[12083] Connected

Get slide cmd :35
Set pwm led :358

Get slide cmd :2
Set pwm led :20

Get slide cmd :97
Set pwm led :992

on the other hand the gpio is not powerful enough to turn a fan ! Do you think to put a motor driver between Wemos and motor like this ?

@SuperNinja he might have fired his device :joy:

We all do that kind of mistake 1 time in the beginning :wink:

Hi,

I try everything, but the device still does not want to work :frowning:
I was try to change the0-255 to 0-1203, try to SuperNinja code too,
I measure it and if i change the slider value, the input doesnt want to change. i wiil need 0-3.3V to control the fan, but it always 0.
Pls help.

Thanks you

show us your last complet code

Here is my code
Link

@ory.gabriel so the problem you are facing is to control a fan using a slider. we will solve this one step at a time.
are you able to read slider value on the serial monitor when you change the position of the slider on the dashboard.

If i change the slider position, the serial monitor read it, but the output pin dont change, always same V, but if output is 0V then the fan is stopped, if the output volt is 3.3V the fan is run full speed

Now for this code tha fan work this method: i set 10 to slider step value, if i set 0 the fan stop, but if a set between 10-100 the fan run at full speed

so what do you want?

i want to control the fan with slider. if slider is 10 the run the fan 10%, if 20 then run 20% etc

which driver you are using to control the fan?

Wemos d1 r2 and mosfet

can you buy a driver module (l298) as those are much efficient and easy to connect.

no, i buy this. its work, but somthing wrong on my code

how do you know it works? do you have any docs on it.

my friend test it. but he cant help in the code