PWM not working ESP8266

Hello all! I am doing a project to make existing homes more sustainable.

Before we where using an regular Arduino Uno but we want to intergrate wifi/IoT. So we got an Esp8266. Unfortunately this doesn't has the timers we use atm.

Is there any change some knows how to overcome this problem?

We are using a 12V 4 pin PWM fan.

TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;


  TCCR1A |= (1 << COM1A1) | (1 << WGM11);
  TCCR1B |= (1 << WGM13) | (1 << CS10);
  ICR1 = TCNT1_TOP;
[PCM_FAN-CODE_SD__V2_.ino|attachment](upload://pKQJORn3QSZlRkR0T5Gw5t3d9uh.ino) (7.9 KB)

Oh and of course i ment we want to send a pwm signal to the fans. As is said before we used the timers stated above but this does not work on the ESP. If someone knows a solution we would be really grateful.

Is there any reason why you can't use analogWrite() ?

Thanks for the reply!

We have tried but the fans wouldn't react/ follow the PWM setting.

This is what we use now:

  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;


  TCCR1A |= (1 << COM1A1) | (1 << WGM11);
  TCCR1B |= (1 << WGM13) | (1 << CS10);
  ICR1 = TCNT1_TOP;

void setPwmDuty(byte duty) {
  OCR1A = (word) (duty * TCNT1_TOP) / 100;
}

There is a lot more in the code but is not relevant in this case.

The ESP8266 is not Uno. The ESP8266 has different registers than an Uno. Why not use the servo library to generate PWM on a 8266?

ESP8266 PWM with Arduino IDE – LED Fading (microcontrollerslab.com)

Thanks!

Yeah i knew that but couldn't find a solution or anything

I am gonna try to use the standard analogwrite function. Previous it didnt work for me because 4 pin PWM fans should be on 25Khz.

The default PWM frequency is 1kHz You can change the PWM frequency using the analogWriteFreq() function with values from 100Hz to 40000Hz

Hello again!

I have tried to use the analogWrite() for the PWM Duty.. The fans are not reaction at all or very slight. I also changed the freq. Do you maybe have any other ideas that could work?

How are the fans powered ?

Please post a sketch illustrating the problem and schematic of your project

The fans are powered via a seprate 12V supply.

The code i will post now is only my test code to get the PWM working on the ESP8266.

void setup() {
  // put your setup code here, to run once:
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(2,LOW);
//  analogWriteFreq(25000);
  analogWrite(4, 64);
  Serial.println("64");
  delay(10000);
  analogWrite(4, 127);
  Serial.println("127");
  delay (10000);
  analogWrite(4, 255);
  Serial.println("255");
  delay(10000);
  analogWrite(4, 127);
  Serial.println("127");
  delay(10000);
    analogWrite(4, 0);
  Serial.println("0");
  delay(10000);
}

The pinmode on pin 2 is the relais. That is not seen on the schematic.

Oh and it is not the right arduino. I am using the Wemos D1 Mini

Which pin are you using as the equivalent of VIN on the Uno ?

At this point i power the Wemos via the USB connected to the laptop

So is the schematic incorrect in showing an external 5V connection to the D1 Mini ?

The schematic is based on my previous version when we where using an UNO. We wanted a WIFI connection so started using a D1 Mini. And the only bottleneck is the PWM.

For testing i am powering the D1 Mini with the usb connected to my laptop. The pwm pin is D4 and the fans have there own 12v. The ground of the arduino and the fan come together and are connected to the ground of the 12v supply.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.