This tutorial explains how to take analog output from Arduino Nano. One of the basic tutorials for Arduino Nano. The output is taken on a LED that fades in and fades out.
1. Introduction:
A step by step illustrated very basic tutorial for Arduino Nano. Here we are taking analog output on a LED. This LED gets fade in and then fade out.
Arduino Nano 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 Nano Boards have 6 PWM(Analog Pins) like Arduino UNO these are PIN No. 3,5,6,9,10,11.
S.No. | Item | Quantity |
1. | Arduino Nano | 1 |
2. | Mini USB Cable | 1 |
3. | Breadboard | 1 |
4. | LED | 1 |
5. | Resistor 220 Ohm | 1 |
6. | Male to Male Jumper Wires | 2 |
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.
int led = 3; // the PWM pin the LED is attached to int brightness = 0; // how bright the LED is int fadeAmount = 5; // how many points to fade the LED by void setup() { pinMode(led, OUTPUT); } void loop() { analogWrite(led, brightness); // change the brightness for next time through the loop: brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 255) { fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30); }
4. Output:
The execution makes fade out effects on the LED. To vary speed of fade in and out effect try changing delay.
5. Troubleshooting:
LED is not glowing: Try changing polarity of LED, Pull it out rotate it by 180 degree and insert its again.
If still not working pull the led out and test it may be defective
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com