Need help with project 10 - Can't figure out why

Hello, this is my first post here so please excuse improper placement of the thread or any specifics I might have missed.

I'm working on project 10 of the arduino UNO R3 project book, and believe to have followed everything to a T and can't figure out what's wrong, I've checked my wires, code, and nothing seems to work. Am I missing anything here? I'm inches away from skipping this project or completely re-wiring it again.

Link to the project in question - Project 10: Zoetrope – Programming in Arduino

The off-screen wire connects to A0.

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() {
  pinMode(directionSwitchPin, INPUT);
  pinMode(onOffSwitchStatePin, INPUT);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);

  digitalWrite(enablePin, LOW);

}

void loop() {
  onOffSwitchState =
    digitalRead(onOffSwitchStatePin);
   delay(1);
   directionSwitchState = 
    digitalRead(directionSwitchPin);
   motorSpeed = analogRead(potPin)/4;

   if(onOffSwitchState != previousOnOffSwitchState){
      if(onOffSwitchState == HIGH){
        motorEnabled = !motorEnabled;
      }
   }
   if (directionSwitchState !=
   previousDirectionSwitchState) {
    if (directionSwitchState == HIGH){
      motorDirection = !motorDirection;
    }
   }

   if (motorDirection == 1){
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin2, LOW);
   }

   else {
    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, HIGH);
    
   }
   if (motorEnabled == 1 ){
    analogWrite(enablePin, motorSpeed);
   }
   else{
    analogWrite(enablePin, 0);
   }
   previousDirectionSwitchState =
    directionSwitchState;
   previousOnOffSwitchState = onOffSwitchState;

}

Please post a link to that project. Most forum members will never have seen it, or maybe years ago and cannot remember it.

what’s the error or problems you’re encountering? Compiling, connecting, uploading or running the program ?

We need to understand exactly what you’re seeing or experiencing - then maybe able to help.

What problem are you getting in the result?

I'd say I'm having problems running the program, everything seems to check out but when I press the buttons on the project nothing seems to work, the motor doesn't turn on, etc.

Link to the project in question since it was mentioned

(Despite saying project 11 it is still a link to project 10)

Probably a loose contact...

Can you connect pin 1 and 2 of the ic to 5v and pin 7 to ground? First disconnect the yellow wires from Arduino...

The motor should run then...

You could also check whether your buttons are working... connect green wires to 5V...
If motor runs, button is not OK...

Or add a Serial.print(onOfSwitchState); in loop to see if a button press is received by the program.

You learn more with failure than success!

Learn about debugging code with serial print. You should then see that your code is functioning properly. Then get a multimeter and debug your circuit by checking that wires are the voltage they are supposed to be

Leaning towards a loose contact and / or button related issue right now, thanks for mentioning it.

I'm using the small provided button switches, which according to others generally have a hard time reaching deep enough into the breadboard to do anything, which I think is my main issue right now as I went through all of the ones I was provided in my kit and none of them worked for a simple "click the button and the light turns on" circuit.

For reference I used this video: Project #1, Circuit #1 (Arduino Starter Kit) - YouTube
and couldn't make it work, yet when I connected the resistor directly to the light and skipped over the button everything worked fine.

Replace the button with loose wires. A press is the same as touching the wires together. All a button is is a break in a circuit and a way to close the break!

It'll definitely look strange, but hopefully it'll work. Just finished up some other troubleshooting ideas and I'm certain it's the button switches just being button switches.

I think the idea with the switches was for it to be a toggle for the motor, to either turn it on / off, and to also reverse the rotation. I hope doing it this way won't mess with that too much?

2 wires is exactly the same as a button. Tap the ends together briefly and it is a momentary button. Join them together and it is a latching button. If joining in latching mode use a spare bit of breadboard to make the connection.

I did this for ages prior to bothering to buy some buttons. This is because my projects would use entirely different non breadboard friendly buttons and I couldn’t be bothered to wait for breadboard friendly buttons just to prototype

A DMM (multimeter) will reveal any button errors. It is also the most basic of debugging tools for electronics

image

Oops!

Look closer... the resistor is in 6... which os correct.

Yes. Hard to see without zooming all the way in.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.