Creeping servo

I’m using an Arduino Nano, and an external intervaltimer/remote control, my servo works with the code that I have written.

// Camera trigger using RC Servo
// by The Mutt

// Code description
// 'attach' connects a servo object to a specific pin of the Arduino. You can use any pin.
// 'detach' removes the servo object, effectively disabling the servo and removing its power.
// 'writeMicroseconds' specifically indicates that you wish to use microseconds to control the servo position.
//'read' returns the last specified position of the servo, in degrees

// Detaching the servo will prevent it from buzzing or, if using a servo modified for continuous rotation, 
// stop if from slowly “creeping” when you set its position to 0 (stop). Since the servo is not being powered, 
// it also saves battery juice when your Arduino and servos are mounted on a mobile robot.

#include <Servo.h>

Servo shutterservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position
int inputPin = 3; // set button pin
int val;    // variable to read the value from the analog pin

void setup()
{
  shutterservo.attach(9);  // attaches the servo on pin 9 to the servo object
pinMode(inputPin, INPUT); // set button in my case interval timer cable release as input
}

void loop()
{
val = digitalRead(inputPin); // reads value of input

  val = digitalRead(inputPin); // reads value of input
  if (val == HIGH)             // check if the input is HIGH

 // shutterservo.attach(9);   // Attach and apply power  
  //  val = analogRead(potpin);		// reads the value of the potentiometer (value between 0 and 1023)
  //val = map(val, 2000);     // scale it to use it with the servo (value between 1ms and 2ms)
  //val = map(val, 0, 1023, 1000, 2000);     // scale it to use it with the servo (value between 1ms and 2ms)
  shutterservo.writeMicroseconds(2000);	    // sets the servo position according to the scaled value
  delay(60);				   // waits for the servo to get there
  // shutterservo.detach();    // Detach and remove power  

  if (val == LOW)
 // shutterservo.attach(9);   // Re-attach and apply power
  shutterservo.writeMicroseconds(0);			// sets the servo position according to the scaled value
  delay(30);				   // waits for the servo to get there
 //  shutterservo.detach();    // Detach again
}

As you can see some code has been quoted out, I tend to leave it as a reminder in-case I’m called away on business for a while, unused code will be cleaned up when everything works properly.

The problem is, if a long time exposure is selected the servo arm moves into position - pauses - the jerks back to the ‘0’ position, I need the servo arm to stay in position not to return back to ‘0’.

Using the shutterservo.attach(9); and shutterservo.detach() makes the servo arm move slowly with micro pauses.

Anyone with any ideas as to what I’m missing?

Glenn

Anyone with any ideas as to what I'm missing?

Perhaps a little more info on what you are trying to accomplish. Also you need to delete one of your double post.

When you use .writeMicroseconds() the value typically ranges between 1000 and 2000. The value 0 may produce unexpected results.

I have a Sony Nex-3 camera, and a Fotga EZa-C1 camera controller, as the Nex-3 does not have the IR control of the Nex-5 and Nex-7 I need to take fire the camera with a servo, at present the arduino moves the servo arm in time with the Fotga to take photographs at the desired time delay, if a time exposure is selected over 2.5 seconds the servo arm starts getting the jitters and eventually '0' position to full turn.

I hope this is enough info?

Glenn

I changed .writeMicroseconds(0) to .writeMicroseconds(1000) problem still the same,

I've accidentally created two threads on this subject, how can I merge the two threads?

Glenn

What kind of servo are you using?

The servo is a Dynam 8.4g servo.

Glenn

TheMutt: if (val == HIGH)             // check if the input is HIGH

Firstly, comments that merely echo the code are pointless. Comments that explain how the code works (when it isn't obvious) or WHY it's doing what it's doing are useful.

Secondly, you should always ALWAYS follow 'if', 'for', 'while' an so on with a compound statement i.e. { and } pair. It avoids situations like this where you might suppose you're controlling the following block of code but are actually only controlling the very next line.

And thirdly, for goodness sake get rid of the commented out code. You're wasting our time by making us read that stuff.

I find your servo in the manufacturer's website, but I can't find out anything about how it's supposed to work. What behavior do you expect out of this thing when it stops getting a signal?

TheMutt: I've accidentally created two threads on this subject, how can I merge the two threads?

Click [u]Report to moderator[/u]. Plead your case.

PeterH

I checked the voltage state of the circuit, 0.4mV while at idle, 4.4V when triggered fluctuating as low as 3.6mV.

I have +5 volt going directly to one of the Fotga connections, the other Fotga connection splits to pin D02 and through a 10K ohm resistor to Arduino ground,

I have tried the servo on the +5 volt connection on the Arduino and the +5 volt pin (getting +4.6 volts) and the +5 volt battery connection (4.8 volts), I'm using a +5 volt regulator, the servo ground is the same ground as the Arduino.

I'll research 'compound statements'

I now know to remove comment code, sorry about that.

tmd3

I also have a Hitec hs-45hb servo, when I purchased the Dynam the sales guys said they are of identical spec.

Glenn

I rewrote the code and added ‘else’ to follow the ‘if’ statement.

The servo still won’t hold position more than 2-3 seconds.

#include <Servo.h>

Servo shutterservo;

int pos = 1500;
int inputPin = 3;
const int buttonPin = 3;

int buttonState = 0;

void setup() {
      
  pinMode(buttonPin, INPUT);  
  shutterservo.attach(9);
  pinMode(inputPin, INPUT);  
}

void loop(){
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {    
     shutterservo.writeMicroseconds(2000);
  delay(30);
  }
  else {
      shutterservo.writeMicroseconds(1500);
  delay(30);
  }
}

Glenn

As a quick and easy test, attach an LED and current limiting resistor to one of your output pins, turn it off at the start of setup() add a one second delay and then turn it on. If you ever see the LED blink while your code is running, something is resetting your Arduino, its most likley power, but could be code.

// LED Toggle - lets not assume anything about the circuit or default pin states, after all this is a debug aid.
pinMode(LED_PIN,OUTPUT);
digitalWrite(LED_PIN,LOW);
delay(1000);
digitalWrite(LED_PIN,HIGH);

Duane B

rcarduino.blogspot.com