6
\$\begingroup\$

I want to design a very small project for a portable score keeper. It consists of using one microcontroller to control 4 sets/groups of LEDs on a small PCB. It is a very small scale project (3.5in X 1.5in). 2 of the 4 sets will consist of 4 LEDs each and the other 2 will consist of 7 LEDs each. Total of 22 LEDs but I will only need 4 LEDs to be on at one time. I would like to use push buttons to increment & decrement the score which will light up an LED. The LEDs will be labeled by score points. The smaller set will be the game score while the larger set will be the set score.

I was wondering if this was possible and how would I do this? is there a small enough microcontroller to be able to have have 8 push button inputs to manipulate 4 separate sets/groups of multiple LEDS?

I am planning to use plain 3V coin cell batteries for now but will look into small rechargeable power supplies. I have made a very simple dip-switch prototype using very tiny surface mount LEDs on a thin PCB with a coin cell battery. The dip-switch was bulky and took a lot of space. I would to slim it down and make it more sleek with less switches by implementing these ideas if they are possible.

Any words of advice and help will be appreciated. Thank you so much :D

\$\endgroup\$
0

2 Answers 2

4
\$\begingroup\$

Oli gave a good answer, but wait, mine will be better! :-)

Oli commented on the limited current from the coin cell, and that's indeed something to keep an eye on. This CR2430 cell gives 5 mA as maximum continuous. Let's see if we can manage that.

It's a good thing that you only need one LED on at a time, otherwise I would even consider the coin cell. This looks like a nice LED: typically 15 mcd at 2 mA.

Oli went for a SIPO (Serial-In, Parallel-Out) shift register for the LEDs and a PISO (Parallel-In, Serial Out) for the buttons. That saves you a lot of I/O but costs extra components. Can't we use the I/O of a microcontroller directly? 22 LEDs and 8 buttons is 30 I/Os, no problem, but we can do it a bit cheaper if we multiplex the LEDs in a 4 x 5 matrix. Normally this would decrease the LEDs luminosity by 75 %, but since we only have to light one LED at a time we can select one row and one column statically. So we need 4 + 5 + 8 = 17 I/Os.

Usual suspects for a microcontroller are Atmel AVR and Microchop PIC. Usually I'd avoid PIC for LED driving because it can't source or sink 20 mA, but we have a low LED current so no problem. PIC is also cheaper than AVR. The PIC16F57 has 20 I/Os, so that's enough. The datasheet says 22.5 µA maximum for a 32.768 kHz clock at 2 V, so at 3 V that still will be below 50 µA.

That's it. A microcontroller, a cheap crystal, 22 LEDs, 8 buttons, and 12 resistors (4 for the LEDs and 8 for the buttons. The PIC16F57 doesn't seem to have internal pull-ups). No shift registers needed.

\$\endgroup\$
3
  • \$\begingroup\$ Hehe, good answer - I went for the SR way to try and keep it simple, though I may have misjudged, not sure. I thought worrying about saving power and doing the multiplexing using the pins might make the firmware more daunting for a complete newbie, although probably just as likely to be confused by the shift registers :-) I'm leaning towards 1 pin per button/LED now (as mentioned in my second comment), which will still be easy space wise but as simple as possible with connections/firmware. \$\endgroup\$
    – Oli Glaser
    Commented Jul 18, 2012 at 10:44
  • \$\begingroup\$ @Oli - I think complexity of SR and mux are about the same for a beginner. \$\endgroup\$
    – stevenvh
    Commented Jul 18, 2012 at 11:05
  • \$\begingroup\$ yep, I think you are probably right. All good learning for the OP anyway... \$\endgroup\$
    – Oli Glaser
    Commented Jul 18, 2012 at 11:29
4
\$\begingroup\$

This is certainly possible with just about any small micro. You can either get one with enough pins or do some multiplexing for the buttons and have the LEDs driven by shift registers.

For 4 LEDs plus micro a coin cell is not really going to do, they have a very high internal impedance, generally only being able to supply a few mA before the voltage drops below a "usable" level. A few AAAs/AAs/Li-Ion would be more capable.
If you run the LEDs at a very low current and the micro at e.g. 32kHz, then it could be made to work, but unless there is a pressing need to use coin cells I'd avoid them.

Something like the 20-pin PIC16F1828, some buttons, and a few shift registers would be a cheap and easy way to go about this. Obviously if you prefer another brand of micro then there are many equivalents.

EDIT - some detail:

Shift registers

A shift register basically turns serial data into parallel data or vice versa. The one you will need is a serial to parallel shift register like the 74HC595. You have 3 main control inputs, a clock input, a data input and a latch input. The 595 has 8 flip-flops in a chain (flip flops store 1s or 0s) like this (4 shown):

FFs

When the clock toggles, whatever value is on the Data In pin (1 or 0) is shifted into the IC, and the last value shifted out (either forgotten or sent to another 595 if chained together) So you "shift" the data in one bit at a time till you have set all 8 flip flops to your desired value.
Then to output that data, you set the latch pin and the data appears on the 8 output pins. So 3 pins can be used to control 8 pins (or 16, 24, 32, etc)
Here is a picture of 2 595s chained together and driven from an Arduino:

HC595 example

There are loads of tutorials that go into much more detail than above out there, google for "shift register tutorial" and you get stuff like:

PIC shift register tutorial
Arduino 74HC595 tutorial
Another 74HC595 tutorial

Buttons

You can use a multiplexer like I mention above (check out stuff like the 74HC4051, 4052 and 4053), but since we are talking about shift registers it's worth mentioning we can use a parallel in, serial out shift register to read the buttons. The same connections, just the other way around - we latch the button states into the flip flops, then clock the data bit by bit into your microcontroller pin (i.e. read on each clock and store so you end up with 8 binary values)
Here is an example:

Buttons Shift

Final thoughts

From the comments and having had some time to think, I am leaning towards just using a micro with enough pins to have 1 per LED and button. This will be a smaller footprint than the shift registers, and involve the simplest firmware. I'd go for this at least to start with whilst prototyping.

Steven gave a very good answer, and multiplexing using IO pins is a common way of doing things (see Charlieplexing for a very economical multiplexing method) and certainly worth learning about.
The coin cell drive is certainly possible as mentioned. For a rough idea, I have a project prototype here using one of the PIC16F1828s mentioned above driving a 7-seg display, 2 buttons (the 16F1828 has internal pull ups so no resistors necessary) and 2 leds, which runs from a coin cell and sleeps between operations - the cell lasts for up to a year with normal use. So it's certainly possible, just adds complexity which you may want to save till later.

So in summary there are plenty of ways to go about this - if you have a breadboard why not grab the components for the options you want to try (use the dip versions then switch to SMD for final version if possible) and experiment at leisure.

\$\endgroup\$
8
  • \$\begingroup\$ Wow awesome! this sounds complicated :( the computer track was never my strong side of electrical engineering. if you could, would you please elaborate so a beginner like me could understand where to start and to go about on this small project. I'm relieved that this is possible haha. I am quite unsure on how to do multiplexing or utilizing shift register and also what parts to get. thank you so much for your help :D \$\endgroup\$
    – user10916
    Commented Jul 18, 2012 at 0:06
  • \$\begingroup\$ I added some more info, hope this helps a bit - just let me know if you need anything clarifying. \$\endgroup\$
    – Oli Glaser
    Commented Jul 18, 2012 at 0:46
  • \$\begingroup\$ thanks a bunch. I just did some reading on how to multiplex. I will do more reading tonight but I'm curious if this will still fit in a 3.5in X 1.5in PCB with all the parts (LEDs, button, shift regs, micro, power supply and the wiring/soldering.) I am confused about if I should use both multiplexing and shift regs. I need to read up on how shift regs work haha. I remember doing labs, I wish i paid more attention. so far what i had in mind was doing a 5 by 5 so using 10pins. but then i was reading it had to be connected to transistors and resistors. Im worried about space on the PCB. \$\endgroup\$
    – user10916
    Commented Jul 18, 2012 at 1:06
  • \$\begingroup\$ You can just use the shift regs for both buttons/LEDs, or you can use a multiplexer if you want - there are many different ICs and ways of doing this, the above is only one way. Depending on your micro, you may have enough pins to just wire the buttons directly (or even LEDs too if you pick a e.g. 48 or 64-pin micro - might be the way to go if you want to keep it simple and easy) If you use SMD stuff, you should fit it into 3.5in x 1.5in okay. \$\endgroup\$
    – Oli Glaser
    Commented Jul 18, 2012 at 1:13
  • \$\begingroup\$ thank you for being so helpful and patient with me!!! i really do appreciate this! i understand there is a bunch of ways to do this and I wouldn't which would be the best or efficient method. As a last resort i will probably try using a 48 or 64-pin micro haha. But lets say I wanted to do the 5 by 5 multiplexing. What specifically would I need to get and understand to use this method? So far I was thinking I can use one button to increment & decrement by pushing it or holding it. Less buttons now :) In this case what are the necessary things i need to do and understand? thank you so much again \$\endgroup\$
    – user10916
    Commented Jul 18, 2012 at 1:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.