Pages: [1]   Go Down
Author Topic: Problem : servo and DC motor with mega 2560  (Read 2061 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody,

I have just bought a ARDUINO MEGA 2560 Inventor Motor Servo Kit to learn how it works. However, the examples are explained (circuits and programming) for arduino uno. I can handle with the leds, but I can not run the DC motor and the servo. Should I modify something to work with 2560?
By the way, I have a toy dc motor and a toy servo (sg90). I am using USB connection for powering arduino and using +5V and GND pins for circuit, i.e. no external supply. When I do make the DC circuit, nothing happens. For the servo motor, when I make the circuit, it starts to rotate until it is 180 deg and stucks!

For example I can not run the tutorial below  smiley-sad
http://arduino.cc/en/Tutorial/Sweep

Sorry, my questions can be silly, but I am a newbie  smiley

Thanks for your helps.

« Last Edit: June 06, 2011, 07:36:35 am by saruman55 » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8945
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For digital pins 0-13 and analog pins 0-5 the Mega and UNO should be programmed the same.  If your experiments are not working as described then either you have gotten the wiring wrong or the "Experimentation Guide" is wrong.

You can hook the DC motor between GND and +5v to make sure it works.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

Thanks for the answer. When I plug the DC motor to 5v and GND, it works.
The circuit is given in P3 (dc motor without capasitor). When I make it, it does not spin smiley-sad

http://www.sparkfun.com/tutorial/AIK/CIRC00-sheet-SPAR.pdf

THe code is;

int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)

void setup()
{
 pinMode(motorPin, OUTPUT);
}

void loop()                     // run over and over again
{
 motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();
}

void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}

void motorOnThenOffWithSpeed(){
 
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed)
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
 
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed)
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}

void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
 
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
 
  //Decelerates the motor
  for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}

« Last Edit: June 06, 2011, 08:59:58 am by saruman55 » Logged

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

The servo problem has been solved with MegaServo library. However, DC motor problem still goes on smiley-sad
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't power most motors directly from an output pin (if that is what you are tying to do), these pins can only supply ~40ma at most.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8945
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the transistor is hooked up incorrectly or the diode is backward the circuit won't work.

Try to use the transistor to turn on the LED/resistor combination from the previous experiments.  That will let you check the transistor.  Then put the diode across the LED/resistor combination to be sure you have the diode the right way.  If you ca get the transistor to switch the LED it should also work with the motor.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: