Introduction: Using PWM to Control the Light Intensity of a LED


Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a technique used to encode a message into a pulsing signal. It is a type of modulation. Although this modulation technique can be used to encode information for transmission, its main use is to allow the control of the power supplied to electrical devices, especially to inertial loads such as motors.

The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast rate. The longer the switch is on compared to the off periods, the higher the total power supplied to the load.

However note the PWM switching frequency has to be much higher than what would affect the load (the device that uses the power), which is to say that the resultant waveform perceived by the load must be as smooth as possible.

The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on. So fro an arduino if the duty cycle is 50% it means supplying 0.5*5V=2.5V.

The arduino can also provide a PWM output however all the pins cannot be used for providing a PWM output the pins numbers preceded with a tilde(' ~ ') can be used for PWM. In an Arduino UNO there are a total of 6 such pins 11,10,9,6,5,3. We use pin in our project.









A potentiometer measuring instrument is essentially a voltage divider used for measuringelectric potential (voltage); the component is an implementation of the same principle, hence its name.

For connecting the potentiometer node A is connected to 5V of the arduino node B is connected to GND and W the wiper is connected to Analog input A0. The arduino provides a potential difference of 5 V for current to flow. the wiper acts as the potential divider and the current is measured which flows through the wiper.


The cathode is connected to the GND and anode is connected to pin 9 through the 1k ohm resistor of the arduino which provides a PWM output. .

Step 2: Program

I have use the analogRead to read in the value of the potentiometer.Since the ADC of arduino has a resolution of 10 bits these range from 0 to 1023.In my project i found that my analog read input ranged from 116 to 924 . so i mapped the values from 0 to 255 using the function x=map(x,100,1000,0,255). Then i provided this as the output to my LED.