Programmable IC for leds

Discussion in 'The Projects Forum' started by c.marsh, May 15, 2013.

  1. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    Hi everyone,

    I'm a little new to this sort of stuff so please bare with me.

    I have an arduino Uno board and software and I have a little experience with programming on that.

    I spend my hobby time doing scale models of various sci fi and motorcycle based stuff. Usually I use hardware like 555 timer chips to control lighting and so on, but I'm starting a new project, a 1/6 scale motorcycle which I would really like to have all the lights working on it.

    So I was thinking of a tiny circuit with an IC at its heart controlling the lighting in cycles,

    for example:

    Power on
    Head light comes on dipped beam
    rear light comes on
    <time lapse 2 minutes>
    left indicators turn on <time on 15 seconds>
    rear brake turns on for 1 second, off for 2 seconds on for 1 second
    Left indicators turn off
    <time lapse 2 minutes>
    right indicators turn on <time lapse 15 seconds>
    rear brake turns on for 1 second, off for 2 seconds on for 1 second
    right indicators turn off
    <time lapse 2 minutes>
    headlight turns to high beam
    <Time lapse 2 minutes>
    headlight turns to dipped beam
    <Return to beginning of program and loop until turned off?

    Now I can do with real easy on the arduino as I have some code put together for control star trek federation star ships lighting and its pretty universal for this kind of lighting projects.

    The thing is, the arduino is complete and utter overkill for this kind of thing and far to big to go inside a 1/6 scale motorcycle tank/engine casings.

    So I was wondering if anyone knows of an IC/microchip that I can program using the arduino sketch to control the lights?

    i guess it would need the following channels:

    1 - headlight dipped beam
    2 - headlight full beam
    3 - rear light
    4 - rear brake
    5 - left indicators
    6 - right indicators

    As i said, im new to programmable IC's and any help would be greatly appreciated.

    Oh, I'd also like to keep the power requirements to a minimum, I can run 2 power wires INTO the motorcycle and have a battery source external from the bike.
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Just use whatever chip your arduino uses standalone and put the code inside it? you don´t need the whole board, but you do need to program the chip, for example using ponyprog, or right inside the arduino if it is a dip package chip.
    Or do that small step and learn progamming AVRs and put the program in any avr that suits your needs.
     
    c.marsh likes this.
  3. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    The arduino chip is atmega328p-pu but is a bit big really

    Is there a smaller variant?

    when you say program the chip, what do you mean? I know it needs the code to run the lights but what sort of code to get the chip to run that code?
     
  4. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I am not too familiar with arduino, but basically the arduino environment creates a binary file that you can load into the chip. With the arduino the original chip has a pre-loaded part that allows you to easily upload your code.
    A chip that you buy from a shop will not contain this and you need other means of loading the code - a programmer, but these can be quite easy to make.
    But really if you require to a smaller chip the easiest way to do it is to write the code straight in C and then program the chip, without using the arduino libraries.

    First you should start with deciding how many pins you need to controle the LEDs and then go to atmel.com and choos a suitable chip. They even send free samples for some of them.
     
    c.marsh likes this.
  5. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    Okay well i need 6 channels + power input.

    I will look on amtel and see if I can work out which is suitable and post here for confirmation :)

    Thanks for the help, im sure i'll be back for oppinions on the best interface device to use and help on getting the enviroment programming working.
     
  6. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
  7. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    @c.marsh

    What type of leds are going to be used? What is their power or current rating? What is the dimensions of the engine case cavity that is going to hold the driver? Would something like 17mm dia. by 10mm high work?

    A bare ATtiny25 can be had in a small skinny SOIC pkg., and has four PWM registers that should handle the situation. This would assume a single led for headlight and tail light. Don't konw if it has an been ported to Arduino or not. Also, I think Dimension Engr. makes a blinky kit for the RC folks that is user programmable.
     
    c.marsh likes this.
  8. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
  9. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    SMD is fine,

    The actual led lights are SMD anyway.

    I'll be making the PCB myself using photoresist hopefully, otherwise i'll get a pcb made up by a company.

    I'll take a look at the tutorial in a little while as im writing up an arduino sketch just to see how things will run with what i have in mine.
     
  10. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    Sorry I missed your post,

    The leds will be smd style, the headlight and rear light will have 2 smd led each, the dimensions sound good as a 1/6 tank or engine casings should have a good amount of space in them.
     
  11. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    SMD could mean 2ma to 3A or more, which is the reason I asked about the current rating. I have already developed a small (16mm) four channel, high power (350-1000ma), constant current LED driver. You could consider it a slave board to the Arduino or ATtiny, PIC etc. LED's need to be at minimum 1W though, and would be dimmed by PWM from the micro.

    [​IMG]
     
    c.marsh likes this.
  12. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    white 3.8v 20ma
    red 2.2v 20ma
    orange 2.2v 20 ma if that helps?
     
  13. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    O.K. those can be directly driven from the microcontroller pins with the appropriate current limiting resistors. Just watch that you don't go over the overall package limitation which is typically around 200ma. If you get in a pinch, then you can use shift register chip like the 74HC595. My solution is wayyyyy overboard, unless you want BRIGHT.
     
    c.marsh likes this.
  14. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    there is only 180ma draw at peak, so just fits into the typical limitation it seems :D

    Now i just need to work out which chip exactly to use and try to get it setup and write the light code in C.

    I wrote the code in arduino just as a test bed for timings and patterns, looks okay as a motorcycle light system.
     
  15. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    Code ( (Unknown Language)):
    1. // Motorcycle Prototype Mk1
    2.  
    3. #include <LedFader.h>
    4. #include <LedFlasher.h>
    5.  
    6. // pin assignments PMW 3,5,6,9,10,11
    7. const byte DippedPin = 1;          //
    8. const byte HighPin = 2;            //
    9. const byte RightIndicatorPin = 3;  //
    10. const byte LeftIndicatorPin = 4;   //
    11. const byte RearLightPin = 5;       //
    12. const byte RearBrakePin = 6;       //
    13.  
    14.  
    15. // Flashers                     pin                  off-time  on-time       on?
    16. LedFlasher LeftIndicator    (LeftIndicatorPin,        500,       500,     false);
    17. LedFlasher RightIndicator   (RightIndicatorPin,       500,       500,     false);
    18. LedFlasher RearBrake        (RearBrakePin,            700,       2000,     false);
    19.  
    20. // states for the state machine
    21. typedef enum
    22.   {
    23.   initialState,
    24.   wantDippedBeam,
    25.   wantHighBeam,  
    26.   wantHighBeamOff,
    27.   wantLeftIndicator,            
    28.   wantRightIndicator,
    29.   wantLeftIndicatorOff,
    30.   wantRightIndicatorOff,
    31.   wantRearLight,
    32.   wantRearBrake,
    33.   wantRearBrake2,
    34.   wantRearBrakeOff,
    35.   wantRearBrakeOff2,  
    36.   } states;
    37.  
    38. // state machine variables
    39. states state = initialState;
    40. unsigned long lastStateChange = 0;
    41. unsigned long timeInThisState = 1000;
    42.  
    43. void setup ()
    44.   {
    45.   pinMode (DippedPin, OUTPUT);
    46.   pinMode (HighPin, OUTPUT);
    47.   pinMode (RearLightPin, OUTPUT);
    48.    
    49.   // set up faders, flashers  
    50.   LeftIndicator.begin ();
    51.   RightIndicator.begin ();
    52.   RearBrake.begin ();
    53.   }  // end of setup
    54.        
    55. void doStateChange ()
    56.   {
    57.   lastStateChange = millis ();    // when we last changed states
    58.   timeInThisState = 1000;         // default one second between states
    59.  
    60.   switch (state)
    61.    {
    62.     case initialState:
    63.          state = wantDippedBeam;
    64.          break;
    65.          
    66.     case wantDippedBeam:
    67.          digitalWrite (DippedPin, HIGH);
    68.          state = wantRearLight;
    69.          break;
    70.          
    71.     case wantRearLight:
    72.          digitalWrite (RearLightPin, HIGH);
    73.          state = wantRearBrake;
    74.          timeInThisState = 20000;
    75.          break;
    76. //left Indicators/brake Lights
    77.     case wantRearBrake:
    78.          RearBrake.on();
    79.          state = wantLeftIndicator;
    80.          break;
    81.          
    82.     case wantLeftIndicator:
    83.          LeftIndicator.on();
    84.          state = wantRearBrakeOff;
    85.          timeInThisState = 5000;
    86.          break;
    87.          
    88.     case wantRearBrakeOff:
    89.          RearBrake.off();
    90.          state = wantLeftIndicatorOff;
    91.          break;
    92.    
    93.     case wantLeftIndicatorOff:
    94.          LeftIndicator.off();
    95.          state = wantHighBeam;
    96.          timeInThisState = 20000;
    97.          break;
    98.          
    99.     case wantHighBeam:
    100.          digitalWrite (HighPin, HIGH);
    101.          state = wantRearBrake2;
    102.          break;
    103.          
    104.     case wantRearBrake2:
    105.          RearBrake.on();
    106.          state = wantRightIndicator;
    107.          break;
    108.          
    109.     case wantRightIndicator:
    110.          RightIndicator.on();
    111.          state = wantRearBrakeOff2;
    112.          timeInThisState = 5000;
    113.          break;
    114.          
    115.     case wantRearBrakeOff2:
    116.          RearBrake.off();
    117.          state = wantRightIndicatorOff;
    118.          break;
    119.          
    120.     case wantRightIndicatorOff:
    121.          RightIndicator.off();
    122.          state = wantHighBeamOff;
    123.          timeInThisState = 20000;
    124.          break;
    125.          
    126.     case wantHighBeamOff:
    127.          digitalWrite (HighPin, LOW);
    128.          state = wantDippedBeam;
    129.          break;
    130.                
    131.     }  // end of switch on state
    132.   }  // end of doStateChange
    133.  
    134.  
    135. void loop ()
    136.   {
    137.    if (millis () - lastStateChange >= timeInThisState)
    138.      doStateChange ();
    139.    // update faders, flashers
    140.    RearBrake.update ();
    141.    LeftIndicator.update ();
    142.    RightIndicator.update ();
    143.  
    144.   }  // end of loop
    thats the arduino code. is it of any use on a stand alone chip?
     
  16. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I guess you can reuse the whole code, you will then just need to change a few bits and pieces to replace the arduino main.
     
    c.marsh likes this.
  17. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
  18. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    I didn´t know arduino had this capability to program other chip through the main board, so yes I think that if you follow that instructable it should work nice. Also you can check is the arduino supports more than just those two attiny chips.
     
    c.marsh likes this.
  19. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    yeah i downloaded a file for other chips, i just need to select one of the supported chips that meets the power requirements, pinout requirements and of course size requirements.

    So far im sitting on the ATtiny24 which is a 14 pin 12i/o chip. theres some additional downloading and setup for that chip but seems a good choice to go with.
     
  20. c.marsh

    Thread Starter Active Member

    May 16, 2009
    100
    0
    decided on the at85 chip and odering one soon.

    hopefully there wont be any problems and i can report back in a few days with a video of it working away.
     
    Last edited: May 15, 2013
Loading...