Pages: [1]   Go Down
Author Topic: Servo Issues  (Read 324 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I just bought an arduino, and am doing my first project.  It is very simple, it takes a digital input, and tells a servo to go to one of the extremes based on the input. The sensor is a npn photoswitch (allan bradly, I can give you way more details if necessary).  I used the internal pullup resistor to read it.  It requires 12v, and the servo I am using is a Hitec HS-311(rated for 6v).  I used 8 AAs to power the Arduino Uno R3 and photoswitch, and also fed a dc-to-dc downstepper to go from 12v to 6v. 
The problem:
Video http://youtu.be/A8jij6bPTLg
 
Troubleshooting:
I used a multimeter to make sure the servo is receiving 6v
I tested a known good servo to eleminate the servo as the problem. similar issues
I tried different pins on the arduino and breadboard. nothing changed.

The code:
int ServoPin = 10;
int SensorPin = 12;
int SensorVal;

void setup()
  {
    pinMode (SensorPin,INPUT);
    pinMode (ServoPin,OUTPUT);
    SensorVal = LOW;
  }
 
void loop()
  {
    digitalWrite(SensorPin, HIGH);          //pullup resistor
    SensorVal = digitalRead(SensorPin);     //gets sensor
    if(SensorVal==HIGH){
      analogWrite(ServoPin, 240);           //255 is max, 240 in case it wasn't reading the pulses at 255
    }
   
    else{
      analogWrite(ServoPin,2);              //0 is min, 2 is same reason as mentioned above
    }
 
 
  } 



I can get you details if you need more, unsure of what else you'd want.
Thanks for the help!
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The servo is a servo. And a servo requires a pulsed signal.
But don't worry, a library takes care of the pulses.
http://arduino.cc/en/Reference/Servo
http://playground.arduino.cc/Learning/SingleServoExample
You only need three functions:
Declare the class before the setup() function with: Servo myServo;
Set the used pin in the setup() function with: myServo.attach( ServoPin);
Set the rotation angle in the loop() function with: myServo.write(50);

The servo should have some time after the myServo.write().
Add a delay(500); at the end of the loop() function.

Writing to an input for the pull-up resistor is no longer needed.
But you need the newest Arduino 1.0.3
You can specify the pull-up resistor with the pinMode() function: http://arduino.cc/en/Reference/pinMode

If you paste your sketch, you can use the code tags. It is the button with a '#' above the input text field.
It looks like this:
Code:
pinMode(SensorPin, INPUT_PULLUP);
« Last Edit: February 10, 2013, 08:00:05 pm by Krodal » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried the Servo library examples?

File -> Examples -> Servo

-br
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, a servo must use the servo library to operate and servo.write() commands to position the servo.

 You can't use analogWrite() commands for a servo as analogWrite() PWM commands use a 500Hz switching speed and servos expect a 40Hz switching speed.

Lefty

Logged

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

Thanks for all the help guys! Man you are fast.
I didn't realize there was a servo library, or that it needed 40hz. I simply guessed that it used the pwm signal.
Problem Solved!
Logged

Pages: [1]   Go Up
Jump to: