Problem with my first Arduino project

Hello there,

I bought my first Arduino Uno R3 a few days ago, and I’m working on a LED lamp project. I’m quite new to Arduino and electronics, and although most parts of my project seem to work fine, I do have a “bug” I can’t trace. Here’s an explanation, I hope some of you would have a few minutes at hand to help me ^^

Project description : a LED lamp, working with 8 groups of 3 bright white LEDs, powered by a 12vdc adapter. The Arduino code enables or disables the LED groups according to the reading of a LDR.

Problem description : LEDs are getting enabled / disabled by the Arduino according to the LDR reading correctly, but whenever there’s more than 4 groups of LEDs enabled for a while, it looks like the Arduino resets himself. I’m not sure about the “reset”, but that’s how it looks : all LEDs are switching off, onboard “L” LED blinks, then everything goes back to normal for a few seconds, than all LEDs are switching off again, and so on…
If I’m monitoring the Arduino with the Serial Monitor through USB (which gives me the LDR reading and the number of LED groups which should be switched on) at the same time, the Serial Monitor seems to freeze when the “bug” happens and doesn’t update itself anymore.

Also, I don’t know if it’s relevant, but the chip on the Arduino gets quite hot while running.

Picture of my project :

Components :

  • LEDs are 5mm, sold as 14000mcd, forward voltage 3.2 - 3.8v, forward current 20mA (typical) - 30mA (max)
  • Transistors used at switches controlled by the Arduino are BC337
  • Resistors between the LEDs and the transistors are 150 ohm
  • Resistors between the transistors and Arduino’s outputs are 1K ohm

Code used :

int led[8] = {2, 3, 4, 5, 6, 7, 8, 9};
int LDR = 0;
int lum, i, nLED;

void setup()
  for (i = 0; i < 8; i++)
    pinMode(led[i], OUTPUT);

void loop()
  lum = analogRead(LDR); 
  nLED = map(lum,0,600,8,0); 
  Serial.print("sensor = " );
  Serial.print("\t output = ");
  if (nLED == 0) 
    for(i = 0; i < 8; i++)
      digitalWrite(led[i], LOW);
    for (i = 0; i < nLED; i++) 
      digitalWrite(led[i], HIGH);
    for(i = i; i < 8; i++)
      digitalWrite(led[i], LOW);

I tried cutting down the code to something way more simplier, which just switches on X number of LED groups, but the problem keeps happening as long as I’ve got more than 4 groups , so I’m thinking either of a problem with my Arduino board, or with my electronics (I’d probably bet on that one…).

Thanks for any help resolving this issue !

I think you're doing things right, but your unexpected resets are occurring due to overheating of the voltage regulator. If you put your finger on it (surface-mount component next to the input power jack) it's probably pretty hot when the LED's are on, right?

If you have 5 groups of LED's on, each at 20mA (guessing), plus the ~30mA of the Arduino itself, the regulator is supplying 130mA, and dropping 12V down to 5V (7V drop) for a power dissipation of 910mW. That would cause it to get pretty hot and perhaps enter thermal shutdown, resetting your board.

This hypothesis is easy enough to test if you have a 9V supply instead of a 12V supply.

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

I also feel the reason for the bug to occur is the same as mentioned by @RuggedCircuits.

Try reducing the circuit load and reducing the supply voltage. Additionally i'd suggest that you use a proper heat sink to avoid overheating of the main chip.

All the Best :)

I'm kind of new too and am wondering is the 12v LED supply going through the arduino or not.

I think the data pin controls the BC337 transistor which connects the 12v supply to the LEDS. They should share a gnd but there should be two +v lines one from the arduino via the digital pins and the second the 12v line through the transistor to power the series connected LEDs.

as far as I can see on the picture I think the base resistors are not connected the right way. the base of the transistors is connected diredtly to the output of the arduino. and this may be causing the overload.

Thanks all for your replies.

@ RuggedCircuits : Well, it looks like the main chip is getting really hot, even if the Arduino is powered by a 9v adapter, and it's getting a bit hot even if it's only powered by USB (not as much, but still...), as long as there are a few groups of LEDs switched on. I'm afraid this is not normal. I even had the feeling it were getting even hotter with the 9v adapter so I didn't leave it plugged for long enough to see if the bug was still there or not. The voltage regulator you're speaking about is getting pretty hot as well, indeed, only if the Arduino is powered by the DC adapter, not with USB.

@ hellonearthis : I'm not sure I'm getting your point here (sorry, my english isn't perfect). The Arduino is powered by a 12vdc adapter. The LEDs are wired to the Arduino, through its "Vin" output (which, I guess, delivers a 12vdc output if the Arduino itself is powered by such an adapter). The BC337 transistors are used as switches, are controlled by the Arduino through its data pins (pins 2 to 9, declared as outputs in the code) and are indeed used to "open" the circuit of each group of LEDs according to the LDR reading.

@ egeltje69 : If I'm not wrong, the BC337 have the following pinout : CBE (when facing the flat part of the transistor). So, correct me if I'm wrong, but I think my Base pin is connected to the Arduino with my 1K resistor, my Collector pin is connected to the LED group with a 150 ohm resistor, and my Emitter pin is connected to the ground. Does this sound correct ?

Now I did change the code so it only lights up a pre-defined number of LED groups, and did some more tests : - with 0 LED group switched on : voltage regulator gets quite hot, main chip remains cold. - with 1 LED group switched on : the same. - with 2 LED groups : main chip begins to get a bit hot, even if the Arduino is only powered by USB.

Ah, now I see it :) You have a breadboarding error. Your outputs from the microcontroller look like they go through series resistors to the transistor base but you have them all in a single 5-point row on the breadboard. The resistor is useless like this :)

I'm glad you provided a photo.

-- The Flexible MIDI Shield: MIDI IN/OUT, stacking headers, your choice of I/O pins

If I’m not wrong, the BC337 have the following pinout : CBE (when facing the flat part of the transistor). So, correct me if I’m wrong, but I think my Base pin is connected to the Arduino with my 1K resistor

In theory, YES, but on YOUR breadboard, NO. The 1 K resistor is “shorted”.

Here a picture of how I do connected the transistor. My picture use a MPS2222 - a EBC type.

Oh ! I tried to trace that bug for two days and didn't notice I was doing such a newbie error on the breadboard, ahah. :D

I've done the connections between the transistors and the Arduino correctly now, and everything seems to work pretty fine : the board doesn't reset itself anymore, and the main chip doesn't get hot at all.

Thanks a lot to all of you !

All d Best :)