Control an LED with PWM output
Control an LED with PWM output

As you may have noticed in the Arduino board (Uno, Mega-etc.) Are present some PIN that have next a symbol like a wave.

This symbol indicates that the output can also be used in "PWM" or "Pulse-width modulation".
Using this function, it is possible to vary, for example, the frequency of switching on and off of an LED.

Step 1: The circuit

Control an LED with PWM output

First we need to:

- Arduino Uno

- A resistor 220Ohm

- A LED

- Breadboard

- Wires for links

Mounted the circuit as described in the picture

Step 2: The sketch

Control an LED with PWM output

// Created by //

// Alessio Bigini 2015 //

// http://alessiobigini.it //

int lum = 0;

void setup()

{

pinMode(9, OUTPUT);

}

void loop()

{

for (lum = 0; lum < 255; lum++ )

{

analogWrite(9, lum);

delay(10);

}

for (lum = 255; lum > 0; lum-- )

{

analogWrite(9, lum);

delay(10);

}

}

Now load the sketch into your board

In this code I used two simple For loops that allow me to increase the variable "Lum" from 0 to 255 and then decrease it.

Control an LED with PWM output
Uscita_PWM.ino527 bytes

Step 3: The video

For more information visit:

http://alessiobigini.it/

http://alessiobigini.it/2015/02/06/arduino-pwm/

 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel