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

Picture of Using PWM to Control the Light Intensity of a LED

INTRODUCTION

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.

THINGS REQUIRED

1.ARDUINO UNO

2.POTENTIOMETER (20k)

3.LEDs

4.JUMPER WIRES

5.RESISTOR (1K)

Step 1: HOW TO CONNECT

Picture of HOW TO CONNECT

POTENTIOMETER

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.

LED

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

Picture of 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.

Comments

NavyathaH (author)2016-09-29

hello,

I need to do the same using sharp IR sensor. That is, the intensity has to decrease as the object approaches the sensor.

kindly help me with the code

DBGustavson (author)2016-09-26

The circuit diagram in step 1 doesn't match the discussion. It shows one way a meter (MTR) could be used to measure voltage, using the pot to calibrate the meter. For this discussion, the pot should be connected between +5v and ground 0v, with the tap (wiper) going to the analog input of the Arduino. The diagram confuses the issue. It could also be interpreted as a torque control for a MoToR, varying the current using a series resistance, but this type of pot doesn't normally handle enough current to be used that way. It would be better without this diagram present.

NYT1 (author)2016-08-15

Hello, how can this be applied to eliminate the "pulsing" or "flickering" of LED lighting on a motor vehicle (12V DC), caused by the pulse electrical signals sent to the LED's? I have 0 (zero) knowledge of these topics, but need to make modifications to accommodate LED driving lights added to a motorcycle. The lights flicker or strobe at anything higher than idle speed. I am told this will shorten the lifespan of the LED's, and I would prefer to fix the problem rather than replace the lights at frequent intervals. Thank You.

About This Instructable

21,996views

27favorites

License:

More by himshekhar.das:DIY Keypad matrix  from the principle of operation to implementationUsing PWM to control the light intensity of a LEDTo build a voltage regulator and  measure AC voltage using arduino
Add instructable to: