Bad Nanos

Well, I am stumped.............I have been using Nanos for a lot of projects and never had any trouble. Now, I have a program that is for smaller radio control planes. It has a solid left and right nav light in each wing, a strobe in each wing, and one fading beacon. So, a total of 5 small smd led's. The Nano will run for various amounts of time, sometimes leds dim a little or turn off, then back on again in a random way. The board will shut down, start back up at random times. Nothing getting hot. I ran from usb, 8v, 12v, just like in the past but now???????? I reduced the current from 20 all the way down to 6ma on all the leds. Some of the boards can't be re-programmed after this happens a few times. I have the same program running on a Pro Mini for 2 days now, 24 hours a day with the leds at 20ma each and there are no problems. These are clones, but usually no problems. Is there a bad batch of these going around? I have some from as far back as 2014 all the way up to Dec of 2016. Now, I have lost even more of my mind : ( I posted the code which is a mess, but it works. It has a lot of commented out notes and different array setups, etc. Forgive the slop : ) Thanks for reading.

SMD_One_Wing_Strobe_And_One_Nav_Light.ino (2.13 KB)

Nothing jumps out as wrong with the code. Please post a schematic, pic of the nano, and link to where you got it from.

It could an electrical noise problem - if this is the same battery powering the motor or servos.

I have had this with Nanos fed from the same circuit as a pump - spikes were killing them after several
Occasions of causing restarts
I dropped voltage a bit with a couple of diodes on series with the power supply followed by a couple of capacitors.

Hi, Thanks. I am running this on the bench with no other components so I don't think it is noise (In this case) I will keep this in mind for the future though.

Is it an already " used"
nano you are playing with , it may be damaged in that case .

You can try programming it via the icsp comnector , or re loading the bootloader via it . I have had Nanos USB connection fail , but they are still usable via the icsp port

Can you post a pic of the nano, and link to where they came from? If you suspect there's a bad batch going around (which I am highly skeptical of), that information is useless without any way to identify which boards could be suspect.

Well, they are all from Ebay. I bought from several sellers and can't remember them. I have two of the boards that were acting up running now without any problem. The only thing I can figure is that when I soldered the pins/headers on the board, the flux cleaner may have found it's way into the chips???? If it did this, and took a day or two to completely get out? Sounds dumb but it is all I can think of?

long time=0;

 time = millis();

That's a mistake. The millis() function returns UNSIGNED long.

int period = 2000;
void loop()
{
 time = millis();
 value = 128+127*cos(2*PI/period*time);

I would worry about errors accumulating when 'time' gets into the millions or billions. I would try:

value = 128+127*cos((2*PI*(time%period)) / period);

That will limit the range to 0..2Pi.

There is no need to have 'time' and 'currentMillis' be separate variables.

//Use the default  16.5Mhz !!!!!!
//Hit "Upload" Wait til it says to plug in, THEN plug it in !!!
// yet another blink sketch by aarg, Arduino forum
//

unsigned long previousMillis = 0;

// circular list of intervals, alternating off and on
const unsigned long intervals[] = {60, 60, 60, 900,};
//const unsigned long intervals[] = {50, 50, 50, 1000, 10, 10};//try odd numbers here originally
//const unsigned long intervals[] = {100, 50, 100, 1000, 10, 10};
//const unsigned long intervals[] = {50, 50, 50, 800, 10, 10, 20, 30};//My favorite

const byte NUM_OF_INTERVALS = sizeof(intervals) / sizeof(unsigned long);
byte currentInterval = 0;

//int brightness = 30;    // how bright the LED is
//int fadeAmount = 10;    // how many points to fade the LED by

const int period = 2000;
// int displace = 500;

const byte White1Pin = 3;
const byte RedPin = 5;
const byte GreenPin = 4;
const byte White2Pin = 7;
const byte BeaconPin = 9;

void setup()
{
  pinMode(13, OUTPUT);
  //pinMode(Stro1, OUTPUT);
  pinMode(RedPin, OUTPUT);
  pinMode(White1Pin, OUTPUT);
  pinMode(GreenPin, OUTPUT);
  pinMode(White2Pin, OUTPUT);
  pinMode(BeaconPin, OUTPUT);
  digitalWrite(RedPin, HIGH);//I added this to start HIGH. Seems to work so far :  )
  digitalWrite(White1Pin, HIGH);
  digitalWrite(White2Pin, HIGH);
  digitalWrite(GreenPin, HIGH);
  //digitalWrite(Lpin2, HIGH);
}

void loop()
{
  unsigned long currentMillis = millis();          //get current value of millisecond counter

  int value = 128 + 127 * cos((2 * PI * (currentMillis % period)) / period);
  analogWrite(BeaconPin, value);           // sets the value (range from 0 to 255)

  if (currentMillis - previousMillis >= intervals[currentInterval])  //if the time interval has elapsed
  {
    currentInterval = currentInterval + 1;     // select the next interval in the list
    if (currentInterval >= NUM_OF_INTERVALS)
      currentInterval = 0;
    digitalWrite(White1Pin, not digitalRead(White1Pin));    //change state of the LED
    digitalWrite(White2Pin, not digitalRead(White2Pin));
    previousMillis = currentMillis;                //save the time of change
  }
}