Why is my LED so Dim?

I am making a toggle on/off led for practice for a future project i plan to do. I am kind of new to arduino so i watched a tutorial, and everything works fine except the light is very dim. I know that the port/led is not broken because when i use a different code (like a simple blink every 500ms) it works fine and is lit up bright. My project requires the light to be bright and i cant figure it out. I did take into account that the tutorial uses a UNO and i have a Mega2560 but does that matter even if my code is set to go on a Mega?Please help! (tutorial i watched Arduino uno Toggle button with led on and off tutorial - YouTube)

int led = 3;
int button = 7;

int ledState = HIGH;
int buttonCurrent;
int buttonPrevious = LOW;

void setup() {
int (button, INPUT);
int (led, OUTPUT);
}

void loop() {
buttonCurrent = digitalRead(button);

if (buttonCurrent == HIGH && buttonPrevious == LOW)
{
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
}

digitalWrite(led, ledState);

buttonPrevious = buttonCurrent;

}

1234.jpg

123.jpg

  int (button, INPUT);
  int (led, OUTPUT);

This is not how you set the pinMode() of an Arduino pin

What resistor values did you use. Are you operating at 5V. Since you are new to this, Why not start by defining the problem with specifications including a flow chart, schematic, and power requirements. Define what the expected outcome needs to be. Purchase the Arduino cookbook and read it, this will give you some basics. also use the online tutorials and videos available, there are many good ones on this web site. At this point you will be able to define the problem and may have already solved it. This will save you a lot of time in the long time although you need to invest some time in reading the cookbook. If you have a scope you will also see you have a fast square wave feeding the LED, not a blinking signal. Add some delays in the code.

everything works fine except the light is very dim.

Because you have not set pin 3 to be an output it is an input by default. Therefore doing a digital write to it is just turning on and off the 30K or so internal pull up resistor. This is enough to turn on the LED but as you see it will be dim.

1 Like

Heh, heh, this is an old one! We know the answer the moment we read the subject line. :grinning:

OK, the code is:

void setup() {
  pinMode(button, INPUT);
  pinMode(led, OUTPUT);
}

However pinMode defaults to INPUT on reset so if you left that line out it would still work.