MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

icon
Avatar
juleiin
Posts: 54
Hi!

I have a question about using LEDs on Arduino Mega.

From what I understand each digital pin deliver 5V and up to 40mA. And the total intensity allowed over all pins is 200mA.

The operative voltage of an orange/yellow LED is approximatively 2,1V and the intensity needed is said to be 20mA (can it be less ?)

Consequently, if you want to light 4 LED (example : displaying HDG HDG VS VS or TRK TRK FPA FPA on the fcu) from one pin you only have one option :



Indeed, if you put 3 leds in series the voltage per led drops below the operating voltage (1,66V < 2,1V) so it does not work.
And if you add one more leg in parallel (so 2leds/1led/1led) the intensity in each leg is 13mA which is < 20mA.

Am I right about this ?

Secondly, with an a320 fcu, I have to be able to light at the same time (imagine pressing annunciator light test swtich) :

6 green led for the button
orange speed led (1 led)
mach speed led (1 led)
hdg/hdg/vs/vs leds (4 leds)
trk/trk/fpa/fpa leds (4 leds)
lat/alt/lvlch/--------- leds (i need 8 leds for this and it is always lit)
3 managed dot leds
(+ the 3 7-segment display but let's forget them for the moment)

All of these leds need 6+1+1+1+1+3=13pins (knowing that the lat/alt/lvlch/------- leds are always lit they are plugged to the 5V pin which delivers 500mA if I'm right ?

Then for two of these 13 pins 40mA are used, for the other 11, 20mA are used (because only one led per pin), for a total of 300mA => conclusion it is impossible car limited to 200mA. (and we skipped the 7 segment)

So then, how should I do ?

Thanks
Julien
2018-06-10 15:37
Avatar
juleiin
Posts: 54
Update :

I realized my leds work as I wish (it is to say enough bright) with a current between 2 and 7 mA which make it more simple to power all the leds I need for the FCU within one Arduino Mega.
2018-06-10 20:00
Avatar
StephanHo
From: EDDG, Germany
Posts: 1719
Supporter
Hi Julien,

in terms of physical parameters you are quite right. But you also describe the values ​​that should not be exceeded as the ultimate maximum.
The engine of a car should not always run in the red area, if you would like that he lives longer.

So also with the LEDs and the pins of the Arduino.

I myself use high brightness LEDs with >8000mcd. This one can operate with less than 10mA and still has sufficient brightness. Works only with the high brightness LEDs.

In your case, it's not about being able to pin as few pins as possible and getting the maximum amount of power, but about designing everything for longevity and reliability.

If LEDs are e.g. can be connected in series to exploit the operating voltage, it may lead to differences in brightness, because the LEDs are subject to both the brightness and the breakdown voltage of a production-related scattering.

By switching the LEDs that you want to connect in series in parallel, you still have the option of individually balancing the brightness by adjusting the pre-resistance.

As you have correctly stated in your update, and I had already recommended that, LEDs do not have to be operated with the mandatory 20mA. A less goes too and ensures a longer life of the LEDs.

Optimization or not, but to maximize the maximum, I do not consider it appropriate to push the MEGA to its limits and save pins. A MEGA costs about 10 euros / piece and can control up to 40 LEDs or 50 switches. That's 20-25 cents per pin. Mobiflight, on the other hand, can control any number of MEGAs (up to 127, depending on the operating system). In this respect, one should consider, rather take a MEGA more into the system, rather than consuming perform power and Pinsparberechnungen.

For "power guzzlers", such as stepper motors, you should plan a separate power supply from the outset, because 2 steppers are already a MEGA lame.

When looking at your chart I noticed that it is wrong - not in the presentation, but in the values.
If you are running a 40 ohm resistor at 20mA, 0.8V will drop across the resistor. This leaves only 4.2V or 2.1V per LED for the LEDs.
If you want the 2.5V to drop across the LEDs, you do not need a dropping resistor, which greatly shortens the life of your LEDs!
So you need to take LEDs that have less than 2.5V breakdown voltage so that the voltage proportions are correct and voltage can drop / should over the resistor.

Ohm's law is always and everywhere valid in electronics and always applies to the entire circuit. U (v) = R (ohm) * I (A) or I = U / R or R = U / I

The current flow direction you have shown correctly, however, no voltage flows, as illustrated by you. Voltage is the potential difference between two points in a circuit. Voltage differences can always be measured across components, e.g. a resistor, a diode, a capacitor. In your diagram, the voltage between the upper and lower horizontal lines must always be 5V. Above the components, the voltage is divided, depending on the resistance.

Also, it does not matter how many identical parallel strands you install. If you have the same components in each strand, the current of the first strand is added for each strand, but the voltage remains the same. In this respect, I can not understand how you then per strand without component change the current from 20 to 13 mA to sink?

The 500mA have nothing to do with the Arduino. This is a feature of the USB interface whose specification specifies that a maximum of 500mA current can flow through a USB cable. Even the USB hubs with 10 interfaces have only one power supply with 3500mA, because it is assumed that the currents do not flow permantent.

The current of the MEGA is not limited (only via the input of the interface). If more current is drawn than can be supplied, the voltage will be reduced (it will break) and malfunction will occur at the outputs of the MEGA.

Whether a MEGA regulates an output current of 200mA depends on many factors. Basically, the outputs of a MEGA are grouped into groups of a 8 pins and these are limited to 200mA. Which as well as belong together can be read in the data sheet. So in total more than 200mA of electricity can be drawn. With proper wiring so the maximum possible 500mA.

Your concern for the 7-segment displays is unfounded. I operate 14 of these displays on a mega in two chains of 8 and 6 boards with 5 digits each.
These digits are not permanently on, that only happens to us because the human eye is sluggish in its perception. The magic word here is called multiplexing. Actually only one digit is controlled (one of 5 or 8 - depending on the arrangement) and this with a very high speed (about 800 to 1000 Hz on the MAX7219). The high frequency also has a positive effect on the power consumption. By controlling only one digit at a time, the system switches to the next one before the entire current flows through the first digit. Thus, the actual power consumption in multiplex mode is about 30-40% lower than with static control.

When assigning the devices to Mobiflight, care should be taken to allocate the devices in mixed operation to the modules, so that a distribution of the loads is performed. This protects the MEGAs.

What should you do?
Many things have already been said. If you include this in your decision, there should be no problems in the operation of your modules.
For LEDs that always light, you do not need a pin, which can then be permanently connected to a corresponding resistor to + 5V.
I wish you success!
Grüße,
Stephan
2018-06-11 11:40
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4703
Supporter
Just a Idea... Crazy i never think about before....

Basicly i not understand the technic with setting here LED in series or parallel..... Cause every LED in the cockpit needs its own Pin finaly ( to controll the needed function and show the specific status of that function).
Shure... For a Lighttest the curren status of function is not important.... BUT If we make the Lighttest via Software (Whatever the AddOn support all Offsets to "1" when virtual button is pushed OR via Mobiflight Preconditions ( If Lighttest Offset =1 THEN Always 1) .... In Both Ways Every LED get the Power again from its specific Pin.

If you cable 4 LED together to ONE Pin (Whatever parelell or in a row) then all will light same time or won´t light same time. ... That make no sense in a cockpit.

BUT!!!!!

NOW i think about a different logic.
Question to Stephan

For example i will use 10 LED to show 10 different things.... ( Like the MCP Status LED of AP, HDG Hold, ALT Hold and so on )
Every LED is set to a individual Pin ( for example Pin 3-12 )
Every function got a own Config ... Control the specifiv LED on its pin and work directly to the Offsets ( No Lighttest logic included)
Every LED is set with the needed resisitor.... Like we do always... LED Power current.... 5V ... and so on)

NOW the Idea.
What happend if we cable all 10 LED now additional to the already used system ( via pins) with a additional line that support 5v .
This line have a switch that cut power all time and only open when pushed.

Result... The 10 LED will light all the time in case of there SIM Status via Pin Power.... BUT When our new button is pushed ALL 10 LED will powerd "external" and will light.

Finaly here my electronic skills are to poor.
Question 1: What happend if a LED is ON by Pin and now get additional Power by the second line SAME TIME?
Question 2: What hapend with GRD ? Do we need to share all 10 Grounds to the "external" suply of Line 2, too ?
Question 3: Whats the correct way... Should the second line is Paralell or in a row ? And how is the needed Power and resistor finaly ( For example 10 identical LED´s )
Finaly.... Is that possible after all... or is that just a stupid idea ?

Thanks
Good Luck !
2018-06-11 16:55
Avatar
StephanHo
From: EDDG, Germany
Posts: 1719
Supporter
There is only one reason for the technology of switching the LEDs in series: saving components.
For the LEDs in series, I need only one resistor per row, with parallel connection, each LED requires a resistor.
BUT: with the Arduino, the series connection has its problems when the breakdown voltage of the LED is at or above half the operating voltage. Then no voltage can drop over the resistor, since it must become infinitely small. With a breakdown voltage of 2.5V and two LEDs in series, 0V will remain, dropping above the resistor without lowering the 5V across the two LEDs. At 20mA and 0V voltage, according to Ohm's law, R = U / I, ie R = 0V / 0.02A = 0 ohms. U = R * I would be 0 = 0 * 0.02 - also correct I = U / R would be I = 0 / 0. Verschaf! Mathematically, a division by 0 is prohibited, so not possible! Thus, this calculation is not solvable. It will only become feasible if the breakdown voltage of the LEDs is below 2.5V. But by material scattering, one LED can have 2.4V, the other 2.6. Again not feasible. So as a minimum, 0,1V are necessary.

Now for the example with the 10 LEDs:

I anticipate the result: it does not work, or at least until the MEGA is fried.

Reason:

First to the wiring. From the external power supply the GND goes to the GND of the MEGA. Thus, both the MEGA and the external power supply have a common reference potential - namely the GND.

Viewing error: From each pin goes a line to the series resistor of the respective LED, from there to the anode via the LED to the cathode and the GND.

Now comes from the switch ONE line, which goes to LED1, then to LED2, then to LED3 ... LED10. The wire is soldered to the point BEFORE the series resistor.

Assuming that all LEDs are off, nothing happens at first. Now, when switched on via the SIM LED4, comes from PIN6 of the MEGA + 5V. These + 5V go immediately over the wire of the switch to all points in front of the series resistors, via the series resistor to the anode of the LED to the cathode to the GND. So ALL LEDs want to light up. Thats not OK. Assuming that the series resistor is designed for 10mA, 10 x 10mA = 100mA would flow through the output of Pin6, which immediately causes the voltage to collapse. Result: no LED lights. Since the outputs of the MEGA are not short circuit proof, this output inevitably burns through and is destroyed!

That's not how it works.

What would happen now if the new button is pressed?

All outputs of the MEGA are at approximately GND potential. Now come via the button + 5V to the point in front of the series resistors, the anode of the LEDs, the cathode to the GND. Result: All 10 LEDs are lit!

BUT:

The + 5V also go to the pins of the MEGA. Its outputs are at GND potential (approximately). The MEGA controls at its outputs so against this 5V, but it can not make it because the currents are too large.

Result: The output stages of pins 3 to 12 burn through.

So it is not synonymous.

So the problem is the direct connection of the outputs via the new button. Now you could solder the button leads between the series resistor and the anodes of the LEDs.
Does not work, because when the button is pressed, the LEDs get the 5V of the button WITHOUT resistor.

Result: all LEDs are burning!

So it is not synonymous.

In order to make your circuit operational, we need more components, namely 20 diodes, to decouple the leads of the probe and the pins of the MEGA.

This is done as follows: between the pin of the MEGA and the series resistor, a diode is inserted in the flux, ie pin - anode - cathode resistor.
This ensures that a positive voltage can flow in one direction only. The series resistors must be recalculated because about a diode about 0.7V voltage drops, which then drops less than the resistance.

So far, only 10 diodes are installed, thus protecting the outputs of the pins, even when the button is pressed. But still 100mA flow when an LED is turned on by any pin.
So the lines from the button must also be decoupled from each other.
Cable from the button to anode diode, cathode to cathode before the series resistor. Set up for all 10 lines - done.

What happens if PIN4 of the MEGA is pulled to 5V? 5V go to the first diode, then even 4.3V, which hit the series resistor, but at the same time on the cathode of the line from the button. 4.3V can not pass this second diode, because it is in the reverse direction. Then the 4.3V continue on the series resistor to the LED (LED lights). But only 1 LED lights up.

Now the button is pressed. 5V go via the button to the 10 anodes of the diodes, to the cathodes and the series resistor. There are the diodes to MEGA but in the reverse direction, so that nothing penetrates to the MEGA. Then the 4.3V continue on the series resistors to the LEDs and all light up.

BINGO - it works!

For question 1: answered
For question 2: answered
For question 3: answered

You see, your idea is not that stupid at all, it can even be realized - with a little effort, but realizable.

If desired, I also draw the schematics. Was not possible in a hurry ...
Grüße,
Stephan
2018-06-11 20:19
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4703
Supporter
OK.

Thanks for your work Stephan.

I got the fu**ing Diod already in the brain.... But was not shure "where" i should set it.... The key is as you write to use 2 diodes.... That what i not think about.

But summary.... THIS is much more difficult as a software solution.
Whatever the lighttest is not simulated .... Its already much more comfortable/easy to make a Custom Offset Switch and preconditions.... As to wire all led twice with a lot of diodes.

So... Nice Idea, but not think to the end !

Thanks for Brainstorming and sorry for Off Topic !
Good Luck !
2018-06-11 20:46
Avatar
juleiin
Posts: 54
Hello,

I read about transistors to limit the current delivered by the Mega but I really don't understand anything of it. Do you think it can be used with Mobiflight ?

Thanks
2018-06-14 22:24
Avatar
StephanHo
From: EDDG, Germany
Posts: 1719
Supporter
Hi Julien,

as long as the transistors are also controlled via the MEGA, there is no saving with the current. This requires an external power supply.
It is also a question of the effort you want to do.

Basically, you can assume that a MEGA covers your electricity needs. With multiple MEGAs, you can distribute the power demand evenly across the MEGAs without having to resort to external switching elements.

It has been my experience that you only need an external power supply for servos or stepper motors because these elements have an increased power requirement. As long as you make sure that all modules connect the GND to each other, these external components can be properly supplied with the control signals.

I hope this info will help you.
Grüße,
Stephan
2018-06-16 11:50
Avatar
juleiin
Posts: 54
Ok thanks, finally I am gonna used 2mA LED.

Julien
2018-06-17 19:10
Avatar
StephanHo
From: EDDG, Germany
Posts: 1719
Supporter
Great, low current LEDs are a very good alternative to save power.

So you are definitely on the save side.
Grüße,
Stephan
2018-06-17 20:06
Avatar
juleiin
Posts: 54
But is it better taking 2mA led of 2mcd (low brightness) or 20mA led used such as they only use 2mA with the good resistance but initially they bright 50mcd ?

Julien
2018-06-17 22:34
Avatar
StephanHo
From: EDDG, Germany
Posts: 1719
Supporter
Ok, there are high brightness LED with more than 8000mcd. These you can use with a current lower than 10 mA.

Look at https://www.reichelt.com select the french language an search for led ultra bright 5 mm
Grüße,
Stephan
2018-06-18 00:15
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4703
Supporter
Maby somebody find time ( and risk 10 $) for a simple testing.

We can use 40 LED per Board via Mobiflight.

So if you set 40 LED with 20mA current we got a theoretical need of 40x20= 800 mA
Thats basicly above the limit ( maby)

So if one of us simply set those 40 LED on a Breadbaord.... Wire it to 40 Pins of MEGA.... And make a Config for that ( Maby 40 Output Lines.... ALL use same Offset ( like Parking Brake Tutorial)

Now we run Mobiflight and set the Brake.....

What Happens ? Is the Board killed ? Does all 40 LED Light in a normal level of Brightness ?

If all is ok i would test this for 3-5 Seconds .... then Wait a bit and do it again for 3-5 Seconds .... And this maby 10-20 times.
( To simulate a short timed Lighttest of all LED..... As we said in normal procedure normaly not all LED will light same time so there is no power problem after all )

If THIS Testing workes fine and there is again no problem after 20 tests then i would set the brake again and stay ON maby 1 minute, 5 Minutes or maby 1-2 Hours.
What happens now ? Are the LED light after 1-2 Hours already without problems ? Is the MEGA getting hot ?

******
Summary... I not know the result and maby my opinion is wrong ! ... But i think pretty shure a 800 mA use ( Whatever for 10 minutes or longer) will NOT kill your board.
It will reduce lifetime of Mega ! But again... You do the Lighttest only 1 time per flight and then only for some seconds. I think this hole thematic is not realy important !
Good Luck !
2018-06-18 12:25
Avatar
thomaspeak
Posts: 1
Low-current LEDs are a very good alternative for saving energy.
2021-07-21 15:05
Avatar
haleszarz
Posts: 1
But they are not bright enough.
2021-07-21 15:13
icon