Close

Build log 11- right side schematic and code

A project log for Animatronic Iron Man MKIII suit

RFID tags in the gloves control shoulder rockets pods, hip pods, forearm missile, back flaps and wireless helmet.

jeromekeltyjeromekelty 04/26/2014 at 23:490 Comments

Here's the schematic and code for the right side. It's pretty similar to the left side, minus the XBee radio. The servos for the forearm rocket all receive the same signal- one of the servos that opens the side cover will need to be reversed rotation. Two of the servos that open the forward and rearward shoulder rocket covers will also need to have their rotation reversed as they receive the same signal as the servos on the opposite shoulder. 

A larger image can be seen here.

Here's the code for the right side-

#include "Servo.h"                 // include the servo library

Servo forearmServo;             // servos to move forearm missile
Servo rearcoverServo;          // servo to move rear shoulder rocket pod cover
Servo forwardcoverServo;    // servo to move forward shoulder rocket pod cover
Servo podServo;                   // servo to move shoulder rocket pod



int RFIDResetPin = 13;
int servoPin1 = 7;                   // control pin for forearm missile servos
int servoPin2 = 8;                  // control pin for rear shoulder rocket pod cover servo
int servoPin3 = 9;                  // control pin for forward rocket pod cover servo
int servoPin4 = 10;                // control pin for shoulder rocket pod servo



//Register your RFID tags here
char tag1[13] = "440085E77452";
char tag2[13] = "440085FC330E";
char tag3[13] = "440085F97840";
char tag4[13] = "4400863914EF";


void setup(){
Serial.begin(9600);


forearmServo.attach(servoPin1);              // attaches the servo on pin 7 to the servo object
rearcoverServo.attach(servoPin2);          // attaches the servo on pin 8 to the servo object
forwardcoverServo.attach(servoPin3);    // attaches the servo on pin 9 to the servo object
podServo.attach(servoPin4);                    // attches the servo on pin 10 to the servo object
forearmServo.write(45);                            // rotate the forearm servos to 45 degrees
rearcoverServo.write(45);                         // rotate the rear cover servo to 45 degrees
forwardcoverServo.write(45);                   // rotate the forward cover servo to 45 degrees
podServo.write(45);                                   // rotate the left flap servo to 45 degrees



pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);



}

void loop(){

char tagString[13];
int index = 0;
boolean reading = false;

while(Serial.available()){

int readByte = Serial.read();               // read next available byte

if(readByte == 2) reading = true;        // begining of tag
if(readByte == 3) reading = false;       // end of tag

if(reading && readByte != 2 && readByte != 10 && readByte != 13){
//store the tag
tagString[index] = readByte;
index ++;
}
}

checkTag(tagString);            // Check if it is a match
clearTag(tagString);              // Clear the char of all value
resetReader();                       // reset the RFID reader
}

void checkTag(char tag[]){
///////////////////////////////////
//Check the read tag against known tags
///////////////////////////////////

if(strlen(tag) == 0) return;               // empty, no need to continue

if(compareTag(tag, tag3)){              // if matched tag3, do this
forearmServo.write(135);
delay(2500);
forearmServo.write(45);

}else if(compareTag(tag, tag4)){           // if matched tag4, do this
rearcoverServo.write(70);                    // rotate the pod servo to 90 degrees
delay(500);                                           // wait half a second
forwardcoverServo.write(100);            // rotate the forward cover servo to 110 degrees
delay(500);
podServo.write(80);                             // rotate the pod servo to 80 degrees
delay(4000);
podServo.write(45);                             // rotate the pod servo to 45 degrees
delay(500);
forwardcoverServo.write(45);             // rotate the forward coverservo to 90 degrees
delay(500);
rearcoverServo.write(45);                    // rotate the pod servo to 135 degrees


}else{
Serial.println(tag); //read out any unknown tag
}

}

void lightLED(int pin){
///////////////////////////////////
//Turn on LED on pin "pin" for 250ms
///////////////////////////////////
Serial.println(pin);

digitalWrite(pin, HIGH);
delay(250);
digitalWrite(pin, LOW);
}

void resetReader(){
///////////////////////////////////
//Reset the RFID reader to read again.
///////////////////////////////////
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
delay(150);
}

void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
for(int i = 0; i < strlen(one); i++){
one[i] = 0;
}
}

boolean compareTag(char one[], char two[]){
///////////////////////////////////
//compare two value to see if same,
//strcmp not working 100% so we do this
///////////////////////////////////

if(strlen(one) == 0) return false; //empty

for(int i = 0; i < 12; i++){
if(one[i] != two[i]) return false;
}

return true; //no mismatches
}

Discussions