Author Topic: servo motor control problem  (Read 1581 times)

0 Members and 1 Guest are viewing this topic.

Offline amanggTopic starter

  • Newbie
  • Posts: 5
  • Country: in
servo motor control problem
« on: February 01, 2018, 09:56:12 am »
hello everyone,

I am working on the objective of using IR sensor to control the movement of a servo motor on an arduino uno
The motor responds to the value but not every time.

It moves on random signals but most of the time does not respond. It continuously produces knocking/clicking sounds without any movement of the gear.

The servo independently has been tested and works totally fine.

Any ideas why i am facing this problem ? I am also thinking of timing the signals for better monitoring . How can I do that?

Here are the components :
1. IR sensor - Sharp IR sensor http://www.sharp-world.com/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf

2. servo motor - tower pro 996R

here is the code :-

Code: [Select]
#include<Servo.h>

Servo servo1;

int analogPin = 3 ;

int dist = 0 ;
int i =0 ;


void setup() {
Serial.begin(9600);

servo1.attach(9);

// digitalWrite(A3, INPUT_PULLUP);
}

void loop() {
  dist = analogRead(analogPin);
  dist = map (dist,0,1023,0,20);
   
  Serial.println(dist);
  {
 
  for (i=0;i<20;i++)
  {
    if (dist==i)
      servo1.write(dist*10);
       
    }
     
  }
  delay(2000);
}


« Last Edit: February 01, 2018, 10:01:01 am by amangg »
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 6537
  • Country: gb
Re: servo motor control problem
« Reply #1 on: February 01, 2018, 02:55:47 pm »
Emm...

Serial.println(dist);
servo1.write(dist*10);
delay(2000);

Try that.

Also check in the servo library that it is not sending a high frequency.  PWM frequency 50-100Hz is more than enough.

Do you have an oscilloscope?  If you do, probe the signal pin on the servo.

You might also need to calibrate the servo to find it's max and min positions. 

Simplify your code back and move the servo through 0-255 in a loop with a 100ms delay

for( int pos=0; pos<255; pos++) {
   servo.write(pos);
   delay(100);
}

You will find it won't move immediately but will buzz and it will stop before 255 at the other end and buzz.
« Last Edit: February 01, 2018, 03:06:04 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1262
  • Country: us
Re: servo motor control problem
« Reply #2 on: February 02, 2018, 12:58:44 am »
Are you sure you have the servo pins right? Signal and Vdd being switched could be a cause.

The library has a lot of users so I suspect it's not the problem. The PWM frequency will be 50 hz and the duty cycle is 10 to 20%.

I agree with paulca that you should write a little test program.  You only need to go from 0 to 180 degrees.  You might want to make the delay a little smaller - I'd use 10. 100 will take 5 minutes to run through 180 degrees. Though, I'd first do a servo1.write(0); followed by a 2 second delay to allow it to return to the 0 position and then step from 0 to 180.

 

Offline hussamaldean

  • Supporter
  • ****
  • Posts: 284
  • Country: iq
Re: servo motor control problem
« Reply #3 on: February 02, 2018, 06:13:52 am »
could you please elaborate ?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->