Go Down

Topic: Motor not responding on button click (Read 424 times) previous topic - next topic

srihari_unnikrishnan

Hey,
this is my code and my motor does not respond on button click. the circuit is alright and i am not able to diagnose it help.

Code: [Select]
#include <AFMotor.h>

AF_DCMotor Rmotor(4, MOTOR12_1KHZ); // create motor #2, 64KHz pwm
AF_DCMotor Lmotor(3, MOTOR12_1KHZ);
void setup() {
  pinMode(13, OUTPUT);    // Use Built-In LED for Indication
  pinMode(8, INPUT_PULLUP);
   
 
    Serial.begin(9600);
              // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  Rmotor.setSpeed(225);
  Lmotor.setSpeed(225);
}
 
void loop() {
 
  bool buttonState = digitalRead(8);
   if(buttonState){
    Lmotor.run(FORWARD);
    Rmotor.run(FORWARD);
   }
 
digitalWrite(13,buttonState);

   Serial.println(buttonState);
}
 

TomGeorge

Hi,
Welcome to the forum.

How have you got your button wired?

Can you please post a picture of your project?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What does your monitor show?

Tom... :)

Everything runs on smoke, let the smoke out, it stops running....

AWOL

What do your debug prints tell you?

Robin2

For testing, try putting delay(500); into loop(). I suspect you are sending too much stuff to the Serial Monitor and the Arduino is choking on it. Be aware that loop() repeats 1000 times per second or more.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up