Jul 062014

Motorcycle (automobile) tail lights with leds and PWM


It is trendy to use leds wherever. On automobiles, but especially on motorbikes, where power is of the essence, going down from 10W (or 32W with break lights on) to ~1W is very important.

I did this for a friend who owns a Yamaha Venture:


This is how the tail light looks like on this bike:


1. Survey

I have measured the inside of the tail light and I came out with this:

Tail Lights Survey: the thicker border defines the PCB where the leds will be mounted.

The tail lights are also used to light up the license plate. So, two sets of leds should be used: red ones for the position and break lights, and white ones for the license plate lights.

All of these leds should be protected from an possible over voltage coming from the bike.

The schematic looks like this:

White lights are powered directly from the regulator while the red one will be linked to the PWM generator

The final PCB looks like this:

PCB with leds and 12 volts regulator

2. PWM generator

I have decided to build a digital PWM generator instead of a linear one, powered by a LM555.

The reasons were the following:

– LM555 works to a voltage up to 16V. A short voltage spike could easily ruin it;

– There is a need to make adjustments to the position intensity and memorize it somewhere.

– Micro-controllers work at 5V and they are protected easier than a LM555;

– they have almost the same price.

I have decided to use an ATtiny25/45/85 for this project, along with SMD components, in order to have a small PCB for the controller.

The schematic:

Power Stage

Micro-controller stage. Notice the Stop signal voltage being divided with resistors

Keyboard and ISP header

Power Stage


 The mosfet is able to drive up to 500 leds, connected in parallel rows of 4-5 leds, depending on their voltage, directly from 12V.

The keyboard is not a regular keyboard, but merely contacts on the PCB, which allow for an easy setup of the positions intensity. Shorting the “UP” or “DOWN” keys will increase, respectively decrease the PWM duty of the leds, while also memorizing the value into EEprom. This value will be loaded and used the next time the motorcycle will be powered.

3. The software

The software works if your MCU runs at 8 MHz, using the internal RC oscillator, not divided by 8.

Fuses setup

The program is written in C and compiled using Atmel Studio 6.1:

#include <stdlib.h>
#include <avr/io.h>
#include <avr/eeprom.h>
#define F_CPU 80000000
#include <util/delay.h>

uint8_t EEMEM EPositionValue=10;
uint8_t Def_PositionValue=10;

uint8_t PositionValue=10;
uint8_t StopValue=100;

//keys definition
#define UP        1
#define DOWN     2
#define STOP     4
#define KPIN  PINB

void init(void)
//timer0 setup
    TCCR0A = 
    1 << COM0A1 | // normal port operation, PWM disabled 
    0 << COM0A0 |
    0 << COM0B1 | // not inverted 
    0 << COM0B0 |
    1 << WGM00  | // fast pwm 8 bit
    1 << WGM01  ; // fast pwm 8 bit

    TCCR0B = 
    0 << WGM02 |
    0 << CS00  | // prescaler /8 = 250 Hz PWM 
    0 << CS01  |
    1 << CS02  ;

    DDRB  =_BV(0)|_BV(1)|_BV(2)|_BV(3);        //bits 0-3 of PORTB are defined as outputs
    PORTB =_BV(0)|_BV(1)|_BV(2)|_BV(3);        //bits 4-5 of PORTB are defined as inputs
    PositionValue= eeprom_read_byte(&EPositionValue);
    if (PositionValue==0xFF)                //not programmed EEPROM
        eeprom_write_byte(&EPositionValue, Def_PositionValue);

void setduty( uint8_t duty) 

void readkeys(void)
    //LEFT AND RIGHT keys

    //UP key
    if bit_is_set(KPIN, STOP)
    if bit_is_clear(KPIN, UP)
        if (PositionValue>100) PositionValue=100;
        eeprom_write_byte(&EPositionValue, PositionValue);
    if bit_is_clear(KPIN, DOWN)
        if (PositionValue<1) PositionValue=1;
        eeprom_write_byte(&EPositionValue, PositionValue);
    else    setduty(PositionValue);

void inittest()
    uint8_t i,j;
int main()


Jun 302014

Timer for Ultraviolet exposure with UV LEDs and PWM fine tuning

Timer operation video

Timer measurement video

Previous timer projects had only on/off possibilities for the UV leds. Some projects need a finer tuning of the UV value, and I am not talking just about PCBs. Stamps and other things need ultraviolet curing, with setups that cannot be fulfilled using the basic, previous design.

Based on the same hardware as the Common Cathode timer available in this post, I have further developed the software in order to use the same hardware to achieve finer results.

This is how it works:

 1. Countdown timer setup mode

When powered, the display shows in minutes and seconds a predefined value of 5:00 (five minutes, zero seconds). The display is blinking and the second dot point is lit, showing that it is in countdown timer setup mode.

This value may be modified using the left and right keys (to decrease or to increase the timer). The steps are measured in seconds. The maximum value that can be programmed is 99 minutes and 59 seconds, just as much as the display can hold with just 4 digits.

The UV leds and the blue witness led are shut off.

Pressing the GO key will enter in countdown timer mode.

2. PWM setup mode

GO and RIGHT keys pressed simultaneously switch the countdown value to the PWM value, expressed in percents (from 0% to 100%).

The default value is 100 (%).

The display is blinking and the fourth dot point is lit, showing that it is in PWM value setup mode.

This value may be modified using the left and right keys (to decrease or to increase the PWM value). The steps are measured in percents. The maximum value that can be programmed is 100%.

The UV leds and the blue witness led are lit at the value defined by the PWM value.

To switch back to displaying the countdown timer, press GO and LEFT keys simultaneously.

Pressing the GO key will enter in countdown timer mode.

3. Countdown Timer mode

Pressing the GO key while in either setup mode (countdown timer, PWM) or in power save mode will enter in countdown timer mode.

The display is steady (does not blink), the second dot point is lit and it shows the minutes and seconds as they go down to zero. The display is reverted to minutes and seconds, no matter which was the mode when the GO key was pressed.

The UV leds and the witness blue led are lit at the defined PWM value;

At the end of the countdown, the UV lights are shut off, the device enters timer countdown setup mode and emits 10 beeps to let the user know it has terminated its timing job.

During Countdown timer mode, the power save mode is disabled and keys functions are also disabled. Upon reaching zero, keys functions are enabled again and power save mode enters automatically in effect after ~ 10 seconds.

4. Power save mode

To save power and to allow the 78L05 regulator to cool down after counting down, the display is shut off after 10 seconds and just the dot point remains blinking. Power save mode works no matter if you are in timer setup mode or in PWM setup mode.

5. Memorizing other values as default values

LEFT and RIGHT keys pressed simultaneously will write in EEPROM both the timer countdown value and the PWM value. set up by the user. At the next power-up, these will be the values used by default for countdown and PWM. After writing these values in EEPROM, the device emits 4 beeps.

6. Other considerations
I can assure you the 78L05 will function very well over time. However, if you feel any doubt, replace it with an 7805 and a small aluminum heat sink.

Any key will do exactly as intended and, if pressed, will disable the power down mode.

During power down, a beep is emitted every ~10 seconds to let the user know the device is waiting, asleep.

The code is written in C and compiles under AVR Studio 4.

The fuses for ATtiny2313 are set as follows:

SELFPREGEN - disabled
DWEN       - disabled
EESAVE     - disabled
SPIEN      - enabled
WDTON      - disabled
BODLEVEL   - brown-out detection disabled
RSTDISBL   - disabled
CKDIV8     - disabled
CKOUT      - disabled
SUT_CKSEL  - Internal RC Oscillator 8MHz; Start-up time: 14CK + 65 ms


Common Cathode Display Version: HEX and EEP compiled files enabling you to have a full featured timer, can be found here.

Common Anode Display Version: HEX and EEP compiled files enabling you to have a full featured timer, can be found here.


The complete source code for either CC version or CA version can be emailed to those interested in obtaining it. The cost is 10 EUR, payable by paypal, to Cristian Copcea, email copcea at yahoo dot com

Both (CC and CA versions) will be emailed for 15 EUR.

These funds will contribute to acquiring parts, equipment and all other necessary stuff (TIME being the most expensive) to create more interesting devices to be posted in this blog.


Make the transaction specifying “UV Timer with PWM source code”, send me an email about this and you will receive in return shortly an email from me with the desired source code(s) attached to the email in a .rar archive.


Switch to mobile version
Advertisment ad adsense adlogger