Pages: [1]   Go Down
Author Topic: motor rotation limit  (Read 898 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so this is what i have so far but i can't seem to get the motor to rotate once, stop by the means of a rocker switch then continue. i can only get it to stop 



Code:
const int buttonPin = 4;
int val = 0;

void setup() {
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(buttonPin, INPUT);
}

void loop() {
  val = digitalRead(buttonPin);
  if (val == LOW) {
                           //forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
  }
  else {
 
  digitalWrite(9, HIGH); //Engage the Brake for Channel A

  delay (2000);        // delay for set amount of time
                        // then repeat the whole thing
                           
  }
   
}
Logged

0
Offline Offline
Shannon Member
****
Karma: 214
Posts: 12412
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What motor?  What shield/controller?  How are you measuring its position?  What is the motor actually doing?
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 394
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you need to move the 'delay(2000)'  outside the else block.
Also you should provide more circuit info.

Logged

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would appear that if you start the sketch with the motor positioned on the switch then the sketch just continues to run the stop code.

val = digitalRead(buttonPin);
  if (val == LOW) {

if val is already high then this code will never run. So - the motor runs until it trips the switch and stops, and if the switch is still tripped the motor will never start again.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have a r3 motor shield on top of an arduino uno, the motor is a 3-12 volt motor with a gear box on it to make it run at 15 rpm. the position is measured by a roller tack switch. the motor as a 6in wheel on it with a hole cut in it to let an item drop

this is newest code i have
Code:
const int buttonPin = 4;

boolean lastButton = LOW;
boolean currentButton = LOW;
boolean switchon = false;



void setup() {
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(buttonPin, INPUT);
}
boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
   switchon = !switchon;   
  }
    lastButton = currentButton;                   
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, !switchon);   //Disengage the Brake for Channel A
  analogWrite(3, 255);

   
}
« Last Edit: August 16, 2013, 06:59:45 pm by bengrvr » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

should i use a interrupt to make this work instead or is that not necessary
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have a r3 motor shield on top of an arduino uno, the motor is a 3-12 volt motor with a gear box on it to make it run at 15 rpm. the position is measured by a roller tack switch. the motor as a 6in wheel on it with a hole cut in it to let an item drop

this is newest code i have

So what are you using to stop the rotation a roller track switch or a rocker switch or are you reffering to the same switch?

Is pin 12 used to communicate with a shield? I ask because of:

Code:
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, !switchon);   //Disengage the Brake for Channel A

Surely you would reverse the order of this?

What about braking, are you using the DC braking of the motor itself or some other method?
« Last Edit: August 18, 2013, 12:15:50 am by charlie_smith87 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is what i have so far and it works to what i want

Code:
const int buttonPin = 4;
int val = 0;

void setup() {
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(buttonPin, INPUT);
}
boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}

void loop() {
  val = digitalRead(buttonPin);
  if (val == LOW) {
                           //forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
  }
  else {
 
  digitalWrite(9, HIGH); //Engage the Brake for Channel A

  delay (5000);        // delay for set amount of time
                        // then repeat the whole thin
   }
   
  val = digitalRead(buttonPin);
  if (val == LOW) {
                           //forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
  }
  else {
 
  digitalWrite(9, HIGH);
   
}
}
Logged

Pages: [1]   Go Up
Jump to: