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.