0
\$\begingroup\$

I am working on a project on image tracking on MATLAB, by moving the mounted camera on a servo motor controlled by the Arduino Uno board, the data is serially sent to the arduino using USB according to which the servo motor changes its angle, but there a problem at start the motor initializes to its RESET position that is 0 deg, but after passing an angle serially its does not move back to RESET position when I send 0 as a angle again.

#include <Servo.h>
Servo myservo; 
int incomingByte=0;
void setup() {
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
void loop() {
  if(Serial.available()>0){
    incomingByte=Serial.read();
     Serial.println(incomingByte,DEC);
    Serial.write("readvalue");
    myservo.write(incomingByte);
  }
}

It also doesn't response to some of the angles which are sent serially. I am using a SG90 servo motor, here is its datasheet.
Thanks.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ What angle does it move to when you tell it to go back to 0, and which angles get no response? What happens if you set the angle to 90 (center) then go to 0 or 180 and back to 90? \$\endgroup\$ Commented Feb 21, 2016 at 19:42
  • \$\begingroup\$ Servo motor is set to 0 deg by default but after passing the first angle, it gives a very slight response to other angles. for example when I give it 67 deg it moves to that position after that it does not react to any other angles till range of 40 deg and moves slightly when 10 or 20 deg is given. \$\endgroup\$ Commented Feb 22, 2016 at 7:32
  • \$\begingroup\$ How about you save the previous value of angle sent and calculate the difference between new and previous value and write that to servo. I bet that you want that results. \$\endgroup\$
    – ammar.cma
    Commented Feb 22, 2016 at 7:36
  • \$\begingroup\$ The servo is reacting correctly only to the first angle,other angles however big produce no or slight movement,anyone know what might be causing it? \$\endgroup\$ Commented Feb 22, 2016 at 7:44

1 Answer 1

2
\$\begingroup\$

I tested your code on an Arduino Pro Mini with a Towerpro SG90 servo, and it worked perfectly. Therefore I suspect you have a fault in the wiring or power supply.

The SG90 is a small servo but quite power-hungry - even without a load it draws up to 0.75A. For my test I used a separate 4.8V battery to power the servo, ensuring that the Arduino would not be disturbed by current surges or voltage drop when the servo is operating.

If using a separate power supply doesn't help then you may have flaky wiring or a faulty servo.

\$\endgroup\$
2
  • \$\begingroup\$ Try powering the servo with a separate supply (eg. 4 cell AA NIMH battery or 5V 2A+ PSU). If it now works properly then you have the answer. If it still misbehaves then the problem is elsewhere. \$\endgroup\$ Commented Feb 22, 2016 at 15:21
  • \$\begingroup\$ Thanks, I have used 1000uF( 25V ) to ensure protection against extra current surge, is it not enough?The wires are connected correctly as the change in (+ -) would damage arduino. \$\endgroup\$ Commented Feb 22, 2016 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.