Servo programming

Hi guys new here and to arduino. I have a couple of questions I hope you guys can help me with. I'm making a EMG controlled bionic arm for a project.

I have an arduino Nano and an uno,
x2 MG90S servos,
x1 buck converter,
x4 AA 2500mah battery pack 6v,
x1 V3 EMG muscle sensor
X1 on/off toggle switch

I want to control the servos independently of one another. They need to be controlled by by the EMG signal, so I'll need to be able to toggle between them with a push button to switch to the servo I want to control. One servo needs to open and close the hand to grasp, and the other only opens and closes the index and thumb fingers to pinch to pick up smaller objects.

I've included a diagram of the circuit I plan on using. My first question is, where do I need to put a switch or momentary push button to switch between the servos?

And my second question is how do I set up the code to run it all?

I know you might say github but tbh I don't know what I'm looking for as I'm a newbie to this. Even if there was someone willing to write the code for me it would be amazing.

I appreciate any help you guys can provide.

I've included a diagram of the circuit I plan on using. My first question is, where do I need to put a switch or momentary push button to switch between the servos?

On any free digital pin.

And my second question is how do I set up the code to run it all?

You read the examples, and understand how they work.

I know you might say github but tbh I don't know what I'm looking for as I'm a newbie to this.

I would not say github, I would say the examples supplied with the IDE, and C++ tutorial/reference sites on the web.

Even if there was someone willing to write the code for me it would be amazing.

If you want to employ someone here to do our work, hen fine. But don'y expect anyone to provide your code for free.

I appreciate any help you guys can provide.

I'm not a 'guy'!

You need to follow SSS (Small Start Strategy straggly) approach. (Edit)
1. Connect SW1 with DPin-D2 (DPin-2) with internal pull-up enabled.
2. Connect signal pin of Servo1 with Dpin-D3 (DPin3).
3. Upload the following sketch. Check that the Servo1 turns to 600 when you press SW1. (Connect SW1 between DPin-D2 and GND.)

#include <Servo.h>
Servo myServo;

void setup()
{
     pinMode(2, INPUT_PULLUP);
     myServo.attach(3);
}

void loop()
{
    while(digitalRead(2) != LOW)
         ;
    myServo.write(60);
   while(1);    //wait for ever
}

4. Connect SW2 with DPin-D4 (DPin-4) with internal pull-up resistor unconnected.
5. Connect signal pin of Servo2 with DPin-D5.
6. Create and upload sketch so that Servo2 will turn to 1200 when SW2 is pressed.
7. Combine the sketches of Step-3 and Step-6 together and check that the Servos respond correctly in response to the activation of SW1 and SW2.

GolamMostafa:
You need to follow SSS (Small Start Straggly) approach.

What on Earth does that mean?

TheMemberFormerlyKnownAsAWOL:
What on Earth does that mean?

Not bad; now, a new word is added in my vocabulary? :slight_smile: The Post-1 is edited to include strategy instead of straggly.

GolamMostafa:
You need to follow SSS (Small Start Strategy straggly) approach. (Edit)
1. Connect SW1 with DPin-D2 (DPin-2) with internal pull-up enabled.
2. Connect signal pin of Servo1 with Dpin-D3 (DPin3).
3. Upload the following sketch. Check that the Servo1 turns to 600 when you press SW1. (Connect SW1 between DPin-D2 and GND.)

#include <Servo.h>

Servo myServo;

void setup()
{
    pinMode(2, INPUT_PULLUP);
    myServo.attach(3);
}

void loop()
{
   while(digitalRead(2) != LOW)
        ;
   myServo.write(60);
  while(1);    //wait for ever
}




**4.** Connect SW2 with DPin-D4 (DPin-4) with internal pull-up resistor unconnected.
**5.** Connect signal pin of Servo2 with DPin-D5.
**6.** Create and upload sketch so that Servo2 will turn to 120<sup>0</sup> when SW2 is pressed.
**7.** Combine the sketches of Step-3 and Step-6 together and check that the Servos respond correctly in response to the activation of SW1 and SW2.

Thanks for your reply, so will this allow me to toggle between the two servos also, or will I can I put a toggle switch between them on the shared positive wire and switch power between them?

jonny3777:
Thanks for your reply, so will this allow me to toggle between the two servos also, or will I can I put a toggle switch between them on the shared positive wire and switch power between them?

Build something very minimum and test it. Add another incremental amount of hardware/software and test it. This is the SSS Strategy approach.

can I put a toggle switch between them on the shared positive wire and switch power between them?

I don't think you want to put the switch on the servos as such, but rather read the switch in the code and if the switch is control servo1 and if it's control servo2.

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