This tutorial explains how to take analog output from Arduino. One of the basic tutorials for Arduino. The output is taken on a LED that fades in and fades out. The video of output is also included.
1. Introduction:
A step by step illustrated very basic tutorial for Arduino. Here we are taking analog output on a LED. This LED gets fade in and then fade out.
Arduino gives analog output in range of 0 to 255. Technically the output is digital but in the form of PWM, but it seems to be analog.
Arduino Boards have 6 PWM(Analog Pins) these are PIN No. 3,5,6,9,10,11.
This tutorial is made on Original Arduino UNO and Robo India’s R-Board(UNO compatible.)
2. Required Hardware
Following Hardware will be required to perform this LED fade in and fade out circuit.
S.No. | Item | Quantity |
1. | R-Board with FTDI or Arduino Board | 1 |
2. | Bread Board | 1 |
3. | Male to male Jumpers | 4 |
4. | Indicator LED | 1 |
5. | 100 OHM Resistance | 1 |
3. Building Circuit
Make following circuit with the help of above mentioned components.
3.1 You may go with Robo India’s R-Board ( UNO Compatible)-
Here is the schematic of this circuit-
or
3.2 You may go with original Arduino UNO Board-
Here is the schematic of this circuit-
4. Programming:
Once we are done with circuit part, here is our programme to this circuit.
You may download this code (Arduino Sketch) from here.
/* Tutorial for Analog Output. Analog output is taken through PWM. Prepared by Robo India. www.roboindia.com */ int LED_ao = 3; // The LED attached to Pin 3 for analog output. void setup() { pinMode(LED_ao, OUTPUT); // Declaring Pin as output. } void loop() { // Range of PWM is 0 to 255. So we are running FOR LOOP for 1 to 255. for (int brightness=1; brightness<=255; brightness++) // For loop for Fade In effect. { analogWrite(LED_ao, brightness); // LED will glow for value of 1 to 255. delay(20); // Small delay to see fade effect. } for (int brightness=255; brightness>0; brightness--) // Same FOR LOOP for Fade out effect. { analogWrite(LED_ao, brightness); delay(20); } }
5. output:
Here is the output of this tutorial-
6. You may Download Arduino Code (Sketch) of exercise-2 shown in above video.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
http://roboindia.com