• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomeArduinoIntroductory Kit with Clear Case for ArduinoExperiment 5 Control LED Breathing Light Using PWM
Previous Next

Experiment 5 Control LED Breathing Light Using PWM

Posted by: Alvin Jin , February 17, 2014

[vc_row][vc_column width=”1/1″][vc_column_text]The components used in this experiment are shown below:

QQ截图20140217132537

The components are one LED, one 470 ohm resistor,2 jumper wires and one breadboard.

Schematics:

QQ截图20140217133028

QQ截图20140217133137

The long pin of LED is positive ,and the short pin is negative.

Wiring Diagram:

QQ截图20140217133452

The positive pin of LED is wired to digital pin 9 of Arduino, the negative pin of LED is wired to a resister and then to the GND of the Arduino.

Arduino code:
/*
This experiment shows how to gradually change the brightness of LED
which is connected to digital pin 9 using analogWrite() command.
*/
//Define a variable brightness, which is used to represent the
brightness of the LED
int brightness = 0;
int fadeAmount = 5; //Define a variable fadeAmount, which is used to
represent the change amount of the brightness
void setup() {
pinMode(9, OUTPUT);// Set the mode of digital pin 9 to be OUTPUT
}
void loop() {
//Write the value of brightness to digital pin 9
analogWrite(9, brightness);
//Update the value of brightness to be used for next cycle
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
//Change the sign of the fadeAmount at the largest and smallest
brightness points
fadeAmount = -fadeAmount ;
}
delay(30); //delay 30ms
}[/vc_column_text][/vc_column][/vc_row]

Tags: Introductory Kit with Clear Case for Arduino

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors