Three servos controlled by only one digital input

hello dears

I'm working on project and I have some issues and I want some advice about the sequence

I have 3 servos and I want them works in order by one input digital pin (3.6V) for example :
when the digital input pin goes Hight the first servo should move to 90 degree and when the pin goes low the first servo should be return to 0 degree and when the digital input pin goes Hight (second time ) the second servo should move to 90 degree and when the pin goes low the second servo should be return to 0 degree and when the digital input pin goes Hight (third time ) the third servo should move to 90 degree and when the pin goes low the third servo should be return to 0 degree

all of the servos controlled by only one digital input (3.6V)

any help?

To clarify: each servo is connected to its dedicated output pin, and you want to control the servos from one input signal?

That's the typical application of a finite-state machine (automaton).

Hi, @mohamed-ly
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

What model Arduino are you using?
What servos do you have, link to specs/data?
What are you going to use to power your project?

Can you post the code you already have written so we can help you develop it?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

this is my diagram connection
when the digital input pin active for first time the first servo should move to 90 degree and when the digital input pin active for second time the second servo should move to 90 degree when the digital input pin active for third time the third servo should move to 90 degree

this is my diagram connection
when the digital input pin active for first time the first servo should move to 90 degree and when the digital input pin active for second time the second servo should move to 90 degree when the digital input pin active for third time the third servo should move to 90 degree.

Normally 9V is too high for a servo it needs to be 6V3.
Also 3V3 is too low for the control signal, although in practice it might just function or be erratic. I would recommend boosting the output to 5V with a transistor.

The way you program this is as @DrDiettrich said, a state machine. Look up that technique there are lots of examples. Basically a variable keeps track of what servo you need to activate next.

there is no problem with voltage and power connection I'm looking for example code to understand how to operate 3 servos with 1 digital input in order

Yes there is. It is even more worrying if you think there is not. Ignore this at your own risk.

Are you expecting us to write this for you?
As it is not a very usual request I doubt you will find examples of it on line.
Is the an assignment for some course you are doing?
Often abstract requests like this are. If it is not then what is the application?

Hi, @mohamed-ly

Can you please tell us your electronics, programming, arduino, hardware experience?

Have you looked at the example sketched in the IDE for the Servo library, that is a good place to start.
Do not try and write your complete code at once, first try and get the servos to sweep, there is an example code in the IDE that will help.

Tom... :smiley: :+1: :coffee: :australia:

Here is one quick and dirty way to do it:

#include <Servo.h>
const byte Servo1Pin = 5;
const byte Servo2Pin = 6;
const byte Servo3Pin = 9;
const byte InputPin = 2;

Servo Servo1;
Servo Servo2;
Servo Servo3;

void setup()
{
  Servo1.attach(Servo1Pin);
  Servo2.attach(Servo2Pin);
  Servo3.attach(Servo3Pin);
  pinMode(InputPin, INPUT);
}

void loop()
{
  // Wait for input to go HIGH
  while (digitalRead(InputPin) == LOW) ;
  Servo1.write(90);
  // Wait for input to go LOW
  while (digitalRead(InputPin) == HIGH) ;
  Servo1.write(0);

  // Wait for input to go HIGH
  while (digitalRead(InputPin) == LOW) ;
  Servo2.write(90);
  // Wait for input to go LOW
  while (digitalRead(InputPin) == HIGH) ;
  Servo2.write(0);

  // Wait for input to go HIGH
  while (digitalRead(InputPin) == LOW) ;
  Servo3.write(90);
  // Wait for input to go LOW
  while (digitalRead(InputPin) == HIGH) ;
  Servo3.write(0);
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.