Skip to main content
2 of 2
code formatting and separate paragraphs to make the answer easier to read

One thing to note about the digital write part. While you have a delay between the HIGH to LOW, there is no delay to go back to HIGH (other than the time to leave loop and re-enter; which can be very small amount of time).

While on a slower processor (like AVR) this time maybe enough to cause some buzz (and consistent buzz), on the esp8266 its going to be fast enough that IO pin may not change state at all from LOW to HIGH. On Esp8266, IO physical pin state is at a different frequency than instruction counts. I believe its only 8 MHz. Due to the time before a pin state change to take effect, changing back before it got around to changing the physical state may ignore that state change. In the specific example, the LOW may get ignored often and you will have more random effects from that sketch.

Try adding another delay of 100 ms after setting the pin LOW. this will simulate a PWM of 1000 ms on width of a 1100 ms duty cycle. And even better, lower the delays by a factor of 100 (first being delay 10 ms, the new one a delay of 1 ms), you get a 10 (or so) Hz buzz.