ir control 5 servo help

hello all, ive been looking at how to do this and I have come up with the following code. I am sorry I am a complete novice with Arduino and this will probably be easy for some here to work out.

I'm trying to control the inmoov hand with an ir remote. I know there are ways of controlling the hand with myrobot labs but this hand is a gift for a friends son and it needs to be stand alone.
I can get one button on the remote to control one finger but I cannot figure out how or what to write to get the other fingers to move with other buttons. I may be missing something blindingly obvious but as I have said I am a complete novice and I'm surprised ive got this far.

I hope someone can help me and thanks in advance

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define thumb1 0xFFA25D   //clockwise rotation button
#define thumb2 0xFF22DD//counter clockwise rotation button

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(3);     //servo pin
  }
void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    if (results.value == thumb1)
      {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }
    if (results.value == thumb2)
     {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 160))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 0))  {
    val--;                         //for counter colockwise button
  }
  servo.write(val);
  delay(05);          //General speed

  
}

Start with providing links to the hardware you're using and a picture of the wiring in place.

My guess is that you have just code for one servo in your sketch, so the other fingers are simply not handled.

yeah that's what thought my question is can I add to it to control other servos with other buttons on the same remote.

Read the first line of my first response!

Arduino uno from elegoo
dig pwm 2 for ir receiver
3-7 for servo signal
separate 5v power supply for servo power all through bread board

this is how I would like to make connections

:wink:

.

??? whats that ?

he is telling you there is a bug near the green dotted line :slight_smile:

(think about common grounds)

Yeah I understand all about common grounds I used to be an auto electriction and now I build wire harness's I just wanted to keep this simple until the final build. Using a prototype pcb to build a custom adaptor for the servo plugs and hide that inside the arm/hand.
How ever this still hasn't helped me with the programming.

wampablo:
How ever this still hasn't helped me with the programming.

well in the code you have

if (results.value == thumb1)
...
if (results.value == thumb2)

so you need to check for other codes in results.value and decide what to do with which servo

like I said I am a complete novice with code. ask me to 3d print some thing and I can work wonders but this is rather daunting.
thumb1 is one button moves the thumb forward
while thumb2 does the opposite with a different button on the remote.

problem is theres not enough code for the other fingers and I don't know how to put that code in or if I can use the code I already have and add to it ?

You did say "I have come up with the following code. "

middle1 would move middle finger forward.
middle2 would move middle finger reverse.
index1 . . .
index2 . . .
etc.

.

my apologise when I said come up with this code i didn't mean to imply i wrote it my bad i should have been a little clearer. I do appreciate the help but where wold I put what you've just written ? could you do a small example ?

To have more servos, you need more servo instances in your sketch, one for each digit.
I think you should step back and go through the servo example until you fully understand the nuances.

Have you studied:

Servo questions have been dealt with many times here.
There is a search feature at the top of the screen.
Search for 'multiple servos'.

.

wampablo:
I am a complete novice with Arduino

So hopefully you are an expert in robotics and controlling multi-axis robots.

Hint: The code you posted above just declares one Servo object and attaches it to a single Arduino pin.

If you want to control several Servos, then you better declare as many Servo objects in your code as you want to control and attach a pin to each of them!

ive tried to search for multiple servos and control with ir i just don't seem to be able to tie the two.

nevermind thanks for all your help. maybe I'm being to ambitious

not anywhere near being an expert i can just print some cool stuff.

ive played around with the code and got this far so far

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define thumb1 0xFFA25D   //clockwise rotation button
#define thumb2 0xFF22DD   //counter clockwise rotation button
#define index1 0xFF629D
#define index2 0xFF02FD
#define middle1 0xFFE21D
#define middle2 0xFFC23D
#define ring1 0xFFE01F
#define ring2 0xFF6897
#define pinky1 0xFFA857
#define pinky2 0xFF9867

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(3);     //servo pin
  servo.attach(4);
  servo.attach(5);
  servo.attach(6);
  servo.attach(7);
  }
void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    if (results.value == thumb1)
      {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }
    if (results.value == thumb2)
     {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 160))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 0))  {
    val--;                         //for counter colockwise button
  }
  servo.write(val);
  delay(07);          //General speed

  
}

You need multiple servo instances, 1 per physical hardware

Servo servo;creates one instance andservo.attach(3);    //servo pininitializes that instance to be controlled with pin 3

So you need

Servo servo;
Servo servo1;
Servo servo2;
Servo servo3;
....

servo.attach(3);     //servo pin
servo1.attach(4); 
servo2.attach(5);
....

Of course with better names like thumbServo for example

then multiple Val and rotation directions in different if or switch case to define what angle to set for each servo

thanks for your help with that I understand that a little better now.
I'm still stuck with the values and if you spoke about

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define thumb1 0xFFA25D   //clockwise rotation button
#define thumb2 0xFF22DD   //counter clockwise rotation button
#define index1 0xFF629D
#define index2 0xFF02FD
#define middle1 0xFFE21D
#define middle2 0xFFC23D
#define ring1 0xFFE01F
#define ring2 0xFF6897
#define pinky1 0xFFA857
#define pinky2 0xFF9867

int RECV_PIN = 2;       //IR receiver pin
Servo servo;
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(3);     //servo pin
  servo1.attach(4);     //servo pin
  servo2.attach(5);     //servo pin
  servo3.attach(6);     //servo pin
  servo4.attach(7);     //servo pin
  }
void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    if (results.value == pinky1)
      {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }
    if (results.value == pinky2)
     {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 160))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 0))  {
    val--;                         //for counter colockwise button
  }
  servo.write(val);
  delay(03);          //General speed

  
}