I am a beginner in Arduino. Below is my code to propel the fans of my motor. This happens in a clockwise direction but I wish to change the direction of rotation.

How can I modify it?

// Declare the pin for the motor
int motorPin = 9;

void setup() {
  // Define pin #9 as output
  pinMode(motorPin, OUTPUT);

void loop() {
  // Turn motor on
  digitalWrite(motorPin, HIGH);
  // Wait 250 ms
  // Reanimate motor
  digitalWrite(motorPin, HIGH);
  // Wait 250 ms
  // Turn motor off.
  • can you please tell something about your motor i.e. datasheet, name of some schematics?
    – ARK
    Apr 19, 2016 at 6:12
  • Rewrite your code. Your code doesn't even turn off your motor. Then tell us, which shield you are using for motor control and give us information about your wiring. Without further information nobody will be able to answer your question.
    – Ariser
    Apr 19, 2016 at 7:31
  • Swap the wires over? Apr 19, 2016 at 9:03

1 Answer 1


I guess you have a DC motor in use. Likely a FET drives it on port 9.

This arrangement is enough to start or stop the motor, however to change direction, you need to swap the two wires on the motor.

I guess you may perfer to do this in software - and for that you need to replace the simple FET driver with a H-Bridge. H-Bridge is an arrangement of electric switches which allows you swapping motor polarity, and it usually comes pre-assembled to a chip.

There are a vast amount of h-bridge motor driver chips to choose from. Google for "pololu motor driver", or "adafruit motor driver".

You can find all the further details in the Arduino examples on the web, e.g.:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.