Iron man motorised faceplate electronics tutorial!!!

Wow xI97, that is huge!
...I know, that's what she said ;)

Does it bare any differences to the second code in post 1?
 
I think it is 'similar',.. as far as results...

just the approach I posted is very scalable... there is also no delays being used.. (which makes the whole code stop)... I think I threw in a quick little one in the initial blink..(no time to take it out while I was at work) :)

Does anyone have any sound clips handy? for a gear /whirrring sound?



I'll see if I can dig up my servo and make a quick video of it in action if you want.
 
Ya know.. looking at the code..

I think it needs another step..

right now I am not fully waiting for the servo to complete..

'but'.. this code makes it easy to add that.. or change things up.

could be as easy as adjusting the delay before the led 'on' call.. (but I am trying to teach myself to code without as many/any delays as I can!) :)


also here is the blink effect video.. couldnt find any servo in my box o' junk.. (sorry).. just motors.

IM eyeblink v1 - YouTube
 
here is an updated version...

where you can easily control the 'wait' between when you call/start the eye flicker/fade in, after the face plate servo starts to bring it down.. (easy to time your own servo/weight...etc)

cleaned it up a bit too.. would like to have anyone check it out.. or others chime in on suggestions! :)

thanks..


Code:
// IronMan Helmet: eye blink sequence_v1.0
// created by: xl97


//import servo lib
#include <Servo.h>

//servo object names
Servo myservo; // create servo object to control a servo
Servo myservo1;

const int buttonPin = 2; // the pin that the pushbutton is attached to
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button


// led control pins (need to be PWM enabled pins for fading)
const int leftEye =  6;  // the number of the left eye/pcb LEDs
const int rightEye =  3;  // the number of the right eye/pcb LEDs

unsigned long fadeDelay = .5; //speed of the eye 'fade'
unsigned long callDelay = 700; //length to wait to start eye flicker after face plate comes down
unsigned long blinkSpeed = 100; //delay between init blink on/off
unsigned long currentPWM = 0;
boolean isOpen = true;

#define S_IDLE 1
#define S_LEDON 2
#define S_WAITON 3
#define S_LEDOFF 4
#define S_WAITOFF 5
#define S_INITON 6
#define S_INITWAIT 7
#define S_BLINKON 8
#define S_SERVOUP 9
#define S_SERVODOWN 0
#define S_SERVOWAIT 10



//FSM init vars
static int state = S_IDLE; // initial state is 1, the "idle" state.
static unsigned long lastTime;  // To store the "current" time in for delays.


void setup() {
  // Set up serial port
  Serial.begin(9600);  
  //start it off
  //state = S_BLINKON; 
  Serial.print("INTIT STATE: ");
  Serial.println(state);

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

  pinMode(buttonPin, INPUT); // initialize the button pin as a input
  digitalWrite(buttonPin, HIGH); //use interal pull up resistors
}

void loop() { 
  switch(state)
  {
  case S_IDLE:
    // We don't need to do anything here, waiting for a forced state change...like button press.
    //check mian button state
    buttonState = digitalRead(buttonPin);

    // compare buttonState to previous state  
    if (buttonState != lastButtonState) {
      //if button pressed/down
      if (buttonState == LOW){
        //ie: pressed   
        if(isOpen == true){
          Serial.print("CLOSING FACE PLATE: ");
          Serial.println(isOpen, DEC); 
          state = S_SERVODOWN;
        }
        else{
          Serial.print("OPENING FACE PLATE: ");
          Serial.println(isOpen, DEC); 
          //state = S_SERVOUP;
          state = S_LEDOFF;
        }
        isOpen = !isOpen;
      } 
      else{
        //went from ON/HIGH to LOW/OFF..ie: released
        //Serial.print("RELEASE: ");
        //Serial.println(isOpen, DEC); 
      } 
    }
    // save the current state for next loop
    lastButtonState = buttonState;
    break;

  case S_BLINKON:
    Serial.println("init blink.........");   
    //do blink routine here
    //one blink
    analogWrite(leftEye, 155);
    analogWrite(rightEye, 155);
    delay(blinkSpeed);
    analogWrite(leftEye, 0);
    analogWrite(rightEye, 0);
    delay(10);
    //two blinks
    /*
    analogWrite(leftEye, 155);
     analogWrite(rightEye, 155);
     delay(blinkSpeed);
     analogWrite(leftEye, 0);
     analogWrite(rightEye, 0);
     delay(10);
     */
    state = S_LEDON;    
    break;

  case S_LEDON:
    Serial.println("increase........");    
    lastTime = millis();  // Remember the current time
    analogWrite(leftEye, currentPWM);
    analogWrite(rightEye, currentPWM);
    state = S_WAITON;  // Move to the next state
    break;

  case S_WAITON:
    // If one second has passed, then move on to the next state.
    if(millis() > (lastTime + fadeDelay)){
      if(currentPWM < 255){
        currentPWM += 5;
        state = S_LEDON;        
      }
      else{
        Serial.println("@ 255 done........");
        state = S_IDLE;
        //state = S_LEDOFF; //no auto turn off.. set to idle state
      }
    }
    break;

  case S_LEDOFF:
    Serial.println("........decrease");     
    lastTime = millis();  // Remember the current time
    analogWrite(leftEye, currentPWM);
    analogWrite(rightEye, currentPWM);
    state = S_WAITOFF;
    break;

  case S_WAITOFF:
    // If one second has passed, then move on to the next state.
    if(millis() > (lastTime + fadeDelay)){
      if(currentPWM > 0){  //change 0 to higher number to init face 'up' function sooner.
        currentPWM -= 5;
        state = S_LEDOFF;        
      }
      else{
        Serial.println("@ 0 done........");
        state = S_SERVOUP; //leds off..raise faceplate
      }
    }
    break; 

  case S_SERVOUP:
    Serial.println("servo up........."); 
    myservo.write(100);
    myservo1.write(100);
    state = S_IDLE;    
    break;

  case S_SERVODOWN:
    lastTime = millis();  // Remember the current time
    Serial.println("servo down.........");   
    myservo.write(0);
    myservo1.write(0);
    state = S_SERVOWAIT;    
    break;

  case S_SERVOWAIT:
    // If enough time has passed, call the eye flicker routine
    if(millis() > (lastTime + callDelay)){   
      Serial.println("start eye flicker routine");
      state = S_BLINKON;        
    }
    else{
      Serial.println("waiting........");
    }
    break;

  default:
    state = S_IDLE;
    break;
  } 
}


all commented.. serial monitor debugging/code following, and easily edited!

cheers!
 
Last edited:
xl97 your code is turning both servos in the same direction, they need to mirror each other. They appear to have different starting and end points too. The eye flicker is good though. I'd avoid fading eyes for when the faceplate lifts, but its al about personal preference.

Thanks for all the gratuitous posts folks. We're trying to provide the holy grail here. Glad your all appreciating the hard work put in.
3 weeks ago i knew NOTHING about Arduino, circuits, codes etc, the learning curve has been extremely steep and intense.

Just watching the suit up video, seems the eyes dont flicker before powering up, but i know I've seen it somewhere! Really frustrating me now as i cant find it!
Still, I like the effect and post 1 has provided both options for you all.

Heres a random suit up video:
Suit up

I'd also like to give a big cocky wave to Master Le.... Sorry if I'm p*****g on your bonfire buddy... actually no I'm not :p
 
Thank you ! Finally someone made it accessible for everyone ! Your thread deserve more attention, this is a big piece of information when you build a suit.
Just need to find a good electronics supplier, which I can't seem to do here... Any suggestion of online stores that would sell servos and boards ?
 
Thank you ! Finally someone made it accessible for everyone ! Your thread deserve more attention, this is a big piece of information when you build a suit.
Just need to find a good electronics supplier, which I can't seem to do here... Any suggestion of online stores that would sell servos and boards ?

Try ebay, stores within ebay generally ship to anywhere.

First post updated with schematic (i think). If it looks wrong let me know.
 
Oh.. I wasnt aware the servos need to do opposite directions..

(again this is YOUR set-up for the hardware... not mine.. so I have no clue how its set-up for your project :).. others I have seen had only used 1 servo/worm gear..etc)


anyways.. its VERY easy to change..


this is the only place where you edit the servo positions..

edit to what suits your project:

old/original code:

Code:
case S_SERVOUP:
    Serial.println("servo up........."); 
    myservo.write(100);
    myservo1.write(100);
    state = S_IDLE;    
    break;

  case S_SERVODOWN:
    lastTime = millis();  // Remember the current time
    Serial.println("servo down.........");   
    myservo.write(0);
    myservo1.write(0);
    state = S_SERVOWAIT;    
    break;


new code:


Code:
case S_SERVOUP:
    Serial.println("servo up........."); 
    myservo.write(100);
    myservo1.write(0);
    state = S_IDLE;    
    break;

  case S_SERVODOWN:
    lastTime = millis();  // Remember the current time
    Serial.println("servo down.........");   
    myservo.write(0);
    myservo1.write(100);
    state = S_SERVOWAIT;    
    break;


you could easily replace those two values with a variable.. (like pos & pos1 in your original code) to make it easier to edit at the top of the sketch if you like



I believe most servos (unless altered) only go from 0 - 180 degrees..

so choose what you want as the servo start and end points.. as well as for servo1 start & end points.

curently.. when in 'up' function.. it will move both servos to position 100

when in 'down' mode.. it moves servos to position 0..


edit to fit your movement/range..


the approach taken here in this thread (the hinge stuff) is pretty nice as well:
http://www.therpf.com/f24/3d-printed-functional-iron-man-mark-iii-166482/index5.html#post2648553



also for anyone looking for servo's..

I have purchased a few from www.dealextreme.com

they are usually very cheap being around $3.00 or so.. (last I recall)..

shipping takes forever since its from china... but its free shipping.. so if you want to order something that costs a $1.00.. they'll ship it for free. :)

I sometimes order solder paste, Arduino stuff.. when Im not in a hurry..
 
see this is whati like to see and how we should all be sharing our info on these so we can... this is what me and 7sinzz were talking about before this thread was created
 
haha.. thats ok!

just plug in the right wires to the right components.. and copy/paste the code.

You'll be in business.. :)
 
The ironic thing is i work with electronics for the military.... this stuff youre working on is a little smaller than the stuff we use lol..... now if anyone wants to install radar and missile systems into their suits gimme a shout hehe
 
Ordered all my components from amazon... and it dawned on me that once unhooked from the computer theres no power source? did i overlook something or is that such a basic thing it wasnt even mentioned? i did say i am new at this arduino stuff lol
 
No buddy this is just the foundation. This is the main part everybody has been searching for. From here on it will be a group project to get it from the usb port into the helmet. The rest is fairly easy in comparison.
 
No buddy this is just the foundation. This is the main part everybody has been searching for. From here on it will be a group project to get it from the usb port into the helmet. The rest is fairly easy in comparison.

what was the part everyone has been searching for? (I dont really keep up on the IM builds alot).. but I have seen code and hinge/servo stuff released before

what part is the 'group' part needed? If you mean making a smaller 'Arduino circuit' that fits in the helmet.. instead of using the real/full Arduino development board maybe I can help. :)

I made many different Arduino boards.. I even posted a retail one that can be used too :)
 
Last edited:
Ordered all my components from amazon... and it dawned on me that once unhooked from the computer theres no power source? did i overlook something or is that such a basic thing it wasnt even mentioned? i did say i am new at this arduino stuff lol

HI DB-

IMHO.. the Arduino is a 'development' board.. designed for easy/rapid prototyping..

it has alot of things you wont/dont need in you final projects usually..

(such as USB..etc)

Im not sure what exact board you ordered (UNO?).. but you can add a battery pack in place of the USB for power..

'but'.. its not very practical/cost effective to be sticking a $20, $30, $50 dollar Arduino board into a project forever...

so normally you use these for designing your circuit.. testing out components with the addition of your breadboard..etc.... when you are done/satisfied you can 'port' your code to a bare minimum type board.. or jut remove the chip and pop into a ready made pcb designed for your project..etc..
 
This thread is more than 4 years old.

Your message may be considered spam for the following reasons:

  1. This thread hasn't been active in some time. A new post in this thread might not contribute constructively to this discussion after so long.
If you wish to reply despite these issues, check the box below before replying.
Be aware that malicious compliance may result in more severe penalties.
Back
Top