Monday 3 November 2014

ATTiny85 – Tutorial 5 – Dimming LED using PWM

This tutorial is a very simple conversion from ATMEGA328P to ATTiny85, there is only one pin involved in producing output, so we only need to change from pin 11 to pin 0. On the ATTiny85, there are three hardware PWM pins … pin 0, pin 1 and pin2 , so it’s simply a matter of switching over to Pin 0 and away we go.

ATTiny85 - Lesson 5 - Dimming LED with PWM

I’ve changed the sketch for personal taste (and I think, efficiency), you’re free to use the Freetronics version of the code if you like … it’s no great shakes on something this small.

/* project 5: Controlling LED brightness with PWM */

int led = 0;
int brightness = 0;
int delayTime = 10;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  while (brightness < 255)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness++;
  }
  while (brightness > 0)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness--;
  }
}

As you will see from the following image, there isn’t much to the wiring for this project.

Tutorial5

And here’s the circuit running through it’s light/dim wizardry.

Tutorial 5 – ATTiny85 - Dimming LED with PWM

Once again, I’m using my ATTiny85 ICSP to program the ATTiny85 using the Arduino UNO and my 9V to 5V power regulator to supply 5V to the circuit.

Check out the rest of the tutorials here.

No comments:

Post a Comment

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.