PIC Interface – PWM



  • pwm_init()
  • pwm_dutycycle(unsigned int duty)

Example : Generate predefined PWM using four buttons


  • Define Port-B as input and RB0, RB1, RB2 and RB3 used as button input
  • Generate PWM using PWM functions

Note  :  UN-command the line depend on your preferred compiler.


Result :


Next :

previous :


ESP8266 NodeMCU Project – Imperial March Ringtone Play in ESP8266

Pr-request to study first

  • Pulse With Modulation
  • ESP8266 NodeMCU Module – PWM

First Watch the Video Demonstration


What is RRTL?

  • Ring Tone Text Transfer Language (RTTTL) was developed by Nokia.
  • The RTTTL format is a string divided into three sections:
    • Name
    • Default value and
    • Data.
  • See More

Imperial March Music (Hear)

  • The Imperial March (Darth Vader’s Theme) is a musical theme present in the Star Wars franchise.
  • It was composed by John Williams for the film Star Wars: The Empire Strikes Back.

What is PWM

PWM in ESP8266

  • ESP8266 have four PWM.
  • Only 6 pins can be set to PWM mode at the most, if use NodeMCU Firmware

Note : Your NodeMCU firmware should have PWM Module library functions.

Required Hardware and Software Tools


ESP8266 with Buzzer Connection Diagram

NodeMCU Lua code


Follow steps

  • Connect the circuit as per the connection diagram
  • Save the above code as “AEW_RRTL_Buzzer.lua”
  • Open ESPlorer and upload the file “AEW_RRTL_Buzzer.lua”
  • Run the file  [ dofile(“AEW_RRTL_Buzzer.lua”) ]
  • Done.! Enjoy!! (Hear Imperial_march RTTL ringtone)



  • True Credits –  Arduino sketch by Andre Tagliati
  • Additional Credits – Lua code By Andres Reischle

Next :

Previous :


if you have any queries call us +918300026060 or WhatsApp Dismiss


Your Cart

%d bloggers like this: