Author Topic: Problem with servo scanning with Arduino  (Read 516 times)

0 Members and 1 Guest are viewing this topic.

Offline SUTO the GTopic starter

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 0
Problem with servo scanning with Arduino
« on: June 09, 2013, 07:19:36 AM »
here is the code:
#include <Servo.h>
Servo scanner;
int scan_angle = 0;  //angle that the scanning servo is at

void setup()
{
scanner.attach(3);
}

void loop()
{

if(scan_angle < 180)  //overflow protection
    {   
      scan_angle += 1;  //turn right
      scanner.write(scan_angle);
      delay(15); 
    }
    else
    {
      scan_angle = 0;
      scanner.write(scan_angle);
      delay(15);
    }     
}
I don`t understand why does my motor make smaller angular turns if I put delay(5). I am trying to make it to scan from 0 to 180 deg and when it reaches 180 to jump back to 0, but I want to make this as fast as possible. If I change the delay(15) to delay(5) it goes faster but it doesn`t seams to go to 180 deg only to 90. Why is this happening? What can I do to make it go to 180 deg fast. Someone please help me!

Offline jlizotte

  • Jr. Member
  • **
  • Posts: 42
  • Helpful? 2
Re: Problem with servo scanning with Arduino
« Reply #1 on: June 09, 2013, 08:19:27 AM »
where's the delete key? lol  :o
« Last Edit: June 09, 2013, 08:27:23 AM by jlizotte »

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,281
  • Helpful? 79
Re: Problem with servo scanning with Arduino
« Reply #2 on: June 09, 2013, 10:34:46 AM »
5 milliseconds between pulses may be too small, and the servo doesn't like it when there's not enough pause between each pulse.

If you want it to turn faster, try adding 2 instead of 1 for each iteration through the loop.

 


Get Your Ad Here