First Project - Check for errors?

This is my first Arduino project as well electronics. The circuit is working just as I would like it to, but I was wondering if I have made any blatant wiring mistakes or inefficiencies.

int buttonPin = 12;     
int ledPin1 =  13;
int ledPin2 =  11; 
int ledPin3 =  10; 
int ledPin4 =  9; 
int motorPin1 = 2;
int motorPin2 = 8;
int motorPin3 = 7;
int motorPin4 = 6;
int motorPin5 = 5;
int motorPin6 = 4;
int motorPin7 = 3;
int buzzer = 1;

void setup() {
  
  pinMode(ledPin1, OUTPUT);  //Dev LED
  pinMode(ledPin2, OUTPUT);  //Blix LED
  pinMode(ledPin3, OUTPUT);  //Rinse LED
  pinMode(ledPin4, OUTPUT);  //Finish LED
  pinMode(buttonPin, INPUT); //Button
  pinMode(motorPin1, OUTPUT);  // setup Agitation Pump
  pinMode(motorPin2, OUTPUT);  // setup Dev IN Pump
  pinMode(motorPin3, OUTPUT);  // setup Dev OUT Pump
  pinMode(motorPin4, OUTPUT);  // setup Blix IN Pump
  pinMode(motorPin5, OUTPUT);  // setup Blix OUT Pump
  pinMode(motorPin6, OUTPUT);  // setup Rinse IN Pump
  pinMode(motorPin7, OUTPUT);  // setup Rinse OUT Pump
  pinMode(buzzer, OUTPUT); // Set buzzer 
}

void loop() {

  while (digitalRead(buttonPin) == HIGH) {
    
    //Dev
    
    digitalWrite(ledPin1, HIGH);  //Turn on Dev Process Led 
    
    analogWrite(motorPin2, 200);  //Dev IN Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin2, 0);
    
    delay(3000);              //Start Process Timer
    
    analogWrite(motorPin1, 200);  //Agitate for 3 Seconds
   delay(3000);
   analogWrite(motorPin1, 0);
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin3, 200);  //Dev OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin3, 0);
  
    digitalWrite(ledPin1, LOW);  //End Dev Process LED
    
    //BLIX
    
     digitalWrite(ledPin2, HIGH);  //Turn on Blix Process Led 
    
    analogWrite(motorPin4, 200);  //Blix IN Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin4, 0);
    
    delay(3000);              //Start Process Timer
    
    analogWrite(motorPin1, 200);  //Agitate for 3 Seconds
   delay(3000);
   analogWrite(motorPin1, 0);
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin5, 200);  //Blix OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin5, 0);
  
    digitalWrite(ledPin2, LOW);  //End Blix Process LED
    
    //RINSE
    
     digitalWrite(ledPin3, HIGH);  //Turn on Rinse Process Led 
    
    analogWrite(motorPin6, 200);  //Rinse IN Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin6, 0);
    
    delay(3000);              //Start Process Timer
    
    analogWrite(motorPin1, 200);  //Agitate for 3 Seconds
   delay(3000);
   analogWrite(motorPin1, 0);
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin7, 200);  //Rinse OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin7, 0);
  
    digitalWrite(ledPin3, LOW);  //End Rinse Process LED
    
    //Finished!
    
    digitalWrite(ledPin4, HIGH);  //Turn on Finished Led 
    
    tone(buzzer, 1000); // Send 1KHz sound signal...
   delay(500);        // ...for 1 sec
   noTone(buzzer);     // Stop sound...
   delay(1000);        // ...for 1sec
    }
  
}

|500x296

In your case, you might be able to get away with using the delay() function, but in general, it is not good to use (it is a blocking loop function). Google "blink without delay".

You could also use a while or for loop to do the pinMode() setup provided either all of the pins are consecutive or all pin numbers are part of an array. Let me know if that's not clear.

It might be overkill, but you could use debouncing on your pushbutton.

You could also use a single function for turning on a given motor, running for 3 sec and then turning off. The motor pin would be the argument to the function. That way, you could just make one function call per motor instead of rewriting those three lines every time you want to turn on and off a given motor.

Power_Broker:
You could also use a single function for turning on a given motor, running for 3 sec and then turning off. The motor pin would be the argument to the function. That way, you could just make one function call per motor instead of rewriting those three lines every time you want to turn on and off a given motor.

Can you help with this part? I am running into troubles with the motorpin as the argument.

I can't seem to get this to work, I get this error:

45:15: error: 'motorpin2' was not declared in this scope

int buttonPin = 12;     
int ledPin1 =  13;
int ledPin2 =  11; 
int ledPin3 =  10; 
int ledPin4 =  9; 
int motorPin1 = 2;
int motorPin2 = 8;
int motorPin3 = 7;
int motorPin4 = 6;
int motorPin5 = 5;
int motorPin6 = 4;
int motorPin7 = 3;
int buzzer = 1;





void setup() {
  
  pinMode(ledPin1, OUTPUT);  //Dev LED
  pinMode(ledPin2, OUTPUT);  //Blix LED
  pinMode(ledPin3, OUTPUT);  //Rinse LED
  pinMode(ledPin4, OUTPUT);  //Finish LED
  pinMode(buttonPin, INPUT); //Button
  pinMode(motorPin1, OUTPUT);  // setup Agitation Pump
  pinMode(motorPin2, OUTPUT);  // setup Dev IN Pump
  pinMode(motorPin3, OUTPUT);  // setup Dev OUT Pump
  pinMode(motorPin4, OUTPUT);  // setup Blix IN Pump
  pinMode(motorPin5, OUTPUT);  // setup Blix OUT Pump
  pinMode(motorPin6, OUTPUT);  // setup Rinse IN Pump
  pinMode(motorPin7, OUTPUT);  // setup Rinse OUT Pump
  pinMode(buzzer, OUTPUT); // Set buzzer 

}

void loop() {

  while (digitalRead(buttonPin) == HIGH) {
    
    //Dev
    
    digitalWrite(ledPin1, HIGH);  //Turn on Dev Process Led 
    
    pumpINfxn(motorpin2);
    
    delay(3000);              //Start Process Timer
    
    agitate();                    //Agitate Function
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin3, 200);  //Dev OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin3, 0);
  
    digitalWrite(ledPin1, LOW);  //End Dev Process LED
    
    //BLIX
    
     digitalWrite(ledPin2, HIGH);  //Turn on Blix Process Led 
    
    analogWrite(motorPin4, 200);  //Blix IN Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin4, 0);
    
    delay(3000);              //Start Process Timer
    
    agitate();
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin5, 200);  //Blix OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin5, 0);
  
    digitalWrite(ledPin2, LOW);  //End Blix Process LED
    
    //RINSE
    
     digitalWrite(ledPin3, HIGH);  //Turn on Rinse Process Led 
    
    analogWrite(motorPin6, 200);  //Rinse IN Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin6, 0);
    
    delay(3000);              //Start Process Timer
    
    agitate();
    
    delay(3000);              //Continue Process Timer
    
    analogWrite(motorPin7, 200);  //Rinse OUT Pump run for 3 seconds
   delay(3000);
   analogWrite(motorPin7, 0);
  
    digitalWrite(ledPin3, LOW);  //End Rinse Process LED
    
    //Finished!
    
    digitalWrite(ledPin4, HIGH);  //Turn on Finished Led 
    
    tone(buzzer, 1000); // Send 1KHz sound signal...
   delay(500);        // ...for 1 sec
   noTone(buzzer);     // Stop sound...
   delay(1000);        // ...for 1sec
    }
   
}




  //Functions
  void agitate(){
    analogWrite(motorPin1, 200);  //Agitate for 3 Seconds
   delay(3000);
   analogWrite(motorPin1, 0);
  }

 void pumpINfxn(char pump) {
    analogWrite(pump, 200);  //Run Pump for 3 seconds
   delay(3000);
   analogWrite(pump, 0);
  }

Got it!

int buttonPin = 12;     
int ledPin1 =  13;
int ledPin2 =  11; 
int ledPin3 =  10; 
int ledPin4 =  9; 
int motorPin1 = 2;
int motorPin2 = 8;
int motorPin3 = 7;
int motorPin4 = 6;
int motorPin5 = 5;
int motorPin6 = 4;
int motorPin7 = 3;
int buzzer = 1;




void setup() {
  
  pinMode(ledPin1, OUTPUT);  //Dev LED
  pinMode(ledPin2, OUTPUT);  //Blix LED
  pinMode(ledPin3, OUTPUT);  //Rinse LED
  pinMode(ledPin4, OUTPUT);  //Finish LED
  pinMode(buttonPin, INPUT); //Button
  pinMode(motorPin1, OUTPUT);  // setup Agitation Pump
  pinMode(motorPin2, OUTPUT);  // setup Dev IN Pump
  pinMode(motorPin3, OUTPUT);  // setup Dev OUT Pump
  pinMode(motorPin4, OUTPUT);  // setup Blix IN Pump
  pinMode(motorPin5, OUTPUT);  // setup Blix OUT Pump
  pinMode(motorPin6, OUTPUT);  // setup Rinse IN Pump
  pinMode(motorPin7, OUTPUT);  // setup Rinse OUT Pump
  pinMode(buzzer, OUTPUT); // Set buzzer 

}

void loop() {

  while (digitalRead(buttonPin) == HIGH) {
    
    //Dev
   
    digitalWrite(ledPin1, HIGH);  //Turn on Dev Process Led  
    pumpINfxn(motorPin2);       //Dev IN Pump run for 3 seconds
    
    delay(3000);               //Start Process Timer
    agitatefxn();                  //Agitate Function
    delay(3000);               //Continue Process Timer
    
    pumpOUTfxn(motorPin3);         //Dev OUT Pump run for 3 seconds
    digitalWrite(ledPin1, LOW);  //End Dev Process LED
    
    //BLIX
    
    digitalWrite(ledPin2, HIGH);  //Turn on Blix Process Led 
    pumpINfxn(motorPin4);       //BLIX IN Pump run for 3 seconds

    delay(3000);               //Start Process Timer
    agitatefnx();
    delay(3000);               //Continue Process Timer
    
    pumpOUTfxn(motorPin5);         //Bix OUT Pump run for 3 seconds
    digitalWrite(ledPin2, LOW);  //End Blix Process LED
    
    //RINSE
    
    digitalWrite(ledPin3, HIGH);  //Turn on Rinse Process Led 
    pumpINfxn(motorPin6);       //Rinse IN Pump run for 3 seconds

    delay(3000);               //Start Process Timer
    agitatefnx();
    delay(3000);               //Continue Process Timer
    
    pumpOUTfxn(motorPin7);         //Rinse OUT Pump run for 3 seconds
    digitalWrite(ledPin3, LOW);  //End Rinse Process LED
    
    //Finished!
    
    digitalWrite(ledPin4, HIGH);  //Turn on Finished Led 
    
    tone(buzzer, 1000);        // Send 1KHz sound signal...
   delay(500);                 
   noTone(buzzer);            // Stop sound...
   delay(1000);        
    }
   
}

  //Functions
  void agitatefxn(){            //Agitate for 3 Seconds
    analogWrite(motorPin1, 200);  
   delay(3000);
   analogWrite(motorPin1, 0);
  }

 void pumpINfxn(char pump) {    //Run Pump IN for 3 seconds
    analogWrite(pump, 200);  
   delay(3000);
   analogWrite(pump, 0);
  }

void pumpOUTfxn(char pump) {    //Run Pump OUT for 3 seconds
    analogWrite(pump, 200);  
   delay(3000);
   analogWrite(pump, 0);
  }

Add 1000uF and 100nF decoupling on the motor power buses.

And, time to learn how to draw a proper schematic :wink:

2017-02-03_12-46-13.jpg

Is this the correct placement of the decoupling caps?

|500x307

You have 3 buses. Each bus should have a large and small capacitor. You might be ok with 470uF instead of the 1000uF.

This is for noisy filtering.

Sometimes you need a 100nF cap at the terminals of each motor.

Other times 100nF from each motor terminal to the metal housing of each motor. .

Hi,

int motorPin1 = 2;
int motorPin2 = 8;
int motorPin3 = 7;
int motorPin4 = 6;
int motorPin5 = 5;
int motorPin6 = 4;
int motorPin7 = 3;

If you are using a UNO, and you are analogwrite to pins 2 to 8, I think you will find that only pins 3,5,6 are capable of PWM.

Tom... :)