Order for trouble shooting

I have a project I completed a while back and everything was working. It was sitting around for a while and I took it out again, but it is now not working. I checked the inputs which are working and the led's are still working. I also re-uploaded the code. It is on shield and when I take my multimeter to the shield it is reading power. I just do not know what my next step would be. What should I check next, or any idea what the issue could be?

Since you've given us no idea what the project is it's difficult to make many sensible suggestions.

Can you add Serial.prints so you can see where it's getting to in the program?

Steve

Thanks Steve,

Here is the code:

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPin0 = A0;  // Analog input pin that the potentiometer is attached to
const int analogInPin1 = A1;  // Analog input pin that the potentiometer is attached to
const int analogInPin2 = A2;  // Analog input pin that the potentiometer is attached to
const int analogInPin3 = A3;  // Analog input pin that the potentiometer is attached to


const int analogOutPin = (random (0,15)); // Analog output pin that the LED is attached to

int sensorValue0 = 0;        // value read from the pot
int sensorValue1 = 0;        // value read from the pot
int sensorValue2 = 0;        // value read from the pot
int sensorValue3 = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)


// have we already shown the animation for this visitor
int animationShown = 0; // 1=yes, and 0=no

// we have ten light outputs 0-15
// and they're connected to D2-D11
// For each light, remember whether it's on or off
int lightValue[10];

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);

  turnOffAllLights();

  
  // Set all pins to be outputs (by default they are all inputs)

  
}


// give it a light number from 0 to 9
// if it's on turn it off, and vice versa
void flipALight(int whichLight) {
  if (lightValue[whichLight] == 0) {
    lightValue[whichLight] = 1;
  }
  else {
    lightValue[whichLight] = 0;
  }
  digitalWrite(whichLight + 2, lightValue[whichLight]);
}

// turn off all the lights
void turnOffAllLights() {
  int counter;
  for (counter = 8; counter <= 12; counter = counter + 1) {
    // start off assuming all lights are off
    lightValue[counter] = 0; // 0 means off and 1 means on
    pinMode(counter + 2, OUTPUT); // make this pin an output
    digitalWrite(counter + 2, 0);
  }
}
void doTheBlinkyThing(){
  int randomlight;
  randomlight = random(0,13);
  flipALight(randomlight);
  delay(20);
}


void loop() {
  // read the analog in value:
  sensorValue0 = analogRead(analogInPin0);
  sensorValue1 = analogRead(analogInPin1);
  sensorValue2 = analogRead(analogInPin2);
  sensorValue3 = analogRead(analogInPin3); 

  int totalSensorValue;
  totalSensorValue = sensorValue0 + sensorValue1 + sensorValue2 + sensorValue3;

  Serial.print("Total sensor is ");
  Serial.println(totalSensorValue);
  
  if (totalSensorValue < 2000) {
    turnOffAllLights();
    animationShown = 0;
  }
  else {
    // somebody is on the scale
    // show them the animation - unless they already saw it
    if (animationShown == 0) {
      int counter;
      for (counter = 0; counter <= 19; counter = counter + 1) {
        doTheBlinkyThing();
      } 
      animationShown = 1; 
    }
  }

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(2);
}

The project is a scale that lights up less at random to give people the illusion of being judged. It was working when I first put the piece together but it has been sitting around for a while and now that I am getting back to it something is not working. I was hoping there was just a general check list. I know my inputs and outputs are working. Also that Arduino is lighting up and the shield when I take the multimeter to it has power.

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Hi again Steve,

I have just realized that you were asking to me put serial.print in my code so that it can show up on my computer like with the output monitor. Where should I put that in my code?

It was working when I first put the piece together but it has been sitting around for a while and now that I am getting back to it something is not working

So what ever it is it is not the code. If that worked then it will always work. You have to look to the hardware for your fault.

We have no idea what constitutes working and what behaviour constitutes not working.

...
  int counter;
  for (counter = 8; counter <= 12; counter = counter + 1) {
    // start off assuming all lights are off
    lightValue[counter] = 0; // 0 means off and 1 means on
...

That snippet overruns the end of lightValue. Fixing that bug would be a good place to start.

...
  int randomlight;
  randomlight = random(0,13);
  flipALight(randomlight);
...

Ditto.

What should I check next?

An excellent question. In this case the answer is "What did I assume?" When the behaviour of a project does not make sense and you've run out of ideas you should carefully try to determine what assumptions you've made. In this case an assumption is "The code is correct." The assumption is based on previous casual observations. Which is certainly reasonable.

However, with C++ "is correct" is an extremely difficult conclusion to reach. The language not only allows unsafe side-effects, certain constructs facilitate them (like being able to easily overrun an array).

In the words of Red Green, "Remember, I'm pulling for you. We're all in this together." In other words, you're in good company. Everyone who's crossed paths with a C++ compiler has overrun an array. It's just an annoying right of passage.

Oh, and checking for power was a great way to start troubleshooting.

ashleygoodwyn:
I also re-uploaded the code.

That was not a good idea because now you cannot be 100% certain that the code on the Arduino is the same as it was when it was last working.

You need to tell us in as much detail as possible what the program used to do; what it actually does now; and what you now want it to do that is different from what it actually does.

The point of this is to avoid wasting time looking at parts of the program that are working OK.

Having said all that the most likely cause of a previously successful Arduino project failing to work will be something external to the Arduino - such as a loose connecting or a failed power supply.

...R

Hi,
Have you written some code to test the inputs and outputs individually, not your original code, but some simple test codes using Serial.print and your LED outputs?

Tom... :slight_smile: