Complete newbie, trying to create a sequential LED switch in a very small space

Discussion in 'General Electronics Chat' started by Koppo, Sep 26, 2014.

  1. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    Hi, I'm a complete newbie to electronics. Put it this way, I've figured out which end of the soldering iron not to hold but thats about it. I know almost nothing at this point.

    I do however know what I'd like to do.

    I wish to create a way of sequentially turning off 5 LEDs with a single button. The problem is I have a very small footprint for this. Specifically this is a 40mm round model wargaming base like this (middel top row):
    [​IMG]

    40mm refers to the outside dimension, the inside dimension is about 38mm. The internal heigh is about 4mm.

    I'd like to have something where flicking a switch turns the unit on with all 5 leds lit, while pressing a button/turning a wheel/other control turns one LED off per press/click until there are none on, the next press returning all 5 to on.

    The LEDs would be mounted on/visible on the beveled edge of the base, nothing can be visible on the top of the base.

    Extensions to this project would be to have up to 8 LEDs and options to mount in a 60mm round base and a lower LED count in the 25mm base.

    Like I said I know very little as to how to do this. I know I'll have to use a slimline watch type battery but other than that I don't know. I'd like to make about 50-100 of these so cost is also a factor.

    Thanks for your time.
     
  2. wayneh

    Expert

    Sep 9, 2010
    12,145
    3,056
    I'm not 100% sure, but that nearly requires you to go surface mount instead of thru-hole. For a beginner, that's a step up in difficulty. You MIGHT be able to do thru-hole in 4mm, but it will require care and planning. The other dimensions should be OK. Look for a round perfboard like this, but as wide as will fit.

    The circuit will use a counter and a de-bounced switch. Not hard. What kind of switch do you want, maybe a touchpad?

    You'll need a drawing program to carefully map the internal layout and the design of the PCB.
     
    Last edited: Sep 26, 2014
  3. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    Tru-hole vs surface mount? New terms to me (I'll google it). I'm not too fussy about the switch as long as it does not take up too much space.

    That perf board looks ideal! Now to find a uk supplier
     
  4. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    For a minimum component count (and price) I would use a small micro-controller. An 8-pin PIC will give you 6 I/O pins for your button and the five LEDs. Use a thin lithium coin cell for power. All surface mount. You could probably have a hole in the PCB that the coin cell will sit inside to reduce the overall height.

    When all the LEDs are off the PIC can go into a power-saving mode so no battery switch required.

    If you want to make 50 to 100 the cost of the PCB will be quite low. There are companies that will produce the PCB, source the components and solder to your design for a fixed price.
     
  5. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    If I can get them made up by a company at an accessible price then I'd do that. What would be the best of finding such a company (I'd prefer one in the Northwest UK)
     
  6. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    Google "Contract Electronics Manufacture" should come up with something.

    Another thought on the micro-controller: For battery saving, you could make all the LEDs go off if the button has not been pressed for some time.

    Regarding the design:-
    The actual circuit design is very simple. Battery, push button, PIC, 5 LEDs (are they all the same colour?), 5 resistors and 1 de-coupling capacitor.

    Then a mechanical design:-
    Overall size and shape. Packaging - how is it enclosed? That leads to a PCB layout. It's a very simple circuit so it could probably be single-sided on a thin board with no holes which will save money. Select components - create a list with costings.

    Then a software design:-
    Not very difficult for someone reasonably experienced in micro-controller programming (talk to me nicely). The chips will either be programmed before being soldered to the PCB or could be programmed after assembly if suitable connection pads are provided on the PCB. In this case a jig with spring-loaded pins would be made to connect the programmer. One advantage of this is that the software can be changed later if necessary.

    Might be a good idea to make a prototype first to test the design and software before committing yourself to manufacturing 100!
     
  7. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    Cheers,

    The LED colours will go Red, Yellow, Yellow, Yellow, Green and the sequence will go:
    Red, Yellow, Yellow, Yellow, Green
    Red, Yellow, Yellow, Yellow
    Red, Yellow, Yellow
    Red, Yellow
    Red
    NONE
    Red, Yellow, Yellow, Yellow, Green
    ...
    A timeout off for battery saving is unfortunately not a goer as they'll have to be constantly for around 2 hrs.

    To do the micro-controller programming what sort of kit do I need? Can I get it cheaply? I have some experience in desktop software coding and design but nothing in low level coding.


    So I suppose the circuit would be something like? In all honesty, the de-coupling capacitor thing has me stumped as to where it would go, but I guess the PIC will need power and a gnd (taking 2 of 8 pins), the push switch will attach to one pin and the 5 LEDs to the remaining 5 pins and will then need to go to gnd. Am I close?
    circuit.png
     
  8. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    Yes, your circuit is almost right. De-coupling capacitor across the micro-controller power supply pins. Connect the push button to the 0V rail as the input pin can be configured with an internal pull-up. This saves 1 resistor!

    Thinking that you do need to have a separate power switch. Tried to come up with a way to use the button as a shut-down control. For example press and hold the button for 5secs to shut down. Problem with the PIC is that it wakes up on input "change". So when you release the button it would immediately wake-up again. So, unless anyone can think of a better way, I have specified a power switch. Still thought good to have a power-off timer to save the battery if someone forgets to switch it off.

    I have attached a pdf with a circuit, flow-chart and possible parts-list. Have a look and see what you think. Correct: I haven't had much else going on today!

    You will need to "bread-board" a prototype first using leaded components to test and develop your software design. Develop your program using MPLAB (free download from Microchip). Use the Pickit 3 for programming.

    Of course, there is a lot more design work to do! A nice enclosure for the complete unit is a job in itself (Clear windows for the LEDs? How is the button going to work? How to replace the battery?). Then PCB design and software design. What I am saying here is that there is a lot of design work in even a simple electronics device. They don't just happen!

    Over to you now.
     
    adam555 likes this.
  9. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    Thanks. You have gone above and beyond on this, thank you.

    I'll source the bits and then learn how to code (there are loads of samples on line). If I get this working I'll post it up.
     
  10. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    I haven't given this much thought but could it not be done with something like a counter or a bar-graph driver and avoid the MCU?

    Also it might be worth considering "dead bug" construction - this is where you just solder the leads together without a board, which is an option with if you only have a few components. You can then encapsulate the whole thing to protect it.
     
  11. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    OK. First, build a prototype - just for playing around with and developing your code.
    Buy a piece of strip-board or a bread-board you can just plug everything into.
    Buy components with leads, not the surface-mount components in my list. For example:
    • PIC12F508 Farnell 1123006
    • Yellow LED Farnell 2112098
    • Red LED Farnell 2112100
    • Green LED Farnell 2112096
    Probably you can get most of this at Maplin.

    Use the same value resistor for all your LEDs to start with (220 ohm should do). You will find that some colours appear brighter than the others - especially the green - because our eyes are more sensitive to green. On your finished product you may have to experiment with the resistors so they all look the same. Another reason to build a prototype.

    Read carefully all the data-sheets for each component - very easy to damage things! Especially the PIC. If you look up the Farnell numbers, each item has a link to the data-sheet. Download and read.

    The micro-controller code will take some time and experimentation - especially if you have not done this before.

    Download and install MPLAB. For this very simple micro-controller project you will be programming in assembler. This chip only has about 9 bytes of RAM so the code needs to be efficient! So C is out of the question. In fact the shutdown timer needs 4 bytes and the button timer needs 2 bytes so there is not much left. But you probably will need only 1 other byte to store a couple of flags so plenty! The complete program will be very small: 20-30 instructions max. If I have time I will post some outline code to get you started.

    If you are a real newbie, you are jumping in at the deep end.
     
  12. wayneh

    Expert

    Sep 9, 2010
    12,145
    3,056
    +1
    A very challenging project for a newb.

    One small point; you might use a resistor array - multiple resistors in one package - to substitute for all those individual resistors on each LED, to reduce the parts count. The red LED may still need it's own, but that could add to the value provided by the array.

    If the PIC could do PWM on each output, you might not even need the resistors? Just thinking out loud.
     
  13. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,689
    2,751
    That's only 1/2 the battle. The other half is teaching your friends to hand you the iron handle first.

    100 years ago, back when I was in high school, I used to install car stereos for friends. In one case, my head was under the dash when I said to my friend, "Hand me the soldering iron."

    Great regrets.
     
  14. Eric007

    Senior Member

    Aug 5, 2011
    1,044
    33
    That's a very long time hey! how old are you now if I may ask? lol... I guess you just meant *Very long time ago* and you tired doing the exact math to figured out which year...:p
     
  15. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,689
    2,751
    My avatar looks like I feel...
     
    Eric007 and absf like this.
  16. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    OK, Koppo, an MPLAB project attached includes assembler code. Not tested. No deliberate errors, might be some accidental ones! There is an updated flow-chart in the archive as well.

    Hope I can attach a zip.

    The trouble with supplied software code is that you don't really learn how it works. So please look at it closely once you have read the PIC data-sheet.
     
  17. Bernard

    AAC Fanatic!

    Aug 7, 2008
    4,173
    397
    If you wanted a simple hardware approach to play with while learning code, try a parallel in, serial out shift register like 74165 or for more output, 25 mA, a HD74ACT165. With a push of a button, PB, parallel load all 1's, all LED's on; with de-bounced PB as clock serially load 0's . For each push a LED goes out.
     
  18. Koppo

    Thread Starter New Member

    Sep 26, 2014
    6
    0
    Bloody hell, I take a couple of days away and get 8 more replies and code to boot! Thanks everyone for your help, especially JDT. Now off to buy the bits.
     
Loading...