int motorPin1a = 2; // pin 2 on Arduino int motorPin2a = 3; // pin 3 on Arduino int motorPin1b = 4; // pin 4 on Arduino int motorPin2b = 5; // pin 5 on Arduino int motorPin1c = 6; // pin 6 on Arduino int motorPin2c = 7; // pin 7 on Arduino int motorPin1d = 8; // pin 8 on Arduino int motorPin2d = 9; // pin 9 on Arduino int motorPin1e = 10; // pin 10 on Arduino int motorPin2e = 11; // pin 11 on Arduino int state; int flag=0; void setup() { // put your setup code here, to run once: pinMode(motorPin1a, OUTPUT); pinMode(motorPin2a, OUTPUT); //pinMode(enablePina, OUTPUT); // sets enablePin high so that motor can turn on: //digitalWrite(enablePina, HIGH); // initialize serial communication at 9600 bits per second: Serial.begin(9600); pinMode(motorPin1b, OUTPUT); pinMode(motorPin2b, OUTPUT); //pinMode(enablePinb, OUTPUT); //digitalWrite(enablePinb, HIGH); Serial.begin(9600); pinMode(motorPin1c, OUTPUT); pinMode(motorPin2c, OUTPUT); Serial.begin(9600); pinMode(motorPin1d, OUTPUT); pinMode(motorPin2d, OUTPUT); Serial.begin(9600); pinMode(motorPin1e, OUTPUT); pinMode(motorPin2e, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: //if some date is sent, reads it and saves in state if(Serial.available() > 0){ state = Serial.read(); flag=0; } // if the state is '0' the DC motor will turn off if (state == '0') { digitalWrite(motorPin1a, LOW); // set pin 2 on Arduino low digitalWrite(motorPin2a, LOW); // set pin 3 on Arduino low digitalWrite(motorPin1b, LOW); // set pin 4 on Arduino low digitalWrite(motorPin2b, LOW); // set pin 5 on Arduino low digitalWrite(motorPin1c, LOW); // set pin 6 on Arduino low digitalWrite(motorPin2c, LOW); // set pin 7 on Arduino low digitalWrite(motorPin1d, LOW); // set pin 8 on Arduino low digitalWrite(motorPin2d, LOW); // set pin 9 on Arduino low digitalWrite(motorPin1e, LOW); // set pin 10 on Arduino low digitalWrite(motorPin2e, LOW); // set pin 11 on Arduino low if(flag == 0){ Serial.println("Motor: off"); flag=1; } } // if the state is '1' the motor will turn right else if (state == '1') { digitalWrite(motorPin1a, LOW); // set pin 2 on Arduino low digitalWrite(motorPin2a, HIGH); // set pin 3 on Arduino high if(flag == 0){ Serial.println("Motor: right"); flag=1; } } // if the state is '2' the motor will turn left else if (state == '2') { digitalWrite(motorPin1a, HIGH); // set pin 2 on Arduino high digitalWrite(motorPin2a, LOW); // set pin 3 on Arduino low if(flag == 0){ Serial.println("Motor: left"); flag=1; } } // if the state is '3' the motor will turn up else if (state == '3') { digitalWrite(motorPin1b, LOW); // set pin 4 on Arduino low digitalWrite(motorPin2b, HIGH); // set pin 5 on Arduino high if(flag == 0){ Serial.println("Motor: up"); flag=1; } } // if the state is '4' the motor will turn down else if (state == '4') { digitalWrite(motorPin1b, HIGH); // set pin 4 on Arduino high digitalWrite(motorPin2b, LOW); // set pin 5 on Arduino low if(flag == 0){ Serial.println("Motor: down"); flag=1; } } // if the state is '3' the motor will turn up else if (state == '5') { digitalWrite(motorPin1c, LOW); // set pin 6 on Arduino low digitalWrite(motorPin2c, HIGH); // set pin 7 on Arduino high if(flag == 0){ Serial.println("Motor: up"); flag=1; } } // if the state is '4' the motor will turn down else if (state == '6') { digitalWrite(motorPin1c, HIGH); // set pin 6 on Arduino high digitalWrite(motorPin2c, LOW); // set pin 7 on Arduino low if(flag == 0){ Serial.println("Motor: down"); flag=1; } } // if the state is '3' the motor will turn up else if (state == '7') { digitalWrite(motorPin1d, LOW); // set pin 8 on Arduino low digitalWrite(motorPin2d, HIGH); // set pin 9 on Arduino high if(flag == 0){ Serial.println("Motor: up"); flag=1; } } // if the state is '4' the motor will turn down else if (state == '8') { digitalWrite(motorPin1d, HIGH); // set pin 8 on Arduino high digitalWrite(motorPin2d, LOW); // set pin 9 on Arduino low if(flag == 0){ Serial.println("Motor: down"); flag=1; } } // if the state is '3' the motor will open the claw else if (state == '9') { digitalWrite(motorPin1e, LOW); // set pin 10 on Arduino low digitalWrite(motorPin2e, HIGH); // set pin 11 on Arduino high if(flag == 0){ Serial.println("Claw: open"); flag=1; } } // if the state is '4' the motor will close the claw else if (state == '10') { digitalWrite(motorPin1e, HIGH); // set pin 10 on Arduino high digitalWrite(motorPin2e, LOW); // set pin 11 on Arduino low if(flag == 0){ Serial.println("Claw: Close"); flag=1; } } }