controlling a servo motor with two arduinos?

i have two arduinos, two buttons and one servo motor.

i want to control a servo motor with two arduino's when i pressed the buttons. i linked arduino pwm pins (first arduino pwm pin is 9, and second one is 3) to the servo motor signal input.

when i pressed button 1 servo motor moving a few, or pressed button 2. but the signal isn't clear, and servo motor doesn't move correctly that i assigned degree.

what can i do for the solution?

#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(3);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  { 
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}

and secon arduino code is:

#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(9);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  { 
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}

So you have two servo outputs tied to one servo input? I can't see how that would work. Servo signals are sent continuously, not just when a change is requested. The two signals are "fighting" each other. That's beside the fact that tying 2 outputs together seldom ends well.

The solution is to have the servo connected to only one Arduino and the 2 Arduinos connected by serial, I2C, SPI or just a digital output to an input. When the second Arduino button is pressed it tells the first to move the servo.

PS servos running with the Servo library do not need PWM pins.

i linked arduino pwm pins (first arduino pwm pin is 9, and second one is 3) to the servo motor signal input.

Firstly, not that it matters here, servos work on any pins, not just the pwm ones.

I can't say what the electrical implications are for possible damage, but there may be some.

But assuming there is no electrical reason not to do this, you have no control over the "composite" signal in the joined up wire. A servo signal repeats- the library takes care of that- so with neither button pressed eg, both are sending a repeating 2ms pulse and since the Arduinos are independent, who knows how those signals are overlapping as a combined singnal of who knows how many ms.

The burning question is of course, why are you trying this? If you must have two Arduinos, you could send a message from Arduino A to B with A's button state, with the servo on B only, and let the logic in B decide what to do.

edit.... which is all pretty much just another way of saying what groundFungus said :wink:

thank you for your answers. i will try first arduino connected servo and second connected by serial to first arduino. maybe it will worked :d

As griundFungus said, you dont even need serial. Just use a digital output on the first Arduino to copy the button state to the other one. Of course, you might as well then connect the first button to the second Arduino, and put the first Arduino back in its box.

Why are you using two Arduinos?

@meltDown, because i made a rocket and i need two systems. one is main flight controller and second is backup system. but i have to use one motor to deploy parachute at apogee. so i decide to use two arduinos.

Very off the top of my head, I wonder if the backup could use pulsein() to monitor the health of the main Arduino's servo signal, and only enable the backup servo signal if the main one's dead?

edit... or even just have the backup monitor the main Arduino's 5V output for proof of life and take over if it's died?

So your trying to make the system redundant but your not installing redundant batteries or servo which are the more likely things to fail vs the Arduino itself?

I was wondering about not having a redundant servo too. Might be tricky to make sure the non deploying servo doesnt hold things back when the other one deploys.

How about 2 complete chute systems? No harm in them both deploying. I guess space and mass is a thing....

i think i have to use two systems becasue if one of them fail the other one would work. but there is no capacity to use two servos. so i should use one servo and two controller.

2 complete chute system will be heavy. i need to be sure that it's the heaviest. therefore i can't use.

@Slumpert, yes you are right if arduino fail :slight_smile: but i'm tyring to make a reliable system. if arduino won't work, my rocket wouldn't deploy chute and it will crash to the ground :frowning:

gryhkn:
@Slumpert, yes you are right if arduino fail :slight_smile: but i'm tyring to make a reliable system. if arduino won't work, my rocket wouldn't deploy chute and it will crash to the ground :frowning:

Slumpert's point is though, that the servo side of things is more likely to fail than the Arduino side, so you're making the redundancy on the wrong side. Neither of your Arduinos is likely to fail before the only servo does, is his (her?) point.