Pulse Width Modulation : PWM using Arduino

PWM using Arduino

Pulse Width Modulation or PWM is a method of Digital to Analog Conversion. It helps in delivering analog average voltage using digital pulses of variable pulse width. By controlling the on time and off time, we can generate an analog average voltage using the digital pulses.

PWM using Arduino

PWM has a wide range of application. It is used in DC motor speed control, Brightness control of LED lamps etc.

Here in this simple experiment to understand the PWM working in ARDUINO, we read an analog input pin, maps the result to set the pulsewidth modulation (PWM) of an output pin. The input read from the analog pins will be in the range 0 to 1023. But the PWM fuction has a the width parameter ranging from 0 to 255, where 0 indicates fully off, and 255 indicates fully on pulses.

PWM using Arduino diagram

For better understanding and easy debugging, printing the results to the serial monitor is always performed.
map() is used to convert the the values ranging from 0-1023 to 0-255, which simplify the code and reduce the mathematical operations.

Circuit Diagram

PWM using Arduino Circuit Diagram

  • Potentiometer connected to Analog Pin 0
  • LED connected from digital pin 9 to ground


const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:

Read more: Pulse Width Modulation : PWM using Arduino

Leave a Comment

Your email address will not be published. Required fields are marked *