Go Down

Topic: Project 10 - Zoetrope , The motor spin in only one direction (Read 4536 times) previous topic - next topic


Hi at all, I got a little problem in the project 10, the enable button works, the potentiometer too but there is a problem with the direction... the spin only in one direction, in the other it stops. That's the code:
Code: [Select]

const int controlPin1=2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStatePin = 5;
const int potPin = A0;

int onOffSwitchState=0;
int previousOnOffSwitchState=0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;

int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;

void setup()
  digitalWrite(enablePin, LOW);

void loop()
  onOffSwitchState = digitalRead(onOffSwitchStatePin);
  motorSpeed = analogRead(potPin)/4;
  if(onOffSwitchState != previousOnOffSwitchState)
    if(onOffSwitchState == HIGH)
      motorEnabled = !motorEnabled;
  if(directionSwitchState != previousDirectionSwitchState)
    if(directionSwitchState == HIGH)
      motorDirection = !motorDirection;
  if(motorDirection == 0)
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin2, LOW);
    Serial.println("Direction 1 (The motor turn)");
    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, HIGH);
    Serial.println("Direction 2(The motor doesn't turn)");
  if(motorEnabled == HIGH)
    analogWrite(enablePin, motorSpeed);
    analogWrite(enablePin , 0);
  previousDirectionSwitchState = directionSwitchState;

Arduino switch correctly between the and and else of the direction because on the serial monitor I see both the message(direction 1 and direction 2) but in the direction 2 the motor doesn't turn. I tried to reverse HIGH and LOW and I realized that the motor  never turn when the controlPin1 is LOW and the controlPin2 is HIGH. Where is the problem?

In the attached I there are the photo of the breadboard. Thank you in advance and sorry for bad language, I''m not english :D


I have the exact same problem.  Anyone, please help.


from my understanding, the buttons work as described and you can see that on the monitor. I would suspect there could be a wiring problem on your circuit. I hooked up the project last night and all works fine without any problem. however, I didn't have time to reproduce your problem... still think it could be a wiring issue. try rewiring the project.  8)


Hi all of you with this problem.

I just copied and pasted your code in my board and everything run perfectly.

It's most probably a wiring problem. Double check all the wires go to the exact pins. Also remember that if you did connect the battery before powering the arduino board you might have burnt the H-bridge or motor controller.


Hi everyone
I also just copied the code and uploaded it to the Arduino board. Everything works just fine. I noticed however that the potentiometer and the switches easily goes loose on the breadboard. (I use the components from the Arduino Starter Project).

Go Up