Arduino Forum

Topics => Robotics => Topic started by: Jamesmurg on Jul 25, 2017, 02:32 am

Title: Terminator servo
Post by: Jamesmurg on Jul 25, 2017, 02:32 am
Hi I have an issue with one of my servo's every time I connect power I get a small movement from the servo how do I stop this please help
Title: Re: Terminator servo
Post by: Delta_G on Jul 25, 2017, 04:28 am
Switch the red wire out with the blue wire.  Try deleting line 47 in your code. 

Don't you think you need to provide some details to get a real answer?
Title: Re: Terminator servo
Post by: slipstick on Jul 25, 2017, 12:10 pm
Probably you can't stop it. Many/most servos twitch when powered on as they try to work out what position they're currently in. It's just how servos are.

Title: Re: Terminator servo
Post by: Jamesmurg on Jul 25, 2017, 10:58 pm
Ok sorry about the vague explanation. Here is my code. Sorry that it is a bit all over the place as I am learning and am new to this.

If I could find a way to stop the movement at the start that would be great as I don't want my terminator's eyes to move at all before the light in the eyes come on.

please could some one take a look at my code and see if there is any way to stop this? I would be most grateful


void setup() {

 digitalWrite(pirPos, HIGH);
 Serial.println("calibrating sensor");
 for(int i = 0;i <calibrationtime; i++){
   Serial.print(calibrationtime - i );
 //  delay(1000);




  // delay(500);
 Serial.print("SENSOR ACTIVE");

void loop() {
digitalWrite(ledPin, HIGH);  // turn LED ON

 myservo.write(90,10,true);        // angle / speed/ move the servo to 180, max speed, wait until done                                   // write(degrees 0-180, speed 1-255, wait to complete true-false)

// delay(15);
// myservo.write(180,10,true);// move the servo to 180, slow speed, wait until done
// delay(25);

  digitalWrite(ledPin, LOW);  // turn LED Off
if(digitalRead(pirPin) == LOW);

Title: Re: Terminator servo
Post by: Johan_Ha on Jul 26, 2017, 12:12 am
I've recently learned that when you do myservo.attach(9); the servo jumps to a start position. Your servo might be just a little bit off that start position when you start everything. Without setting a start position, the start position can probably be anything. If you want to set the start position to say 135 degrees at start, you do:

Code: [Select]

You probably want to set the start position instead of having a completely arbitrary start position. Whatever position the servo was before start can't be chosen.
Title: Re: Terminator servo
Post by: Jamesmurg on Jul 26, 2017, 01:02 am
I have put in


before the void loop doesn't seem to make any difference also the servo I have found has to be set at 90 to start or the movement at the start is even bigger 
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 26, 2017, 08:26 am
If you end your program by setting your servo to X degrees (and not leave it at an arbitrary position by pulling the battery off) and set the start position to X degree, you should minimise the jump at the start. You probably can't get rid of it alltogether, due to the analog  nature of the servo.

This is a wild guess, but you might be able to hack the servo lib so that nothing happens on the signal pin until the first servo turn command. A servo doesn't turn at power up, if the signal line is detached, does it?
Title: Re: Terminator servo
Post by: Jamesmurg on Jul 26, 2017, 10:36 am
please can you explain how to do this as I don't know.

perhaps if I bought a digital servo would this happen
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 26, 2017, 12:08 pm
Sorry, I can't help. I don't know either, beyond the idea that you should read the source code (search for servo.cpp and servo.h) and understand what happens there. And change it to what you want to happen there.

If what you want is that the program does nothing to the servo at start, and you still want your servo to be active (meaning it forces back any attempt to twist it), you have to know the exact position of your servo and be able to use that position as the start position. An analog servo has a "standard" potentiometer with VIN, GND and  the middle pin. You can attach a wire to the middle pin and measure it with an analog input pin on the Arduino to get feedback from your servo. This needs of course testing and calibration. And it might mess upp a bit the internal precision of the servo circuit.
Title: Re: Terminator servo
Post by: Jamesmurg on Jul 26, 2017, 02:02 pm

thanks for all your help so far I think I can live with the small movement I will try it with a digital motor to see if it helps but I think not

there is another thing I would like some help with in the mean time.

I am going to run the terminator of a lithium battery or something but when the power is turned of I don't want it to suddenly stop in the middle of my void loop I want it to complete the sequence then power of and I don't want it to run another cycle just complete the one it is in is there a way to do this?   

Title: Re: Terminator servo
Post by: Johan_Ha on Jul 26, 2017, 02:45 pm
Then you can't switch off the power to everything that still needs power. You need a switch that goes to an Arduino pin. And some logic in your program that recognises the switch off, terminates all movements and then perhaps uses a linear actuator to switch off the main switch.
Title: Re: Terminator servo
Post by: Jamesmurg on Jul 26, 2017, 06:55 pm
sorry this is well over my head. are you able to give me a working code for this? Then I can test it out and make alterations to the code where necessary

I know this is asking a lot but I would be most grateful.
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 26, 2017, 10:34 pm
No again. I haven't done anything like this. I just brainstorm. Someone with experience could perhaps answer. Or google using the right search words, something like electronic main switch control.

But if I'd have to build something like this, I might use a relay, which is normally off. And an ON button and an OFF button. Pushing your ON push button would turn it on, it would start Arduino, which would send a logic HIGH to one pin dedicated to the relay. As long as it is HIGH, the relay stays on. In your program you should have a global variable, boolean end = FALSE; When your program has started, check once in your process loop whether your OFF push button has been pressed again for closing. If pressed, set end = TRUE; Now you can complete your sequence and after that you check whether end equals TRUE and send a logic LOW to your relay controlling pin. This will cut the current to the relay solenoid, which will cut the power to your Arduino. Until you press the ON button again.

If your program structure doesn't have a main loop that is performed fast enough, you can't just have two lines somewhere in it checking for the OFF button. You'd have to create an interrupt handler for the OFF button, a function that is run when the OFF button activates its own data pin. And the only thing the function does is setting end to TRUE.

Someone with more experience (or experience at all) might object to my idea.
Title: Re: Terminator servo
Post by: Jamesmurg on Jul 26, 2017, 10:59 pm
This sounds like it might be worth a shot but I don't know how to set the code up pleas could you right me down an example of this
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 27, 2017, 12:05 am
I'd rather not. I have never written an interrupt routine. You should search for examples and learn from them. I'd have to do the same thing, if I'd do it.
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 27, 2017, 11:22 am
I wonder if this circuit would work.

The image shows the circuit in off position. The switch only feeds battery voltage to the transistor, which is closed, since Arduino is down, D0 is down. It also feeds voltage to D1 through a resistor, but D1 shouldn't let anything through - someone needs to confirm that.

When switch is turned to ON, the relay is activated and Arduino starts through voltage to Vin. The Arduino program should now raise D0, which will open the transistor, which will keep the relay active. At this point, the relay gets voltage both from the battery and the transistor. That shouldn't be a problem - someone correct me, if needed.

When the switch is turned to OFF, the D0 is still HIGH and keeps the transistor feeding the relay, which keeps the Arduino running. But now D1 has gone high, which tells your Arduino program to shut itself. The program should finish unfinished business, then it needs to put D0 to LOW, which cuts the transistor feed to the relay, which cuts the power to Arduino.

D1 has no external pulldown, so the pin must be set internally to pulldown. An external pulldown thing would have a constant current (fractions of millivolts), when system is down. I have no idea if the internal thing does the same.

This kind of circuit probably needs some capacitors here and there to reduce noise.

Title: Re: Terminator servo
Post by: Jamesmurg on Jul 29, 2017, 12:13 pm
Thank you so much for taking the time to do this for me I can't waight to try it problem is I managed to brake my nano and am waightin for a part to fix it

Any way thanks again
Title: Re: Terminator servo
Post by: Johan_Ha on Jul 30, 2017, 04:04 am
My image merely shows a principle. As I wrote, it probably needs improvement like some caps. And a flyback diode for the relay coil.