Step 6: CODE!!!

Picture of CODE!!!

The Very first thing you want to do is make sure your shield or xbee's are unplugged from the arduino. Or make sure the correct jumpers are the in the right place (in my case). I have written this code and if you do use it want credit.

This is the code for the sending Arduino:

int Finger1 = 0;
int Finger2 = 1;
int Finger3 = 2;
int Finger4 = 3;
int Finger5 = 4;

void setup()

void loop()
byte servoValue1;
byte servoValue2;
byte servoValue3;
byte servoValue4;
byte servoValue5;

int FingerV1 = analogRead(Finger1);
int FingerV2 = analogRead(Finger2);
int FingerV3 = analogRead(Finger3);
int FingerV4 = analogRead(Finger4);
int FingerV5 = analogRead(Finger5);

if (FingerV1 < 200) FingerV1 = 200;
else if (FingerV1 > 460) FingerV1 = 460;
if (FingerV2 < 200) FingerV2 = 200;
else if (FingerV2 > 460) FingerV2 = 460;
if (FingerV3 < 200) FingerV3 = 200;
else if (FingerV3 > 460) FingerV3 = 460;
if (FingerV4 < 200) FingerV4 = 200;
else if (FingerV4 > 460) FingerV4 = 460;
if (FingerV5 < 200) FingerV5 = 200;
else if (FingerV5 > 460) FingerV5 = 460;

byte servoVal1 = map(FingerV1,460, 200, 255, 0);
byte servoVal2 = map(FingerV2,460, 200, 255, 0);
byte servoVal3 = map(FingerV3,460, 200, 255, 0);
byte servoVal4 = map(FingerV4,460, 200, 255, 0);
byte servoVal5 = map(FingerV5,460, 200, 255, 0);



Here is the receiving:


Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

void setup()

myservo1.attach(2); // attaches the servo on pin 9 to the servo object

void loop()
if(Serial.available() >=5)
byte servoAng1 =;
byte servoAng2 =;
byte servoAng3 =;
byte servoAng4 =;
byte servoAng5 =;

// Send the servo to the position read...  (note: you get to make this happen)

Remove these adsRemove these ads by Signing Up
Don Kellogg2 years ago
Could some one please tell me what Xbee Shield and Modules I need to do this project. I've seen several different Xbee units and some have been discontinued.
chsairam_73 years ago
why did'nt you map it to 1024 analog values and 180 servo angles; would'nt that be more effective? I made a similar hand months ago and it was pretty cool
zachrattner4 years ago
Cool project. You can clean up that chunk of if's by using the constrain function:
Bombbunny4 years ago
What program can I use to open up the xbee recieve and send files?
njkl44 (author)  Bombbunny4 years ago
The code here is actually for the arduino. There is no code for the xbees you have to deal with. You configure the xbees in XCTU but you open the code in the arduino programming program
maewert4 years ago
Very neat!

I see there is no blocking of data being transmitted. I mean within the stream there is no indication where the stream starts. Does this sometimes get confused as to which finger is which, especially if the receiving arduino is powered up after the transmitting arduino? If so then you may want to send a blocking character like '$' before the first finger is transmitted and then the reciever can look for the symbol to remain in sync with the transmitter.

Cool device. I'll have to try this ;-)

Best Wishes.
njkl44 (author)  maewert4 years ago
Hey thank you I'm really glad you like it and there's not a whole lot of problems only about if 30 seconds without use the receiving start sending stuff to the sending wich im nit sure y but I see what you were saying and I may try somthing like that.

Thanks, Easton