In this project we make a pulsating LED by adjusting the brightness. The LED pulsates on and off. The brightness changes by PWM. The PWM is a made by the software instead of hardware. The circuit is simply a LED connected to pin0 of PORTB and ground via a current limiting resistor.

Because it is a software PWM, the LED can be connected to any pin. The circuit can be build with the ATMega328 board and a breadboard. The ATMega328 board can be purchased at www.bizztronix.eu. A hyperflux LED is used, this LED draws 20mA current and is very bright. 
Get a piece of paper of about A6 size (10cm by 15cm), roll it into a cylinder, then glue the edges together so it remains that way. Then place the cylinder over the top of the LED. This will diffuse the light from the LED.

Software Code

The code is simple. It is made with WINAvr C-compiler.

// program name: PWM LED
// date: 08.04.2015
// target device: ATMega328
// purpose: software PWM PORTB.0
// author: www.avrprojects.net
// hardware: LED on PORTB.0

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL


// globals
volatile unsigned char e ;
volatile unsigned char pwm;

void abc(unsigned char a,unsigned char status)
{
if ((status==a))
{
PORTB&= ~(1<<0);
}
}


//overflow isr timer0
ISR(TIMER0_OVF_vect)
{
if (e==255)
{e=0;
PORTB |= (1<<0);
}

abc(pwm,e);
e++;
}


// main program
int main (void)
{

DDRB = 0xFF;

//Timer Initialisation
TCCR0A = 0x00;
TCCR0B = 0x01;//No Prescaling
TIMSK0=0x01;// unmask Timer 0 overflow interrupt
sei();//Global Interrupts Enabled


while(1)
{
for (int x=1; x<255; x++)
{
pwm=x;
_delay_ms(5);
}
for (int x=255; x>1; x--)
{
pwm=x;
_delay_ms(5);
}
}
}

 

Video