# LED brightness help request

**URL:** <https://forum.arduino.cc/t/led-brightness-help-request/1114348>\
**Category:** Programming\
**Created:** [April 12, 2023, 2:10pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348 "2023-04-12T14:10:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyjoe97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jimmyjoe97/32/1098850_2.png) [@jimmyjoe97](https://forum.arduino.cc/u/jimmyjoe97)\
**Post date:** [April 12, 2023, 2:10pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/1 "2023-04-12T14:10:20Z")

</div>

Hey i'm new to the Arduino world helping my daughter on a school project and im stumped on a problem with the LED brightness.

The micro controller is a :Adruino Mega 2650 Rev3

Anyway,  
We have 14 LED light connected in series in banks of two, each bank connected to pins 30 thru 37 and to ground (no resistors in the circuit)  
They are all supposed to flash at one time when the (if) statement conditions are meet it runs fail1 or fail2 scenario, it works but they are all very DIM.

Any help would be greatly appreciated.

```cpp
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#include <LiquidCrystal.h> // include the library code:
#include <Servo.h>
#define button_pin A3 // Defines the Button pin location on the Mega
long randnumber; // Defines the maxium numeric size of the random number
int randomnumber; // Defines that the random number is an integer(a number,not a letter)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Initializes LCD library & defines the Mega pins connected to the LCD pins
Servo myservo; // Initializes the Servo
int servospos = 150; // Start postition of servo
#define ledpin 13 // Defines the Winner LED pin location on the Mega
#define ledpin30 30 // Defines the Fail Lights Pin
#define ledpin32 32 // Defines the Fail Lights Pin
#define ledpin31 31 // Defines the Fail Lights Pin
#define ledpin33 33 // Defines the Fail Lights Pin
#define ledpin34 34 // Defines the Fail Lights Pin
#define ledpin35 35 // Defines the Fail Lights Pin
#define ledpin36 36 // Defines the Fail Lights Pin
#define ledpin37 37 // Defines the Fail Lights Pin

#define buzzerpin 4 // Defines buzzer pin on the Mega
int buttonState = 0; // Defines the data type for buttonState and starting value is 0
int count_value = 0; // Defines the data type as interger and starting value of 0 for the counter
int prestate = 0; // Defines the data type as interger and starting value of 0 for the button prestate
int S = 60; // counts down 60 seconds

void setup()
{

  Serial.begin(9600);
  randomSeed(analogRead(0)); // Tells the random number generator to use the Mega's analog pinA0 to listen for electrical noise and grabs a seed number from the noise to start the random sequense.
  Serial.begin(9600); // Turns on the serial port to use the PC serial monitor for debugging.
  lcd.begin(16, 2); // Set's up the LCD's number of columns and rows:
  randnumber = random(1, 11); // Defines the Random Number Range to be between 1-5 (Note:The number listed as the upper range will not be genrated)
  Serial.println(randnumber); // Print to Serial port for debuging
  lcd.setCursor(8, 0); // Sets the LCD cursor to column 8, line 0 (Note: line 0 is the top line)
  lcd.print(randnumber); // Prints the random number to the LCD
  lcd.setCursor(8, 1); // sets the LCD cursor to column 8, line 1 (Note: line 1 is the botton line)
  lcd.print(count_value); // Prints the number of button presses since reset
  myservo.attach(3); // Defines what pin the servo's signal wire is connected to on the Mega.
  myservo.write(servospos); // Moves the servo to the globaly defined starting postion[Box closed]so its ready when needed (position -> 30°)
  pinMode(ledpin, OUTPUT); //defines LED pin is an Output
  pinMode(button_pin, INPUT); //defined LED pin is an Input
  pinMode(buzzerpin, OUTPUT); //defined LED pin is an Input
  lcd.setCursor(8, 1); // sets the LCD cursor to column 8, line 1 (Note: line 1 is the botton line)
  lcd.print(count_value); // Prints / updates the number of button presses since reset

  Serial.println (S);
  S--;
  delay(1000);
}
void loop ()
{
  if (S < 0)
  {
    M--;
    S = 59;
  }
  if (M < 0)
  {
    H--;
    M = 59;
  }
  if (H < 0) {
    H = 0;
    M = 0;
    S = 0;
  } if (M > 9)
  {

    Serial.println (S);
  }
  else
  {
    Serial.println (S);
  }

  if (S > 9)
  {
    Serial.println (S);
  }
  else
  {
    Serial.println (S);
  }

  if (H > 9)
  {
    Serial.println (S);
  }
  else
  {
    Serial.println (S);
  }

  buttonState = digitalRead(button_pin); // Reads the current position of the button (pressed/high or not pressed/low )
  if (buttonState == HIGH && prestate == 0) {
    count_value++;
    prestate = 1; // States if the button is pressed add 1 to prestate value

  }

  else if (buttonState == LOW) {
    prestate = 0; // States if button is not pressed the prestate value is 0
  }

  lcd.setCursor(8, 1);
  lcd.print(count_value); // Reprints the number of button presses since reset

  // Fail Action if total button press count is less than random number
  if ((count_value < randnumber) && (count_value != 0)) // If the count comparison is less than the random number & not equal to 0 this runs the LED and buzzer fail sequence!

    digitalWrite(ledpin30, HIGH); digitalWrite(ledpin31, HIGH); digitalWrite(ledpin32, HIGH); digitalWrite(ledpin33, HIGH); digitalWrite(ledpin34, HIGH); digitalWrite(ledpin35, HIGH); digitalWrite(ledpin36, HIGH); digitalWrite(ledpin37, HIGH);
  // delay(1000);
  digitalWrite(ledpin30, LOW); digitalWrite(ledpin31, LOW); digitalWrite(ledpin32, LOW); digitalWrite(ledpin33, LOW); digitalWrite(ledpin34, LOW); digitalWrite(ledpin35, LOW); digitalWrite(ledpin36, LOW); digitalWrite(ledpin37, LOW);
  //delay(1000);
  digitalWrite(buzzerpin, LOW);
  //delay(500);
  digitalWrite(buzzerpin, HIGH);
  //delay(1000);
  digitalWrite(buzzerpin, LOW);
  //delay(3000);

  //winner Action if total button press count is equal to Random number
  if (!(randnumber != count_value)) // compares random number to the button press count to see if they are the same if there are is opens the box & lights the winning LEDs flashes!
  {
    digitalWrite(ledpin, HIGH); // Turns on & off Winner LEDS
    //delay(1000);
    digitalWrite(ledpin, LOW);
    // delay(500);
    digitalWrite(ledpin, HIGH);
    //delay(1000);
    digitalWrite(ledpin, LOW);
    // delay(500);
    myservo.write(30);//myservo.write(servospos); //Tells Servo to Opens the box
    // delay(000);
    //lcd.setCursor(8, 1);
    //lcd.print(count_value); // Prints the number of button presses since reset
  }

  else (count_value != 0);
  digitalWrite(ledpin, LOW); // If the above two if statement are not true do we wait longer IF so how long until it completely resets?
  lcd.setCursor(8, 1);
  lcd.print(count_value); // Prints the number of button presses since reset

  //Fail Action if total button press count is greater than Random number
  if ((count_value > randnumber) && (count_value != 0)) //If the count comparison is greater than the random number this IF statement handles the LED and Buzzer fail alerts!
  {

    digitalWrite(ledpin30, HIGH); digitalWrite(ledpin31, HIGH); digitalWrite(ledpin32, HIGH); digitalWrite(ledpin33, HIGH); digitalWrite(ledpin34, HIGH); digitalWrite(ledpin35, HIGH); digitalWrite(ledpin36, HIGH); digitalWrite(ledpin37, HIGH);
    // delay(1000);
    digitalWrite(ledpin30, LOW); digitalWrite(ledpin31, LOW); digitalWrite(ledpin32, LOW); digitalWrite(ledpin33, LOW); digitalWrite(ledpin34, LOW); digitalWrite(ledpin35, LOW); digitalWrite(ledpin36, LOW); digitalWrite(ledpin37, LOW);
    //delay(1000);

    digitalWrite(buzzerpin, LOW);
    //delay(500);
    digitalWrite(buzzerpin, HIGH);
    //delay(1000);
    digitalWrite(buzzerpin, LOW);
  }
}
//resetFunc(); //call reset

```

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [April 12, 2023, 2:11pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/2 "2023-04-12T14:11:37Z")

</div>

pinModes for the LED pins?

Please don't use single letter variable names - this isn't 1970s BASIC.

---

<div class="post-metadata">

**Author:** ![anon56112670](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@anon56112670](https://forum.arduino.cc/u/anon56112670)\
**Post date:** [April 12, 2023, 2:13pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/3 "2023-04-12T14:13:12Z")

</div>

> [@jimmyjoe97](#):
>
> (no resistors in the circuit)

Fix that too.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [April 12, 2023, 2:15pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/4 "2023-04-12T14:15:35Z")

</div>

Welcome to the forum

> [@jimmyjoe97](#):
>
> no resistors in the circuit

Why not ?

Pins default to INPUT unless you use pinMode() to set them as OUTPUT. Are all of your LED pins set to OUTPUT ?

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [April 12, 2023, 2:18pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/5 "2023-04-12T14:18:22Z")

</div>

> [@jimmyjoe97](#):
>
> (no resistors in the circuit)

You do know why no resistors will be an issue?

Why not do a Pinmode, output for the LED GPIO pins?

> [@](#):
>
> - The _absolute maximum_ for any single IO pin is **40 mA** (this is the _maximum_. You should never actually pull a full 40 mA from a pin. Basically, it's the threshold at which Atmel can no longer guarantee the chip won't be damaged. You should always ensure you're safely _below_ this current limit.)
> - The total current from all the IO pins together is **200 mA max**
> - The 5V output pin is good for **~400 mA on USB, ~900 mA when using an external power adapter**
> - The 900 mA is for an adapter that provides ~7V. As the adapter voltage increases, the amount of heat the regulator has to deal with also increases, so the maximum current will drop as the voltage increases. This is called _thermal limiting_

 ![](https://europe1.discourse-cdn.com/arduino/original/4X/0/9/d/09d2e5a3bd2cc835139b1ad40ed5caefa519d241.jpeg)

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [April 12, 2023, 2:31pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/6 "2023-04-12T14:31:26Z")

</div>

In simple terms:  
You can't put two LEDs in series and connect it to a mega pin, it WON'T work and you will probably damage the mega.

You can only put ONE LED with a series resistor to limit the current to 20mA or less.

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [April 12, 2023, 2:51pm UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/7 "2023-04-12T14:51:01Z")

</div>

> [@jimmyjoe97](#):
>
> We have 14 LED light connected in series in banks of two, each bank connected to pins 30 thru 37 and to ground (no resistors in the circuit)

Given the 200mA total limit, **14 LEDs at 14mA each is 196mA.**

[Calculate the resistors](https://ohmslawcalculator.com/led-resistor-calculator) for 14mA (or less) and put the LEDs in **parallel-pairs, each with their own resistor.**

**10mA is probably "bright enough"** and with two in parallel you won't exceed the 20mA per-pin _recommendation._

Our eyes are proportional/logarithmic so 10 mA is only perceived slightly dimmer than 20mA. LEDs also vary in brightness, so an LED with more brightness is another option.

* * *

**...LEDs (like all diodes) are non linear.** As the voltage goes-up their resistance goes-down. [Ohm's Law](https://en.wikipedia.org/wiki/Ohm's_law) says when voltage goes up current goes up, and when resistance goes down current goes up.

**So if the voltage across an LED is a little too high the current can get WAY too high** and the LED or whatever is driving it can burn-up! (Or other "bad things" can happen.)

**If the voltage is a little too low the current goes WAY down and the LED gets VERY DIM.** With devices in series the voltage is divided so that's probably why your LEDs are too dim...

By using a series resistor to control the current, the voltage "magically falls into place" and everything is good!

High power LEDs (1W or more) normally use a special constant-current driver because resistors waste power, and you need a high-power resistor, etc. But that's complicated and expensive and with low-power LEDs we aren't using much power anyway so a resistor is usually the best solution.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [April 13, 2023, 6:03am UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/8 "2023-04-13T06:03:01Z")

</div>

> [@jimmyjoe97](#):
>
> pins 30 thru 37

That equals eight pins, not seven.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 10, 2023, 6:28am UTC](https://forum.arduino.cc/t/led-brightness-help-request/1114348/10 "2023-10-10T06:28:55Z")

</div>

Closed on October 10, 2023, 6:28am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
