Menu Close

Arduino Analog Output – LED fade in and fade out.

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.

S.No.ItemQuantity
1 Arduino UNO 1
2 Breadboard 1
3 LED 1
4 Resistor 1k 1
5 Jumper 4

2. Building Circuit

Schematic Diagram:

Circuit Layout:

3. 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);     
    }


                           
}


4. output:

Here is the output of this tutorial-


If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply