0

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?

My first Arduino code is here:

#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 second 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);
 }
}
VE7JRO
2,51519 gold badges27 silver badges29 bronze badges
asked Jul 23, 2019 at 13:44
3
  • 1
    You do you have 2 Arduino's in the first place? Do you really need both? Commented Jul 23, 2019 at 13:53
  • we have to use mcu.but it's not have to be arduino. does it change if we use a different mcu's? Commented Jul 23, 2019 at 14:06
  • 1
    that does not answer the question why you need two arduinos Commented Jul 23, 2019 at 16:20

1 Answer 1

2

You can't just connect random pins together like that. Connecting two output pins together is a recipe for disaster. Best case scenario: nothing works. Worst case scenario: you break one or both Arduinos.

Only one Arduino can control a servo. If you want a second Arduino to make something happen to the servo you have to make it tell the Arduino that is controlling the servo that something should happen.

That could be a simple output of the second Arduino connected to an input of the first Arduino, in which case it kind of acts like a button. Or you could create some kind of communication channel between them - maybe using a Serial connection, or a Wire (I2C) connection. There's many ways, and which is best depends on how much control one Arduino needs to exert over the other.

answered Jul 23, 2019 at 13:49
5
  • thank you for your answer @Majenko, but let me explain. we are a rocket team and we have to use two flight control system. so we use two arduinos for this rocket. first arduino is main controller and second is backup system. we have different sensors but we have one motor to deployment. we want to use second arduino if the first arduino won't work. I don't know if it's descriptive? Commented Jul 23, 2019 at 14:02
  • 1
    Then you need to have some device that sits between the two arduinos and the servo and selects which Arduino is allowed to talk to the servo. You could have one Arduino in "standby" monitoring the other Arduino and, if it fails, flip the "switch" that allows it to control the servo and have it take over. Commented Jul 23, 2019 at 14:08
  • @Giray Hakan When you are talking about backup in case of failure, you first must define the cases of failure, that you want to mitigate here. There might be many different ways, in that the system can fail and which have to be sensed and mitigated in a different way. Commented Jul 23, 2019 at 14:11
  • @Majenko what type of device? can you give a example? Commented Jul 23, 2019 at 14:34
  • 2
    You could use a MUX chip. Or a relay. There's many solutions both mechanical and silicon based. Commented Jul 23, 2019 at 14:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.