Hi. This is a new forum, and for now you can post without registration.
Feel free to ask any questions. We are all here to help each other.

Smart Home Automation project competition

Starting with 2018 we will hold quarterly Smart Home Automation project competitions! There will also be prizes for the winners!
Read more in the official Competition topic.

ESP8266 PWM example

Discuss the popular microcontrollers and SOC. Arduino, ESP8266, Raspberry PI, etc...
User avatar
Posts: 47
Joined: Fri Nov 10, 2017 11:56 am
x 3

ESP8266 PWM example

Post by oTp » Wed Dec 06, 2017 12:31 pm

Using PWM outputs on an ESP8266 is really easy!

Basicly you just call the analogWrite function like this:

Code: Select all

analogWrite(pin, value);
You can use any IO pin, and a PWM value between 0 and 1023. 0 being always low, and 1023 being always high.

You can change the range with analogWriteRange function:

Code: Select all

With a parameter of 100 for example, If you would like a range from 0 to 100%

And you can set the frequency with analogWriteFreq function:

Code: Select all

The default frequency is 1kHz.

That's all you need to know to successfully use PWM on ESP8266.