This is the introduction of PWM (Pulse Width Modulation) concept in Arduino Uno. Here we have used the PWM method to vary the brightness of a 1 Watt LED.

All the header files and registers are predefined by ARDUINO IDE, we simple have to call them and that’s it we will have a PWM output at appropriate pin.

 

Now for getting a PWM output at a appropriate pin, we need to work on two things,

1. pinMode(ledPin, OUTPUT)

  1. analogWrite(pin, value)

First we need to choose the PWM output pin from six pins, after that we need to set that pin as output.

Next we need to enable the PWM feature of UNO by calling the function “analogWrite(pin, value)” . In here ‘pin’ represent the pin number where we need PWM output we are putting it as ‘3’. So at PIN3 we are getting PWM output.

Value is the turn ON duty cycle, between 0 (always off) and 255 (always on). We are going to increment and decrement this number by button press.

See the source code to understand the working.
{"cc_re__cc_re__cc_by_sa_3_0": ["   \n                <a href=\"/projects/by-tag/arduino/\">arduino</a>, \n                \n                <a href=\"/projects/by-tag/arduino%20uno/\">arduino uno</a>, \n                \n                <a href=\"/projects/by-tag/pwm/\">pwm</a>, \n                \n                <a href=\"/projects/by-tag/led/\">led</a>\n                \n            </p>\n        \n        \n        \n            <p><small>last updated 3 years, 11 months ago</small></p>\n        \n        \n            <p class=\"license\">\n        <a target=\"_blank\" href=\"https://creativecommons.org/licenses/by-sa/3.0/\" alt=\"Creative Commons Attribution-Share Alike 3.0 Unported License\">\n        <img src=\"https://i.creativecommons.org/l/by-sa/3.0/80x15.png\" alt=\"Creative Commons Attribution-Share Alike 3.0 Unported License\" title=\"Creative Commons Attribution-Share Alike 3.0 Unported License\" />\n        </a>\n        </p>\n        \n        \n        \n    </section>\n\n    <section class=\"fab\">\n        <h3><a class=\"button popup-fab\" href='/projects/led-dimmer-using-arduino-uno/fab/'>Fabricate this..</a></h3>\n    </section>\n\n    \n    <section class=\"highlight\">\n        <h3>Downloads<"]}