Go Down

Topic: Terminator servo (Read 1 time) previous topic - next topic

Jamesmurg

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

Delta_G

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?
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

slipstick

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.

Steve

Jamesmurg

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

thanks













void setup() {
 pinMode(ledpin,OUTPUT);

 Serial.begin(9600);
 pinMode(pirPin,INPUT);
myservo.attach(9);
 digitalWrite(pirPos, HIGH);
 
 Serial.println("calibrating sensor");
 for(int i = 0;i <calibrationtime; i++){
   Serial.print(calibrationtime - i );
   Serial.print("-");
 //  delay(1000);

myservo.write(90);

   
 }

 Serial.print("done");

 while(digitalRead(pirPin)==HIGH){
  // delay(500);
   Serial.print(".");
 }
 Serial.print("SENSOR ACTIVE");
}



void loop() {
while(digitalRead(pirPin)==HIGH){
   //delay(1000);
digitalWrite(ledPin, HIGH);  // turn LED ON


 delay(3000);
 digitalWrite(ledpin,HIGH);
 delay(3000);
 
 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(45);

 //myservo.write(70,30,true);
 //delay(15);
 //myservo.write(0,20,true);
 //myservo.write(70,250,true);
// delay(15);
 //myservo.write(0,20,true);
 //delay(15);
 //myservo.write(125,35,true);
 myservo.write(90,250,true);
 delay(25);
// myservo.write(180,10,true);// move the servo to 180, slow speed, wait until done
// delay(25);
 myservo.write(140,250,true);
delay(35);
myservo.write(90,10,true);
delay(35);



  digitalWrite(ledPin, LOW);  // turn LED Off
delay(1000);
delay(50);
if(digitalRead(pirPin) == LOW);
//delay(10000);


}}

Johan_Ha

#4
Jul 26, 2017, 12:12 am Last Edit: Jul 26, 2017, 12:14 am by Johan_Ha Reason: code formatting
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]
myservo.write(135);
myservo.attach(9);


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.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Jamesmurg

I have put in

myservo.write(90);

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 

Johan_Ha

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?
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Jamesmurg

please can you explain how to do this as I don't know.

perhaps if I bought a digital servo would this happen

Johan_Ha

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.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Jamesmurg

Ok

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?   



Johan_Ha

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.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Jamesmurg

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.

Johan_Ha

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.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Jamesmurg

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

Johan_Ha

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.
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Go Up