Arduino + servo motor

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Arduino + servo motor

Postby hansonlyz » Sun Apr 03, 2011 10:25 am

hi there, i got a few question i want to ask about. This is the first time i'm using arduino and have little exposure on PIC ucontroller also. I have tested PIC16F877A on SK40C to control a servo motor(C36R), it works fine. But when i try to work it with Arduino Duemilanove, the servo motor just jerks, and my arduino board keeps connect and disconnect from my computer. I still don't have clue on how to make this work.

basic idea of my mini project:
i'm trying to use a potentiometer to control the rotation of the servo motor. The following is my setup.

Setup:
1. Arduino Duemilanove connected to computer using USB cable, setup at COM3 port.
2. Servo motor (C36R): red cable > +5V on arduino board ; black cable > GND on arduino board ; white cable > pin2 on arduino board
3. Potentiometer: (when the knob is facing you), left connection > GND on arduino board ; centre connection > pin0 on arduino ; right connection > GND on arduino.

Codes:
CODE: SELECT_ALL_CODE
int servoPin = 2;     // Control pin for servo motor
 int minPulse = 500;   // Minimum servo position
 int maxPulse = 2500;  // Maximum servo position
 int pulse = 0;        // Amount to pulse the servo

 long lastPulse = 0;    // the time in milliseconds of the last pulse
 int refreshTime = 20; // the time needed in between pulses

 int analogValue = 0;  // the value returned from the analog sensor
 int analogPin = 0;    // the analog pin that the sensor's on

 void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulse = minPulse;           // Set the motor position value to the minimum
  Serial.begin(9600);
 }

 void loop() {
  analogValue = analogRead(analogPin);      // read the analog input
  pulse = map(analogValue,0,1023,minPulse,maxPulse);    // convert the analog value
                                                        // to a range between minPulse
                                                        // and maxPulse.

  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }
 }


It won't work. Servo motor just rotate slightly (a few degrees) and my Arduino board just disconnect and then re-connect, servo motor rotate slightly again and the process goes on.

Question:
1. since PIC16F877A on SK40C is working fine, is it because of the clock frequency that effects the result? SK40C is running max on 20MHz but Arduino Duemilanove only runs max 16MHz.
2. the servo motor draws too much current? but i'm only using one motor. This mini project i intent to use about 4 servo motor. Do i need to connect the servo motor to external power supply? if yes, how do i connect them?

Any help will be appreciated.
hansonlyz
Freshie
 
Posts: 4
Joined: Mon Dec 06, 2010 9:43 pm

Re: Arduino + servo motor

Postby sich » Mon Apr 04, 2011 1:21 pm

hansonlyz WROTE:But when i try to work it with Arduino Duemilanove, the servo motor just jerks, and my arduino board keeps connect and disconnect from my computer. I still don't have clue on how to make this work.

May be the voltage regulator on Arduino cannot supply enough current to your servo. Thus it resets the circuit due to voltage drop until lower than the Vmin for the mcu on board. You should supply the servo with an external power other than only through the USB connection.

hansonlyz WROTE:2. the servo motor draws too much current? but i'm only using one motor. This mini project i intent to use about 4 servo motor. Do i need to connect the servo motor to external power supply? if yes, how do i connect them?

Yes, you need external power supply. Please refer to PR18 Biped Walking Robot for the sample schematic.
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: Arduino + servo motor

Postby aly » Sun Feb 24, 2013 8:12 pm

guys,
in order for you to using servo motor from arduino board, do you have some extra connection i means using UART converter. is't without UART servo motor also able to run. because what i know, servo is half duplex and arduino by full duplex
aly
Greenhorn
 
Posts: 3
Joined: Sun Feb 24, 2013 8:06 pm

Re: Arduino + servo motor

Postby robosang » Mon Feb 25, 2013 9:32 am

I think mistaken what is servo motor. This thread is talking about standard RC servo, you might be talking about serial control servo such as robotis's AX or Cytron's G15. So don mix up.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 19 guests

cron