Newbie help - first project stopped working unexpectedly

Hi all!
I am new to electronics and Arduino and have recently made a project with a Nano classic - a pir sensor triggered 10 LED sequencer (in the form of a decorative LED light).

After posting some questions here and doing a lot of Googling I managed to build my project, write a sketch and get the whole thing working. Everything was fine for a couple of days (the LED sign activated when triggered by someone passing by), but suddenly stopped working. Looking at the Nano, I can see that both the 'Power' and 'L' leds are permanently lit when connected to a 5V power supply. The reset button does not appear to do anything, and I'm not able to upload any test sketches, and get the following message -

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

The Arduino is hooked up as in the attached image and the code I used is also included below. Anyone out there have any suggestions as to how I can diagnose/fix this? Have I fried my first Arduino project?

// C++ code
//
#define SIGNAL_PIN 12
int LED1 = 11;
int LED2 = 10;
int LED3 = 9;
int LED4 = 8;
int LED5 = 7;
int LED6 = 6;
int LED7 = 5;
int LED8 = 4;
int LED9 = 3;
int LED10 = 2;
int speed1 = 80;
int speed2 = 100;
int speed3 = 40;

void setup()
{
  Serial.begin(9600);
  pinMode(SIGNAL_PIN, INPUT);
  pinMode (LED1, OUTPUT);
  pinMode (LED2, OUTPUT);
  pinMode (LED3, OUTPUT);
  pinMode (LED4, OUTPUT);
  pinMode (LED5, OUTPUT);
  pinMode (LED6, OUTPUT);
  pinMode (LED7, OUTPUT);
  pinMode (LED8, OUTPUT);
  pinMode (LED9, OUTPUT);
  pinMode (LED10, OUTPUT);
}

void loop(){ 
  if(digitalRead(SIGNAL_PIN)==HIGH) {
    
// Pattern 1    
  
  digitalWrite(LED1, HIGH);
  delay(speed1);
  digitalWrite(LED1, LOW);
  delay(speed1);

  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  delay(speed1);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  delay(speed1);
  
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  delay(speed1);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(speed1);
  
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  delay(speed1);
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  delay(speed1);
  
  digitalWrite(LED8, HIGH);
  delay(speed1);
  digitalWrite(LED8, LOW);
  delay(speed1);
  
  digitalWrite(LED9, HIGH);
  digitalWrite(LED10, HIGH);
  delay(speed1);
  digitalWrite(LED9, LOW);
  digitalWrite(LED10, LOW);
  delay(speed1);
    
// Pattern 2    

  digitalWrite(LED9, HIGH);
  digitalWrite(LED10, HIGH);
  delay(speed2);
  
  digitalWrite(LED8, HIGH);
  delay(speed2);
  
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  delay(speed2);
  
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  delay(speed2);
  
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  delay(speed2);
  
  digitalWrite(LED1, HIGH);
  delay(speed2);
  
  digitalWrite(LED9, LOW);
  digitalWrite(LED10, LOW);
  delay(speed2);
  
  digitalWrite(LED8, LOW);
  delay(speed2);
  
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  delay(speed2);
  
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(speed2);
  
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  delay(speed2);
  
  digitalWrite(LED1, LOW);
  delay(speed2);
  
// Pattern 3 x 3
    
  digitalWrite(LED1,HIGH);
  delay(speed3);
  digitalWrite(LED1,LOW);
  delay(speed3);
  
  digitalWrite(LED2,HIGH);
  delay(speed3);
  digitalWrite(LED2,LOW);
  delay(speed3);
    
  digitalWrite(LED4,HIGH);
  delay(speed3);
  digitalWrite(LED4,LOW);
  delay(speed3);
    
  digitalWrite(LED6,HIGH);
  delay(speed3);
  digitalWrite(LED6,LOW);
  delay(speed3);
    
  digitalWrite(LED9,HIGH);
  delay(speed3);
  digitalWrite(LED9,LOW);
  delay(speed3);
    
  digitalWrite(LED8,HIGH);
  delay(speed3);
  digitalWrite(LED8,LOW);
  delay(speed3);
    
  digitalWrite(LED10,HIGH);
  delay(speed3);
  digitalWrite(LED10,LOW);
  delay(speed3);
    
  digitalWrite(LED7,HIGH);
  delay(speed3);
  digitalWrite(LED7,LOW);
  delay(speed3);
    
  digitalWrite(LED5,HIGH);
  delay(speed3);
  digitalWrite(LED5,LOW);
  delay(speed3);
    
  digitalWrite(LED3,HIGH);
  delay(speed3);
  digitalWrite(LED3,LOW);
  delay(speed3);
    
  digitalWrite(LED1,HIGH);
  delay(speed3);
  digitalWrite(LED1,LOW);
  delay(speed3);
  
  digitalWrite(LED2,HIGH);
  delay(speed3);
  digitalWrite(LED2,LOW);
  delay(speed3);
    
  digitalWrite(LED4,HIGH);
  delay(speed3);
  digitalWrite(LED4,LOW);
  delay(speed3);
    
  digitalWrite(LED6,HIGH);
  delay(speed3);
  digitalWrite(LED6,LOW);
  delay(speed3);
    
  digitalWrite(LED9,HIGH);
  delay(speed3);
  digitalWrite(LED9,LOW);
  delay(speed3);
    
  digitalWrite(LED8,HIGH);
  delay(speed3);
  digitalWrite(LED8,LOW);
  delay(speed3);
    
  digitalWrite(LED10,HIGH);
  delay(speed3);
  digitalWrite(LED10,LOW);
  delay(speed3);
    
  digitalWrite(LED7,HIGH);
  delay(speed3);
  digitalWrite(LED7,LOW);
  delay(speed3);
    
  digitalWrite(LED5,HIGH);
  delay(speed3);
  digitalWrite(LED5,LOW);
  delay(speed3);
    
  digitalWrite(LED3,HIGH);
  delay(speed3);
  digitalWrite(LED3,LOW);
  delay(speed3);
    
  digitalWrite(LED1,HIGH);
  delay(speed3);
  digitalWrite(LED1,LOW);
  delay(speed3);
  
  digitalWrite(LED2,HIGH);
  delay(speed3);
  digitalWrite(LED2,LOW);
  delay(speed3);
    
  digitalWrite(LED4,HIGH);
  delay(speed3);
  digitalWrite(LED4,LOW);
  delay(speed3);
    
  digitalWrite(LED6,HIGH);
  delay(speed3);
  digitalWrite(LED6,LOW);
  delay(speed3);
    
  digitalWrite(LED9,HIGH);
  delay(speed3);
  digitalWrite(LED9,LOW);
  delay(speed3);
    
  digitalWrite(LED8,HIGH);
  delay(speed3);
  digitalWrite(LED8,LOW);
  delay(speed3);
    
  digitalWrite(LED10,HIGH);
  delay(speed3);
  digitalWrite(LED10,LOW);
  delay(speed3);
    
  digitalWrite(LED7,HIGH);
  delay(speed3);
  digitalWrite(LED7,LOW);
  delay(speed3);
    
  digitalWrite(LED5,HIGH);
  delay(speed3);
  digitalWrite(LED5,LOW);
  delay(speed3);
    
  digitalWrite(LED3,HIGH);
  delay(speed3);
  digitalWrite(LED3,LOW);
  delay(speed3);
    
// Pattern 2 x 2
    
   digitalWrite(LED9, HIGH);
  digitalWrite(LED10, HIGH);
  delay(speed2);
  
  digitalWrite(LED8, HIGH);
  delay(speed2);
  
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  delay(speed2);
  
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  delay(speed2);
  
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  delay(speed2);
  
  digitalWrite(LED1, HIGH);
  delay(speed2);
  
  digitalWrite(LED9, LOW);
  digitalWrite(LED10, LOW);
  delay(speed2);
  
  digitalWrite(LED8, LOW);
  delay(speed2);
  
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  delay(speed2);
  
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(speed2);
  
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  delay(speed2);
  
  digitalWrite(LED1, LOW);
  delay(speed2);
    

    
  digitalWrite(LED9, HIGH);
  digitalWrite(LED10, HIGH);
  delay(speed2);
  
  digitalWrite(LED8, HIGH);
  delay(speed2);
  
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  delay(speed2);
  
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  delay(speed2);
  
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  delay(speed2);
  
  digitalWrite(LED1, HIGH);
  delay(speed2);
  
  digitalWrite(LED9, LOW);
  digitalWrite(LED10, LOW);
  delay(speed2);
  
  digitalWrite(LED8, LOW);
  delay(speed2);
  
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  delay(speed2);
  
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  delay(speed2);
  
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  delay(speed2);
  
  digitalWrite(LED1, LOW);
  delay(speed2);
    
  if(digitalRead(SIGNAL_PIN)==LOW)
    
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, LOW);
  digitalWrite(LED5, LOW);
  digitalWrite(LED6, LOW);
  digitalWrite(LED7, LOW);
  digitalWrite(LED8, LOW);
  digitalWrite(LED9, LOW);
  digitalWrite(LED10, LOW);  
  }
} 

I fear that connecting 10 LEDs to Arduino has required too much current. Remember that Arduino pins have a maximum current output value each, but also a limit for the total. For example, if each LED has a potential drop of 2 V, with a 220 Ohm resistor the current required for the pin is about 13 mA (but this value could be much greater than that, it depends on the LED type, mainly the emitted colour).
If we turn on all 10 LEDs at the same time, the total current required would therefore be at least 130 mA which, added to the current required for the PIR, probably exceeds the approximately 200 mA total that Arduino can handle.

In this case I think that unfortunately you have fried Arduino, buy another one, and to control 10 LEDs use an external source and transistors: connect the LEDs to an external 5V power supply and use a transistor to drive them (normal 2N2222, or BC547, are also fine).

As well as the power issue, it looks like you need a curly bracket immediately after your if():

 if(digitalRead(SIGNAL_PIN)==LOW)
    
  digitalWrite(LED1, LOW);
etc

Other possibilities include an intermttent wiring connection.

Thanks docdoc,
I had been warned about this possibility before, but perhaps wrongly assumed that increasing the resistor value from an earlier planned version would reduce the danger of this occurring. Would changing the resistors for some of a higher value (680 ohms for example) protect against this problem, or have I misunderstood completely?

I'd like to try again also using the setup you suggest. Does this mean that the project required two completely separate power supplies, or can I still run everything from the supply I've used until now (a mains adapter with USB socket, 5V output, 2.4A). A little bit a guidance about how the transistors can be introduced into the circuit would be very greatfully received too :slightly_smiling_face:

This

avrdude: stk500_recv(): programmer is not responding

is one of those things that can just happen.

Before you scrap you Nano, try everything.

  • restart your machine
  • try a different cable
  • try a different port

I've had weeks where uploading is dicey to the point where I want to give up this stupid hobby followed by months where everything just worked.

As for the possibility that you burned out the board, if your LEDs are in fact white with Vf of 3.3, the current each takes is but 7.7 mA, well below the recommended 20 mA which is already half the absolute maximum per pin.

The PIR sensors I have take almost no current if not sensing, and much less than 100 mA when operating. They are designed to be used in battery powered alarm systems, e.g., and are the controlling element that allows them to work for long periods between battery changes.

It could be the specifications are incorrect or you've used the wrong resistors inadvertently or otherwise damaged or changed something, I just think it's a bit early for a funeral.

You may not yet have meter or the knowledge needed to measure and see; it's fairly basic electronics and this would be a good time to have a decent DVM and an understanding of Ohm's Law. Both will come in handy as long as you play with electronics.

BTW keep this sketch handy. You are going to enjoy learning how to program and as you do, periodically get the sketch out and marvel.

a7

your Arduino Nano may be stuck in a bootloader state or could have been damaged. First, try pressing the reset button just before uploading the sketch; this can sometimes re-establish communication. If that doesn’t work, check your power supply and USB cable for any issues. If the issue persists, try using a different USB port or computer. You might also try using a USB-to-serial adapter to manually reset the board. If none of this works, there’s a possibility the Nano’s bootloader has been corrupted, or it could have been damaged due to a short circuit or over-voltage.

Could do the trick to drain less current, just use Ohm's law to know the current on a 2 V (approximated) LED voltage drop:
I = (Vpow - Vdrop)/R
With a 680 Ohm you get:
I = (5-2)/680 = 4.4 mA
But in this case the LEDs will get dimmer as the resistance increases, so I'm not pretty sure you want this to happen.

No, you can still use the same power supply to bring 5V to the LEDs (and not from the Arduino 5V pin): just keep the 220 Ohm resistor to limit LED current, then use the transistor (through a resistor going from the pin to the base) as a switch to control each LED. Searching the net you'll find dozen of schematics.

Let's circle back to this cleaner solution

@dandesign70
As you've seen from others there are other possible causes. But with the correction I pointed out your code (wired as per your nice schematic) works fine here.

What is this "5V via USB cable"?
Was it connected to a PC/laptop?

UPDATE! Bizarrely the project suddenly started working again a little later, then stopped again after a period of problem-free operation. It was connected to power source the whole time. When operational the 'L' LED was not lit - now that it is (again) not seemingly working, the 'L' LED is again also lit.... Very strange.

Does the Nano have some kind of protective function that could limit it's operation in this way? I'm thinking about some kind of circuit protection perhaps....

See post #10

Yes it has a resettable fuse but you would need to draw much more current than you are for it to trip. So maybe the resistor values you think you have are wrong.

A mains adapter with a usb outlet (similar to a mobile charger) providing 5V DC, 2.4A - connected to the Nano's mini b usb socket.

Interesting. Is this resettable fuse is an internal, automatic function controlled by the Arduino itself - ie not user controllable?

That is correct, if you draw too much current it heats up and trips, then takes a while to cool down and reset but as I said your would have to draw oner 500mA to trip the fuse so there is something wrong in your design.

Hmm, I have no idea where that could be coming from, apart perhaps from the resistors rating being too low. I'm pretty sure I used 220 ohm resistors, which according to the resistance calculator I'm using should give a maximum current draw (from the 10 LEDs) of 90mA...

As another forum user has pointed out, the pir sensor is much less than 100mA when working.

That would be my guess.
Did you measure them with an ohmmeter?
What are the color markings on them?

Maybe that fuse is the thing. I've never tripped one but I have destroyed things that get destroyed before the fuse helps.

But the board coming back to life means you haven't. And it should not take the polyfuse very long to reset, so if you were in the dark for very long it might be the thing.

Make sure all your connections are secure and correct. Confirm the resistor values. Switch, for the moment, to 470 or 680.

How are you delaing with all the parts mechanically? Check for inadvertent short circuits from long bare LED leads on a breadboard, for example.

a7

What LED calculator or equation are you using? Do you really have white LEDs? Do you have a part number?

Your diagram states a Vf of 3.3. So 220 ohms would draw 7.7 mA each or 77 mA all ten on.

But there is no substitute for measuring.

a7