How to increase the dc motor's speed(andFrequency)value more than255(and64KHZ)?

" How to increase the dc motor's speed value more than 255 ? and the frequency value more than MOTOR12_64KH at adafruit motor shield ? thanks "

Hi all,
I have some questions for you :

At my tank project, I am using 4 dc motors ,and 1 dc motor uses 9V-12V, with adafruit motor shield now. The weightness of my tank project is 6kg ;so I felt like these 4 ,9V-12V, dc motors' speed is not enough for a good acceletarion with this (0, 255) speed value at MOTOR12_64KH while we are writing our code at adafruit motor shield.

Thus, how to increase the dc motor's speed value more than 255 ? and the frequency value more than MOTOR12_64KH ? thanks.
If I put a better dc motor which uses more than 12V this speed of 255 speed value will be more efficient, that is to say, I will be able to observe more speed with a better dc motor with same coding ?

And, for a good acceleration to a 6kg tank's to move what kind of dc motor I should use ? I will be glad if you give me some advices ;and answer my above questions, thanks.

Not :
If you need information about adafruit motor shield I can give links here ;or you can check it from google too.

The 255 is just when the motor is full on, you can not get it better than that.
The frequency of PWM does not effect the speed of the motor.
Faster or more powerfully motors is what you need.

Hi, what is your project, what are you doing with the motors?
Increasing the 64kHz will not increase the speed of the motors, and as Mike has said, 255 is full power to them.
A picture of your project and a picture or CAD of your circuit in PDF, jpg or png would be help full.
At the moment you know how your project works and what you want it to do, the forum members don't, so you need to give us as much information, including pictures, so we can help you.

Tom...... :slight_smile:

This is one of my dc motor that I am using at my tank project for the movement of tank.

I am using 4 above picture dc motors for the movement at my tank project ;and there will be 1 more dc motor again ;and 4-6 servo motors ( total : 5 dc motors + 4-6 servo motors )

This is the small video to show you what I have encountered about speed :

Is this less speed happening because I am getting power with usb cable from my computer ( but when I connect it to 9V battery directly the speed is increasing visibly ? If so, I have some techical questions to you again :

I want to use 2 seperated DC power supply for the Arduino and the motors. I plan to use a 9V battery and connect it to arduino's dc jack; then I plan to use a parallel connected 9V batteries ( but I don't know how many I should need to control 4 dc motors for the movement of the tank ,and other extra one more dc motor for the firing system ;and as I mentioned there will be 4-6 servo motors too ). When I connect 2 different power supplies to my arduino and motor shieldİ my arduino might be affected from the motor shield's power supply ? I don'T know how these seperated power supplies are working at arduino.

I have read somewhere that was saying that " take off the ' JUMPER ' if you want to use ". What is the meaning of " JUMPER " at Arduino ?

These are the some of the questions I wanted to ask and learn;but there are more actually. Please someone helps me to understand these ;then I want to ask you guys more. Thank you very much really^^.

Not :
Adafruit motor shield can handle the voltages between 6V and 25V while arduino can handle maximum 18V so far I know ;but I don't know how much ampers they can handle both ( if I have written here something false , please adjust my mistake at this sentence ;or at any sentences ).

I am using " Adafruit motor shield + mega sensor shield on my arduino mega 2560 R3.

My one dc motor wanted ideal voltage is 9V or 12V.

I plan to use a 9V battery

Small rectangular battery? Bad idea, they have very limited capacity and are expensive.

then I plan to use a parallel connected 9V batteries

No never connects batteries directly in parallel, they charge / discharge each other. If you must then use a seriese diode on each battery, but you loose voltage like this.
Better get a clip of 8 AA batteries.

When I connect 2 different power supplies to my arduino and motor shield? my arduino might be affected from the motor shield's power supply ?

No they won't affect anything. You must make sure that the -ve terminals are connected together.

I have read somewhere that was saying that " take off the ' JUMPER ' if you want to use ". What is the meaning of " JUMPER " at Arduino ?

On the very early Arduinos there was jumper link that selected where the power is coming from. These days this switch is automatically done by the electronics. See attached pictures of jumpers.

jumper1.jpg

jumper2.jpg

1 Like

The motor shield may have a jumper that connects the motor driver chip to the Arduino's 5V.

If you do not remove this jumper and you connect 9 or 12V to the Motor Power Input, you'll be applying this directly to the Arduino's 5V buss and fry it. If you have not removed the jumper and haven't fried your Arduino, it is probably because a small rectangular 9V battery can't supply much power.

1 Like

I want to ask some more questions again to you now to clarify my mind ( thank you every much for answering my questions here patiently all the time ) :


When I take of this jumper ( at the above screenshot that is on my motor shield ) I can put 1 power supply to power shield and 1 power supply to my arduino at the same time without any problem, right ? thanks.

///////////////////////////////////////////////////////////////////////////////


Grumpy_Mike, what do you mean by " the -ve terminals should be connected together " , it will be like above picture ? if not, would you be more clear please ? thanks.

//////////////////////////////////////////////////////////////////////////////


One " 8 AA battery " is enough to move my 4 of above dc motor smoothly with a good acceleration that motor wants 9-12V ) ? I am asking because my tank weightness is 6 kg total, thanks.

//////////////////////////////////////////////////////////////////////////////

How much voltage and amper Arduino and motor shield solo itself handle ? thanks.

/////////////////////////////////////////////////////////////////////////////

Do you have any suggestions about what kind of dc motor I should use with how much rpm I need to move and accelerate my 6 kg tank ( for my tank project ) ? thanks.

Grumpy_Mike, what do you mean by " the -ve terminals should be connected together " , it will be like above picture ?

Yes.

How much voltage and amper Arduino and motor shield solo itself handle ?

No idea, have you a web site link it will say there.
Also the data sheet for the shield should answer the other question.

what kind of dc motor I should use with how much rpm I need

Not sure what you are asking. Recommending any one motor is a bit useless unless it is accessible for you. The RPM is not a parameter that affects the torque so I don't know what that has to do with it.

When I take of this jumper ( at the above screenshot that is on my motor shield ) I can put 1 power supply to power shield and 1 power supply to my arduino at the same time without any problem, right ? thanks.

Yes, that is the jumper I thought you were talking about. Take that off and you can power the motors with their own supply.

The grounds will be connected together through the motor shield, as long as you connect both leads to the Ext_Pwr pins.

As for the current, the two outer ICs are the motor driver chips; read the numbers and Google for the datasheets. I think that might be the same motor shield that I have, it has two L293D chips on it. They are rated at 600mA max, 1.2A peak.

However, without a heatsink, they may get quite hot at 600mA.

Friends, I have another problem now at my project. I have built a miniature testing robot to make easier to observe my coding results. I was writing some part of codes for movement and rotation with button control ;however I am living with some problems.

This is the miniature testing robot :


The problems I am living is that :
" When I click the button it takes time to respond to move motors and light the leds too ,while I continue to push the button, it stops moving then the motors moves again then stops again ". I don't know how to fix this problem. " Debounce " might help to fix this problem but I don't know how to apply successfully. When you are newbie and when you don2t know what to do ( which is right or not ) It is really hard to solve the problem ;and it is happening to me right now. You friends might help me please ? thanks.

This is a small video that shows my problem visually :

This the code I have written ( this is only the movement version ) :

#include <AFMotor.h>
	 
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor3(3, MOTOR12_64KHZ);   // create motor #2, 64KHz pwm
AF_DCMotor motor4(4, MOTOR12_64KHZ);   // create motor #1, 64KHz pwm


const int buttonPin1 = 18;     // the number of the pushbutton pin for tank movement  backward
const int buttonPin2 = 19;     // the number of the pushbutton pin for tank movement  forward
const int buttonPin3 = 20;     // the number of the pushbutton pin for tank body rotation  turn around 
// const int buttonPin4 = 21;     // the number of the pushbutton pin for tank firing mechanism motor  at BB firing


const int ledPin1 =  14;      // the number of the LED pin to check if the button works properly for tank movement  backward
const int ledPin2 =  15;      // the number of the LED pin to check if the button works properly for tank movement  forward
const int ledPin3 =  16;      // the number of the LED pin to check if the button works properly for tank body rotation  turn around 
// const int ledPin4 =  17;      // the number of the LED pin to check if the button works properly for tank firing mechanism motor  at BB firing

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status for tank body movement  backward
int buttonState2 = 0;         // variable for reading the pushbutton status for tank body movement  forward 
int buttonState3 = 0;         // variable for reading the pushbutton status for tank body rotation  turn around 
// int buttonState4 = 0;         // variable for reading the pushbutton status for tank firing mechanism motor  at BB firing

void setup() {
  
  Serial.begin(9600);           // set up Serial library at 9600 bps
	  
	  
	  motor1.setSpeed(255);     // set the speed to 200/255
          motor2.setSpeed(255);     // set the speed to 200/255
          motor3.setSpeed(255);
          motor4.setSpeed(255);
           
           pinMode(ledPin1, OUTPUT);        // initialize the LED1 pin as an output 
           pinMode(buttonPin1, INPUT);      // initialize the pushbutton pin as an input
           
           pinMode(ledPin2, OUTPUT);        // initialize the LED2 pin as an output:    
           pinMode(buttonPin2, INPUT);      // initialize the pushbutton pin as an input:
  
           pinMode(ledPin3, OUTPUT);        // initialize the LED3 pin as an output:    
           pinMode(buttonPin3, INPUT);      // initialize the pushbutton pin as an input:
           
/*  
  pinMode(ledPin4, OUTPUT);        // initialize the LED4 pin as an output:    
  pinMode(buttonPin4, INPUT);      // initialize the pushbutton pin as an input:
 */
}


     void loop() {
	  
       // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
       if (buttonState1 == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin1, LOW);  
    
     motor1.run(RELEASE);      // stopped
     motor2.run(RELEASE);      // stopped
     motor3.run(RELEASE);      // stopped
     motor4.run(RELEASE);      // stopped
     delay(1000);
     
  } 
  else {
	  digitalWrite(ledPin1, HIGH);
    
     motor1.run(BACKWARD);      // turn it on going backward
     motor1.setSpeed(255);
     motor2.run(BACKWARD);      // turn it on going backward
     motor2.setSpeed(255);
     motor3.run(BACKWARD);      // turn it on going backward
     motor3.setSpeed(225);
     motor4.run(BACKWARD);      // turn it on going backward
     motor4.setSpeed(255);
                               
     delay(1000);
    
    
  }
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);
       if (buttonState2 == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin2, LOW);  
    
     motor1.run(RELEASE);      // stopped
     motor2.run(RELEASE);      // stopped
     motor3.run(RELEASE);      // stopped
     motor4.run(RELEASE);      // stopped
     delay(1000);
     
  } 
  else {
	  digitalWrite(ledPin2, HIGH);
    
     motor1.run(FORWARD);      // turn it on going backward
     motor1.setSpeed(255);
     motor2.run(FORWARD);      // turn it on going backward
     motor2.setSpeed(255);
     motor3.run(FORWARD);      // turn it on going backward
     motor3.setSpeed(225);
     motor4.run(FORWARD);      // turn it on going backward
     motor4.setSpeed(255);
                               
     delay(1000);
    
    
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  // read the state of the pushbutton value:
  buttonState3 = digitalRead(buttonPin3);
       if (buttonState3 == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin3, LOW);  
    
     motor1.run(RELEASE);      // stopped
     motor2.run(RELEASE);      // stopped
     motor3.run(RELEASE);      // stopped
     motor4.run(RELEASE);      // stopped
     delay(1000);
     
  } 
  else {
	  digitalWrite(ledPin3, HIGH);
    
     motor1.run(FORWARD);      // turn it on going backward
     motor1.setSpeed(255);
     motor2.run(FORWARD);      // turn it on going backward
     motor2.setSpeed(255);
     motor3.run(BACKWARD);      // turn it on going backward
     motor3.setSpeed(225);
     motor4.run(BACKWARD);      // turn it on going backward
     motor4.setSpeed(255);
                               
     delay(1000);

  }
}

Friends please help me to solve this issue at coding too. I really need your help, I stucked at my project now :-(. Please check my code above ;and help me please.

I recorded this problem to video too : Arduino DC motor movement control with buttons with adafurit v1 motor shield library - YouTube

Not :
Actually I wanted to use a potentiometer for movement and rotation but I didn't able to success ,while using adafruit v1 motor shield library, and even I checked if there were any examples from internet about dc motor control with a potentiometer with adafruit motor shield but there was nothing, only examples with dc motor + encoder or stepper motor + potentiometer/encoder )

OK- read the how to use this forum sticky post. Then go back and modify your post so that the it is posted correctly in code tags.

The software problem is caused by your use of the delay function. Do not use delay if you want to interrupt what is happening and make other things happen.
Look at the blink without delay for the technique and look at a finite state machine for further help.
This is a good place to start.
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

Go, Grumpy_Mike.

This is why I'll continue to say that delay() is one of the worst things to teach a newbie as a first lesson. It has its uses.

This is the code I am using ;but it doesn't work properly. With 1 button control the dc motors as forward or whatever other movement rotations are working. However, when I want to use 2 or 3 buttons with debouncing method my miniature testing robot acts like really weird with below code.

Friends, would you show me a 2 buttons control for my dc motors with debouncing please ? I am trying myself but need some help really( I am newbie ), thanks.

#include <AFMotor.h>

AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor3(3, MOTOR12_64KHZ);   // create motor #2, 64KHz pwm
AF_DCMotor motor4(4, MOTOR12_64KHZ);   // create motor #1, 64KHz pwm


const int buttonPin1 = 18;     // the number of the pushbutton pin for tank movement  backward
const int buttonPin2 = 19;     // the number of the pushbutton pin for tank movement  forward
const int buttonPin3 = 20;     // the number of the pushbutton pin for tank body rotation  turn around 
// const int buttonPin4 = 21;     // the number of the pushbutton pin for tank firing mechanism motor  at BB firing


const int ledPin1 =  14;      // the number of the LED pin to check if the button works properly for tank movement  backward
const int ledPin2 =  15;      // the number of the LED pin to check if the button works properly for tank movement  forward
const int ledPin3 =  16;      // the number of the LED pin to check if the button works properly for tank body rotation  turn around 
// const int ledPin4 =  17;      // the number of the LED pin to check if the button works properly for tank firing mechanism motor  at BB firing

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status for tank body movement  backward
int buttonState2 = 0;         // variable for reading the pushbutton status for tank body movement  forward 
int buttonState3 = 0;         // variable for reading the pushbutton status for tank body rotation  turn around 
// int buttonState4 = 0;         // variable for reading the pushbutton status for tank firing mechanism motor  at BB firing




// Variables will change:
int ledState1 = LOW;         // the current state of the output pin
int ledState2 = LOW;         // the current state of the output pin
int ledState3 = LOW;         // the current state of the output pin
// int ledState2 = LOW;         // the current state of the output pin



int lastButtonState1 = LOW;   // the previous reading from the input pin
int lastButtonState2 = LOW;   // the previous reading from the input pin
int lastButtonState3 = LOW;   // the previous reading from the input pin
// int lastButtonState4 = LOW;   // the previous reading from the input pin


int lastReading1= LOW;
int lastReading2= LOW;
int lastReading3= LOW;
// int lastReading4= LOW;

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime1 = 0;  // the last time the output pin was toggled
long lastDebounceTime2 = 0;  // the last time the output pin was toggled
long lastDebounceTime3 = 0;  // the last time the output pin was toggled
// long lastDebounceTime4 = 0;  // the last time the output pin was toggled


long debounceDelay1 = 50;    // the debounce time; increase if the output flickers
long debounceDelay2 = 50;    // the debounce time; increase if the output flickers
long debounceDelay3 = 50;    // the debounce time; increase if the output flickers
// long debounceDelay4 = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(ledPin1, OUTPUT);
  
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin2, OUTPUT);
  
  pinMode(ledPin3, OUTPUT);        // initialize the LED3 pin as an output:    
  pinMode(buttonPin3, INPUT);      // initialize the pushbutton pin as an input:
  
  /*  
  pinMode(ledPin4, OUTPUT);        // initialize the LED4 pin as an output:    
  pinMode(buttonPin4, INPUT);      // initialize the pushbutton pin as an input:
 */
 
  motor1.setSpeed(255);     // set the speed to 200/255
  motor2.setSpeed(255);     // set the speed to 200/255
  motor3.setSpeed(255);
  motor4.setSpeed(255);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading1 = digitalRead(buttonPin1);

  // check to see if you just pressed the button 
  // (i.e. the input went from LOW to HIGH),  and you've waited 
  // long enough since the last press to ignore any noise:  

  // If the switch changed, due to noise or pressing:
  if (reading1 != lastReading1) {
    // reset the debouncing timer
    lastDebounceTime1 = millis();
    // save the reading.  Next time through the loop,
    // it'll be lastReading:
    lastReading1 = reading1;
  } 
  
  if ((millis() - lastDebounceTime1) > debounceDelay1) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so accept the button state change:
  
    // toggle the LED if the state of the button changes from LOW to HIGH:
    if (lastButtonState1 == LOW && reading1 == HIGH) {
      if (ledState1 == HIGH) {
        ledState1 = LOW;
      } else {
        ledState1 = HIGH;
      }
      digitalWrite(ledPin1, ledState1);
    }
    lastButtonState1 = reading1;
    
    // read the state of the pushbutton value:
     buttonState1 = digitalRead(buttonPin1);
       if (buttonState1 == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin1, LOW);  
    
     motor1.run(RELEASE);      // stopped
     motor2.run(RELEASE);      // stopped
     motor3.run(RELEASE);      // stopped
     motor4.run(RELEASE);      // stopped
     delay(1000);
     
  } 
  else {
	  digitalWrite(ledPin1, HIGH);
    
     motor1.run(BACKWARD);      // turn it on going backward
     motor1.setSpeed(255);
     motor2.run(BACKWARD);      // turn it on going backward
     motor2.setSpeed(255);
     motor3.run(BACKWARD);      // turn it on going backward
     motor3.setSpeed(225);
     motor4.run(BACKWARD);      // turn it on going backward
     motor4.setSpeed(255);
                               
     delay(1000);
    
    
  }
  }
  
  /////////////////////////////////////////////////////////////////////////////////
  
  int reading2 = digitalRead(buttonPin2);

  // check to see if you just pressed the button 
  // (i.e. the input went from LOW to HIGH),  and you've waited 
  // long enough since the last press to ignore any noise:  

  // If the switch changed, due to noise or pressing:
  if (reading2 != lastReading2) {
    // reset the debouncing timer
    lastDebounceTime2 = millis();
    // save the reading.  Next time through the loop,
    // it'll be lastReading:
    lastReading2 = reading2;
  } 
  
  if ((millis() - lastDebounceTime2) > debounceDelay2) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so accept the button state change:
  
    // toggle the LED if the state of the button changes from LOW to HIGH:
    if (lastButtonState2 == LOW && reading2 == HIGH) {
      if (ledState2 == HIGH) {
        ledState2 = LOW;
      } else {
        ledState2 = HIGH;
      }
      digitalWrite(ledPin2, ledState2);
    }
    lastButtonState2 = reading2;
    // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);
       if (buttonState2 == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin2, LOW);  
    
     motor1.run(RELEASE);      // stopped
     motor2.run(RELEASE);      // stopped
     motor3.run(RELEASE);      // stopped
     motor4.run(RELEASE);      // stopped
     delay(1000);
     
  } 
  else {
	  digitalWrite(ledPin2, HIGH);
    
     motor1.run(FORWARD);      // turn it on going backward
     motor1.setSpeed(255);
     motor2.run(FORWARD);      // turn it on going backward
     motor2.setSpeed(255);
     motor3.run(FORWARD);      // turn it on going backward
     motor3.setSpeed(225);
     motor4.run(FORWARD);      // turn it on going backward
     motor4.setSpeed(255);
                               
     delay(1000);
    
    
  }
    
  }

Read all the button states at the beginning of your code, then perform all tests.

You are still using delay!
Your buttons do not need debouncing.

It is still the same without delays . And now only last button works the way I want ;but others doesn't work ( okay leds are on and off when I press button ;but motors don't move at other 2 buttons and while pressing other 2 buttons they noise " tick tick ;or a strange noise ". How to fix it ? thanks.

Would you make some adjustments on my codes please to solve and fix this issue ? thanks.
( first button is for tank movement forward; second button is for tank movement backward; third button is for tank body rotation to turn its around with using debouncing )

Not:
I tried without debouncing ;but it gives only noise and " tick tick " or strange behaviours happening ( start to move after a while then stop then move again while holding the button; thus I was started to use debouncing but new problems occured now that I mentioned at my first paragraph above ). Friends Please help me to fix this issue, I really need your help, thanks again.

I want to learn please help me, I am newbie so I am seeking help ;and this issue is not solving with reading the documents about debouncing with button, I need a sample example to learn this multi button coding with debouncing which it will be work with my motor codes successfully, please help me, thanks.

Just came across this link you might be interested in:-
http://www.intorobotics.com/2-simple-methods-choose-motors-wheel-drive-robots/

Hi.
Is it normal that full spid on motorsheld is less than speed when direct connected to battery?