00-20 counter 7 segment LED - Advice requested

Hello there.

I’m currently learning Arduino and could do with a bit of advice with regards to reducing the length and size of my current code.
I have done some reading online and couldn’t find information about changing the way in which I trigger the segments to light (but I know there must be a better way)

I will also include a series of images of my board and an image to show the current wiring
(the wiring picture isn’t very well made but in my circumstances I can’t make one better)
Thanks in advance for any advice or links provided, Ewdie

IMG_1662.JPG

IMG_1663.JPG

IMG_1664.JPG

IMG_1665.JPG

IMG_1666.JPG

IMG_1667.JPG

_8Point_LED_Display_3_PROJECT.ino (16.4 KB)

Hello , it's not clear what excatly is your need as i understood you want an up/down counter from 0 to 20 with 2 push buttons for up and down ?

I think it’s relatively clear… I’m interested in a method of shortening my current code and would like advice with regards to shortening and reducing (maybe completely replacing) that area…

I’m not interested in having it done for me but links or a push in the right direction would be more than appreciated

check the topic write before your is this forum and you should find what you need it's named "O to 99 counter UP/DOWN on 7 segmant _ SCOREBOARD"

I have seen (and posted) in your thread, I don't want the code I want to understand... Your thread did not particularly assist me in understanding...

Ewdie:
Hello there.

I'm currently learning Arduino and could do with a bit of advice with regards to reducing the length and size of my current code.
I have done some reading online and couldn't find information about changing the way in which I trigger the segments to light (but I know there must be a better way)

The code originally went up to 20 but I can't fit it all in one post (due to restrictions)

I will also include a series of images of my board and an image to show the current wiring
(the wiring picture isn't very well made but in my circumstances I can't make one better)
Thanks in advance for any advice or links provided, Ewdie

I am not understanding what you want.
Do you want a counter to go from 0 to 20 only and then back again to 0?

As to your hardware, you need a resistor for each segment of your 7-segment display, so you need fourteen resistors.

There are a lot of tutorials online for Arduino with 7-segment display. I would suggest you start with one of those.

Hello,

You should not be worried about the length of your code right now because there is something more important to worry about.

The way you have wired up your display is going to damage the Nano, and may already have done so.

You need 7 series resistors for the led segments, two transistors to handle the current from the display common connectors and 2 resistors for the transistor bases.

Please ask if you are interested in an explanation.

Paul

PaulRB:
Hello,

You should not be worried about the length of your code right now because there is something more important to worry about.

The way you have wired up your display is going to damage the Nano, and may already have done so.

You need 7 series resistors for the led segments, two transistors to handle the current from the display common connectors and 2 resistors for the transistor bases.

Please ask if you are interested in an explanation.

Paul

I understand the Resistors, but I don't understand the Transistors, can you explain please :slight_smile:

Thanks, Ewan

Hi Ewan,

An Arduino output can only source or sink a maximum of 40mA. More than that could damage it. Right now your circuit has the Arduino pins, the two that are connected to the display common pins, sourcing or sinking the current from 7 segments at once. With no series resistors, its hard to know how much that is but it is likely to be way more than 40mA.

You have a couple of choices. You could put in high value series resistors (e.g. 1K) so that the total current from 7 segments is less than 40mA. This may make the display somewhat dim. Or you can use a couple of transistors. The transistors can handle the current from 7 segments easily. Then you can use lower series resistors (e.g. 220R) for a brighter display. The transistors would be connected between the Arduino pins and the display common connectors using a resistor (e.g. 4K7). The type of transistor would depend on the type of display you have. NPN transistors for common cathode displays, PNP transistor for common anode displays.

So can I use 7 resistors for the 2 displays? Placing the resistors on each pin before connecting the segments in parallel?

Then using the transistors for the connection of the common power rails on the display.

Frankly I would not drive an LED directly from the Arduino in this manner - as was previously mentioned you risk exceeded the amount of current the Arduino can handle.

Using a multiplexer (such as the ubiquitous MAX7219) gets around this (sort of, depends on number of digits) by only turning on segments very quickly for each digit. Works like a dream.

If you think this might be an approach you could take take a look at my videos #9, #10 & #11 and you will know all you want to know about using a MAX7219 and an 7 segment display! Then you can just 'write' the number to the required digit without any fuss at all.

Just suggestin' :slight_smile:

Set up your hardware like this.

I believe mine is common Anode, therefore I would do the same thing with the opposite transistor on the Anode?

Yes, with PNP transistor.
Using TPIC6C595 open drain shift register vs Arduino pins would eliminate current concerns, free up Arduino pins, and also make coding easier as then just need to shift out a byte, turn on anode drive, after 3-4mS turn off anode drive, shift out a byte, turn on the next anode drive, after 3-4mS turn off anode drive, and repeat.

Thank you very much, much appreciated and a good explanation with diagrams.....

With 220R or 330R series resistors, the Arduino will be able to supply the current ok, as long as it it not also supplying too much else (other leds etc).

You may also need to adjust your code slightly because the transistors will logically invert the Arduino output. But then you came here for suggestions for code changes anyway! Let us know when you have the display working ok with the transistors & resistors and we can start looking at it.

CrossRoads:
Yes, with PNP transistor.
Using TPIC6C595 open drain shift register vs Arduino pins would eliminate current concerns, free up Arduino pins, and also make coding easier as then just need to shift out a byte, turn on anode drive, after 3-4mS turn off anode drive, shift out a byte, turn on the next anode drive, after 3-4mS turn off anode drive, and repeat.

What is the top of this transistor to be connected to and why please?

5V for single LEDs and small displays.

Only ever the same 5 V supply as the Arduino with that particular circuit, actually.

Newly connected board… What do you think?