3
\$\begingroup\$

I want to show a program state with LEDs. There are 22 steps, each step is represented by an LED.

  • only one LED is on at a time
  • the sequence is set (forward or backwards).

I have only one pin left on my MCU, maybe two.

Basically, I'd like to have the pin work as a 'clock'. For every pulse, the "next" LED is switched on, all other LEDs are off.

I could use a clock to binary IC. (e.g. 74HC393 Binary Counter) This would create a nibble, which I could then feed into a multiplexer (e.g. 700-MAX336CPI+) which would switch one of its 16 outputs on at a time. (I can live with 16 steps).

I want to make it relatively cheap. I wonder if there is a more elegant solution. Maybe with a specialized IC, or if there is a solution with simple discrete components, oh, maybe I could even use a little servo to point at the right step... What comes to your mind?

\$\endgroup\$
7
  • 8
    \$\begingroup\$ Chain two decade counters (e.g. CD4017) you'll get a "decimal" display \$\endgroup\$
    – Mat
    Commented Jan 11, 2022 at 22:28
  • \$\begingroup\$ 2 or 3 cascaded 4094B 8-Stage Shift and Store Bus Registers. D and Clock inputs. \$\endgroup\$
    – user173271
    Commented Jan 11, 2022 at 22:44
  • \$\begingroup\$ Do you or do you not need for the display to move both forwards and backwards? If forward only, then I also recommend 4017's. \$\endgroup\$
    – AnalogKid
    Commented Jan 11, 2022 at 23:01
  • \$\begingroup\$ yes, both forward and backward, but, backward would be pulsing it quickly 21 times \$\endgroup\$
    – lode
    Commented Jan 11, 2022 at 23:11
  • 1
    \$\begingroup\$ Does this answer your question? How to Cascade 4017 Decade Counters? \$\endgroup\$
    – Damien
    Commented Jan 12, 2022 at 8:58

7 Answers 7

6
\$\begingroup\$

I'd use 3 4017 counters, chained together. Just clock the chain from your microcontroller. The 4017 is very cheap, has an output for each LED (so no decoding), and can be set up very easily to be chained. You would need 3 for your application. The 23 pin output should just reset them all to restart the count.

Edit: You might be able to hack up something using diodes and pull-downs to test whether the 'reset' (ie, the 23 output) is high using the clock pin. A diode from 23 to the clock output through a 10k resistor, with a 100k resistor at the pin as a pull-down. When the clock is being driven low by the uC, momentarily change it to an input. If it stays low, it's not the end yet. You might also have to test 24 (ie, have them both connected to clock through a diode and 10k resistor) since the pullup will probably clock it again (but only once, until you drive it low again). Not sure, haven't tried it, but probably.

Much easier just to blow another uC pin to test 23, but you said you didn't want to do that.

\$\endgroup\$
3
  • \$\begingroup\$ CD4017 "decade counter" is the answer to my question and is putting me on track. Indeed cheap. Thanks. \$\endgroup\$
    – lode
    Commented Jan 11, 2022 at 23:11
  • \$\begingroup\$ electronics.stackexchange.com/questions/33652/… \$\endgroup\$
    – Damien
    Commented Jan 12, 2022 at 8:58
  • \$\begingroup\$ Connecting the micro's output pin to the 4017 clock input and to an R,C,R network feeding MR on the 4017 probably would be simpler than "something using diodes and pull-downs". To clock the 4017 send a short pulse then delay briefly to let voltage on C drop. To reset the 4017 send pulse long enough to raise voltage on C above reset threshhold. (This supposes positive going reset which might not be so) \$\endgroup\$ Commented Jan 12, 2022 at 21:17
10
\$\begingroup\$

Upgrade you MCU to one with more pins. It will be cheaper than adding more parts.

\$\endgroup\$
1
  • \$\begingroup\$ very good point \$\endgroup\$
    – lode
    Commented Jan 11, 2022 at 23:12
8
\$\begingroup\$

Addressable RGB LED strips work with one single data pin.

\$\endgroup\$
2
  • \$\begingroup\$ To add some context: WS2812b is the type of the most often used addressable LED in an SMD 5050 package on a strip. APA106 would be a near-compatible LED type in a standard 5mm round-hat LED package ("F5"). Both of these work with a one-wire protocol, which needs a precision of plusminus 150ns in the timing of the data protocol; i.e. you'll be blocking your µC for the duration of the data transfer. There also is e.g. APA102(c) (in an SMD 5050 package), which uses a two-wire protocol, which is less prone to timing issues. \$\endgroup\$
    – orithena
    Commented Jan 12, 2022 at 10:15
  • \$\begingroup\$ An I2C port expander would work as well. \$\endgroup\$
    – Michael
    Commented Jan 13, 2022 at 8:09
5
\$\begingroup\$

Use a second MCU.

Connect to it using one I/O pin and implement a UART protocol between the two in software. That gives you a whole data byte in which to encode your LED pattern control, which is tons as you describe the requirements.

You can buy a 28-pin MCU that will do the trick for under a quid (£1). That gives you your 22 I/O pins for direct LED driving with only one ever on, plus 1 I/O for host MCU connection.

This is the smallest circuit with the fewest ICs for direct LED drive: one IC, probably one crystal, two decoupling capacitors. Saves on a load of shift registers etc. and uses cheap LEDs and resistors.

If you're happy to put the LEDs in an multiplexed drive array, you could use fewer resistors and fewer MCU pins, so a smaller MCU. The example circuit below shows 20 LEDs in an array, driven by 5 MCU I/Os and with 4 MCU I/Os sinking the return current.

You'd need a 5x5 LED array so you'd use 10 MCU I/O pins. With 1 more I/O pin for UART receiving, you could use a 14-pin or 16-pin MCU.

enter image description here

Image from Nduli's World

On top of the part cost, you'll pay program development/testing time and expense. If it's just you on your own, not a professional job, then that's less important. If it's a professional job, that is a consideration to be costed out.

\$\endgroup\$
4
  • \$\begingroup\$ ... or even a 14-pin MCU! \$\endgroup\$ Commented Jan 12, 2022 at 9:47
  • \$\begingroup\$ @MartinRosenau, very much, thanks. I didn't have the energy to put that in the original answer late last night but I've put it in now. \$\endgroup\$
    – TonyM
    Commented Jan 12, 2022 at 11:38
  • \$\begingroup\$ With some charlieplexing, it could be done in 7 pins, (4x3)x2=24. \$\endgroup\$
    – penguin359
    Commented Jan 12, 2022 at 17:43
  • 2
    \$\begingroup\$ @penguin359, actually I was keen to avoid it subsiding into a 'how do I drive LEDs with fewest pins' answer, with the accompany mountain of comments. That's been done too many times before on the site. The OP will get the point from the direct and muxed examples given. \$\endgroup\$
    – TonyM
    Commented Jan 12, 2022 at 20:11
2
\$\begingroup\$

Your proposed solution with a pulse to advance to the next LED sounds doable.

With two dedicated pins (data+clock) you could use I2C (bit-banged in software if required) and connect a couple I/O expanders or a multi-channel led driver.

With a single data pin, you could try an addressable RGB LED strip or your own arrangement of daisy-chained addressable led chips on a PCB. They're pretty cheap, but they will need 5V and a level shifter.

You can also look at the 1-wire family of chips.

A solution with a servo and dial would definitely have some character, if you can live with the noise ;)

\$\endgroup\$
1
\$\begingroup\$

Like Justme I would suggest the use of addressable LEDs, like the ubiquitous WS2812 (single pin needed, weird timing-based protocol, but very widely supported), or the APA102 (two pins needed, standard SPI).

The LEDs are daisy-chained, so you send commands on the wire(s) and you can change all LEDs at once.

This may be overkill in you case as:

  • They are RGB LEDs
  • You can make any combination you want

But the simplicity and additional flexibility may be useful!

\$\endgroup\$
0
\$\begingroup\$

the sequence is set (forward or backwards).

Even if you use 74HC4017 you'll need a second pin for reset.

If you want to scan in both directions, you need a clock pin and a direction pin, so 2 pins. With 2 pins you can use chained 74HC595 shift registers.

If you don't have two pins free, you can move one of the outputs like another LED to one of the HC595 outputs, or mux some buttons to save a pin.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ You can use the 23rd output to reset the thing. This is an old trick with these counters. Both directions can't really be done with the 4017 solution. \$\endgroup\$
    – bob_monsen
    Commented Jan 12, 2022 at 0:02
  • 3
    \$\begingroup\$ @bob_monsen you can do both directions, just send N-1 pulses quickly to light the previous LED \$\endgroup\$
    – bobflux
    Commented Jan 12, 2022 at 7:08
  • \$\begingroup\$ @bobflux: Additionally, if one connects the first LED output to the clock wire via resistor, one could reset the state of the device by switching an output repeatedly between high and floating. \$\endgroup\$
    – supercat
    Commented Jan 12, 2022 at 23:41
  • 1
    \$\begingroup\$ @bobflux I like it. zoom through the sequence! \$\endgroup\$
    – bob_monsen
    Commented Jan 13, 2022 at 4:38
  • \$\begingroup\$ You still need a power on reset to make sure it starts at the first LED, but it doesn't have to me a microcontroller IO \$\endgroup\$
    – bobflux
    Commented Jan 13, 2022 at 7:16

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.