xl97's Iron Man motorized face plate tutorial

Discussion in 'Marvel Costumes and Props' started by xl97, Jul 23, 2015.

  1. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    In an effort to:

    1.) decrease confusion
    2.) keep posts organized, in order
    3.) hopefully help others spot people making money off what was freely giving for the community here

    I am posting my approach (which I'm fairly certain people have taken and made 'products' for sale from) on how to add some electronics to your Iron Man buckets.. to get a motorized face plate and led (blinking) eyes..

    The original post is located here:
    http://www.therpf.com/showthread.php?t=170853

    (I would suggest reading it regardless, and MUCH information has been provided to help trouble shoot other members with their issues)

    * Take note of member: "memebr's" post over there as well as it is solid info (with a slight variation on my wiring and code for his wiring and code)

    Key notes to take with you on this adventure:

    1.) Servos shoud NOT be powered (driven) by your Arduino.. it may be 'ok' to temporarily connect the servo to your Arduino (with no load, nothing attached to the servo).. but generally they need more voltage and more current than the Arduino pin can provide.. and can blow your Arduino

    2.) It is best/better to power your servo's separately, and connect the GND wires together for everything,

    3.) I suggest using a +7.v Li-Ion pack with some sort of voltage regulation for your servos (and Arduino board if needed)

    4.) Not connecting ground wires together may result in odd behavior and/or jitter in your servos.

    5.) An Arduino pin is +5v tolerant and can only provide (roughly) 20-40mA... so enough to light up 1 or 2 small accent leds (not high powered ones)

    6.) Your key components (eye leds, Arduino, servos) all take different voltage (have different power needs).. keep this in mind while you design, buy your parts.
    https://www.youtube.com/watch?feature=player_detailpage&v=GSzVs7_aW-Y

    * Arduino usually has vRegulator on-board (depending what variant you have/use) or needs a REGULATED +5v source (not more or you'll blow it)
    * Servos (please read data sheet on your particular model).. most I have seen require about +6v (some +4.8-+6).. so you need to ensure you are not giving them more
    * Your led eyes is a tricky and can be set up several ways..but most leds (depends on color too) need (roughly) +2.0v (reds) to +3.3v (blues, greens..etc)..
    if wired up in parallel, they require more current (in total).. if wired up in series (you require less current, and can get closer to the voltage of the battery source, and not waste as much excess voltage as heat), so depending how it is configured/wired.. you'll need a +3.3v regulator or a maybe a +6v regulator..etc..

    Read: http://www.therpf.com/showthread.php?t=170853&p=2729601&viewfull=1#post2729601



    Link to the eye pcb's I made:
    http://www.therpf.com/showthread.php?t=170853&p=2648856&viewfull=1#post2648856


    Link to calculate the resistors needed in your personal set up:
    http://www.therpf.com/showthread.php?t=170853&p=2650741&viewfull=1#post2650741


    Random Link to sound FX: (if applicable to your project, a bit outside the scope of this tutorial though)
    http://www.therpf.com/showthread.php?t=170853&p=2650741&viewfull=1#post2650741
    http://www.therpf.com/showthread.php?t=170853&p=2662440&viewfull=1#post2662440


    Bring this to the next level:
    * You can add audio
    * You can use other ways to trigger the faceplate (bluetooh, IR, accelerometer..etc) easily added in the base code below



    Example vids:
    http://youtu.be/VzPivAzSb5M

    My personal (final) video: (servo, lights & sounds)
    http://youtu.be/cTXt8l2XH-Q

    *using a 'custom' Arduino board I made (it has built-in Waveshield/microSd..etc all on-board).. roughly same size of a Nano
    *plays audio (.wav file from SD card)
    ref pic: http://dmstudios.net/misc/scab_assembly/flash_board.jpg



    First version of code posted: (eye blink code only)

    Code:
    // IronMan Helmet: eye blink sequence_v1.0
    // created by: xl97
    
    
    // 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
    
    /* we always wait a bit between updates of the display */
    unsigned long delaytime = 1;
    unsigned long fadespeed = 500;
    unsigned long blinkspeed = 100;
    unsigned long currentPWM = 0;
    
    #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
    
    
    //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);  
      Serial.print("INTIT STATE: ");
      Serial.println(state);
    
      //start it off
      state = S_BLINKON; 
    }
    
    
    
    
    
    void loop() { 
      switch(state)
      {
      case S_IDLE:
        // We don't need to do anything here, waiting for a forced state change...like button press.
        break;
    
      case S_BLINKON:
        //do blink routine here
        analogWrite(leftEye, 155);
        analogWrite(rightEye, 155);
        delay(blinkspeed);
        analogWrite(leftEye, 0);
        analogWrite(rightEye, 0);
        delay(blinkspeed);
        analogWrite(leftEye, 155);
        analogWrite(rightEye, 155);
        delay(blinkspeed);
        analogWrite(leftEye, 0);
        analogWrite(rightEye, 0);
        delay(10);
        currentPWM = 0;
        
        state = S_LEDON;    
        break;
    
      case S_LEDON:
        Serial.println("increase........");
        analogWrite(leftEye, currentPWM);
        analogWrite(rightEye, currentPWM);
        lastTime = millis();  // Remember the current time
        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 + delaytime)
        {
          if(currentPWM < 255){
            currentPWM++;
            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
        state = S_WAITOFF;
        break;
    
      case S_WAITOFF:
        // If one second has passed, then go back to state 2.
        if(millis() > lastTime + delaytime)
        {
          if(currentPWM > 0){
            currentPWM--;
            state = S_LEDOFF;        
          }
          else{
            state = S_LEDON;
          }
        }
        break;
    
      default:
        state = S_IDLE;
        break;
      } 
    }
    



    Second version of code: (eye blink and servo)

    *Summary:

    1.) 1 x button (digital pin 2) controls both open and close operations
    2.) when OPEN.. the servos will close and then trigger the led 'blink & fade in' routine
    3.) when CLOSED... the leds will fade out then the servos will 'open'.

    should be a very scalable and easy editable sketch so far:
    Code:
    // IronMan Helmet: eye blink sequence_v1.0
    // created by: xl97
    // Movie Props, Costumes and Scale Models | the RPF thread: 
    // http://www.therpf.com/f24/iron-man-m...ml#post2647126
    
    //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
    int pos = 0; // variable to store the servo positions
    int pos1 = 180;
    
    // 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 delaytime = 1;
    unsigned long blinkspeed = 100;
    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
    
    
    
    //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
        analogWrite(leftEye, 155);
        analogWrite(rightEye, 155);
        delay(blinkspeed);
        analogWrite(leftEye, 0);
        analogWrite(rightEye, 0);
        delay(10);
        /*
        analogWrite(leftEye, 155);
        analogWrite(rightEye, 155);
        delay(blinkspeed);
        analogWrite(leftEye, 0);
        analogWrite(rightEye, 0);
        delay(10);
        */    
        currentPWM = 0;
        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 + delaytime)
        {
          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 + delaytime)
        {
          if(currentPWM > 0){
            currentPWM -= 5;
            state = S_LEDOFF;        
          }
          else{
            Serial.println("@ 0 done........");
            state = S_SERVOUP; //leds off..raise faceplate
          }
        }
        break; 
    
      case S_SERVOUP:
        myservo.write(100);
        myservo1.write(100);
        //delay(20); //wait to trigger the led flicker.. will remove delay() use in next revision
        state = S_IDLE;
        Serial.println("servo up.........");   
        break;
    
      case S_SERVODOWN:
        myservo.write(0);
        myservo1.write(0);
        delay(20); //wait to trigger the led flicker.. will remove delay() use in next revision
        state = S_BLINKON;
        Serial.println("servo down.........");   
        break;
    
      default:
        state = S_IDLE;
        break;
      } 
    }

    3rd version of code:

    * 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/wait...etc)

    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;
      } 
    }

    Wiring:

    [​IMG]


    Hopefully this will clear up confusion, and offer people a FREE alternative to other justtaking the free work posted and making a profit from it.


    Any questions, just ask. (I also suggest reading through the whole other thread for completensss and understanding) :)
     
    jasonamigo23, Dio, Radigast and 4 others like this.
  2. devildog12

    devildog12 Active Member

    Trophy Points:
    361
    wait...i'm confused lol jk :D
     
  3. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    lmao!!! 'you' (for sure), should not be confused! ;)


    (cant wait to see the final voice recog) :)
     
  4. ubcs86

    ubcs86 Active Member

    Trophy Points:
    242
    Ah! Perfect! Thanks for compiling!
     
  5. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    if anyone uses my code/diagram, post up your finished product/project.. :)
     
  6. IronMeg

    IronMeg Active Member

    Trophy Points:
    361
    Thank you so much for condensing this! I've always really wanted to do this, but I found the other thread to be VERY confusing. This, I might be able to give it a shot.
     
    RichLather and Bogleo like this.
  7. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    post back if you need help.

    As long as you follow the diagram posted here, the code should work as well..

    (slight difference in wiring between my code and memebers code there.. and the wiring matches those changes)

    I would say first get the servo portion up & running.. then work in the leds and whatever else you want to add. :)
     
  8. IronMeg

    IronMeg Active Member

    Trophy Points:
    361
    Thanks! It'll be a while before I can actually work on it but it is very much something I've always wanted to do.
     
  9. Ikras

    Ikras Active Member

    Trophy Points:
    487
    I'm aiming to start work on this shortly and it's a great help having it summarised in this way. I've got most of the bits I need but was looking to check some details about the capacitors with the voltage regulator. I saw in the other thread that those are smooth out any variations from the battery but what determines the values you've chosen?

    I've got a large of pack with a range of values (but not the particular ones you've got in the diagram) and I'm just trying to work out the origin of those numbers.
     
  10. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    the capacitors used on the voltage regulator will be determined by the specific voltage regulator used.

    whatever one you use, check out the data sheet, it should tell you what values to use.
     
  11. jediknight

    jediknight New Member

    Trophy Points:
    2
    hey guys, im a total noob, could you write out a shoping list of everything i will need, im from the uk and will probably be buying from ebay.co.uk :) im looking to have the servo and eyes, many thanks!!!!
     
  12. fishertime

    fishertime New Member

    Trophy Points:
    4
    May I copy this post to oher site and tlanslate another language?
     
  13. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    I dont see why not. :)


    Just make sure credit goes to where it needs to go.

    Both myself and member "memebr" have contributed a lot of time and info to these two threads/posts... (while others may think they know or did it themselves, or are even profiting from the free work shared here... in reality, no one else contributed anything or truly understood what was going on)

    please post links or pm? to the other sites shared on.

    thanks
    -xl
     
  14. Murdoch

    Murdoch Sr Member RPF PREMIUM MEMBER

    Trophy Points:
    2,286
    Proper credit is proper all around.
    Thanks guys for this...GM
     
  15. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    not quite sure what the first line means?


    but if your truly saying thanks!.. then no problem!

    glad to have helped someone bring their prop to the next level!! :)

    (just irks me a bit that some have taken the diagrams, code..etc and tried to profit from it)
     
  16. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,
    I'm new here and recently want to start the Iron Man helmet project. Right Now I'm working on the Electric part and following your instruction. I want to try virtual simulation before I actually hands on these electric parts. I used the website called 123D to do the simulation. Below is what I did.
    Test.jpg
    Hope the graph doesn't look too messy. After I load the code, nothing happening. The code I used is your "IronMan Helmet: eye blink sequence_v1.0" code.

    I'm not sure if I connect everything correctly, since I have no background in electric at all.

    One more thing, I couldn't find the vregulator LM7805 under the add components section on 123d's website. So I used pmos instead.

    Could you give me a hand on this?

    Thanks

    Dio
     
  17. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    Hi-

    Not familiar with the 123D site.. (might have to check it out)

    what is a PMOS? the LM7805 is a voltage regulator.. that also required some capacitors to run properly.. (which I think you have in your schematic?)

    hard to tell but it looks mostly correct.. what I dont see (which may very well be there.. but not visible with that diagram) is the lines/pins out to the transistors that switch on/off the eye leds?

    might be easier to just get a breadboard and prototype things up instead of the simulator..
     
  18. Dio

    Dio Jr Member

    Trophy Points:
    92
    HI

    Thanks for the quick reply.

    PMOS is showing as "pMOS Transistor (MOSFET)" on the 123D website (https://123d.circuits.io).

    I did add two capacitors just like your instruction. The problem is in your instruction I see the power source is linked at the top left comer as below (I circled blue) :

    IronMan_circuitLayout_xl97.jpg

    However, on the 123D website they don't have this option. So I linked positive to 5v and negative on the GND both on tthe POWER section showing on the UNO R3 board.

    The reason why I use 123D is they have the start simulation function so after I link all the parts together and upload the code, it can virtually show how the result looks like.

    I tried to find some other virtual simulation software but they are not free such as VBB. I also tried Fritzing but it is for schematic only, no simulation.

    If you know any other good simulation software, could you let me know?

    I redid another screenshot. hoe this looks better:

    Test 1.jpg

    I connect both led to the 0.1 uf Capacitor.

    I don't know if you have a schematic with the breadboard? I saw your comments saying that the Jump Wire can be used for temporary test due to their voltage limitation is not suggested for a long run.

    I have order the package on amazon but since it come from china the ETA showing as begin or middle of March. So I thought I may play around with the virtual simulation to be prepared. Just want to make sure I don't burn any of the actual parts. If I do, it will take another 1 and half month for the new one arrive:cry

    Really hope I can get it work.

    Thanks

    Dio
     
  19. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    Is this compatible with led sheets ? :)
     
  20. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    I have never worked with EL wire or sheets before...

    so I am not sure about the PWM..etc of them.. (or how it works with the inverter)


    in theory though... if you need to trigger/power something the Arduino cant.. but need the Arduino to 'control' that triggering.. this is the same approach.
     
    Dio likes this.
  21. xl97

    xl97 Sr Member

    Trophy Points:
    1,711


    couple of things..

    1.) You need a voltage regulator.. MOSFET is not the same thing.
    2.) You are NOT using a regulated +5v power source.. so you should be connecting to VIN on the Arduino.. not +5v..

    Maybe try using a regulated +5v (maybe the PSU component in 123D?).. if it can be set to a steady voltage.. (not sure how)..

    then you can connect to the Arduino +5v pin.. as well as remove the MOSFET and caps.. and run the simulation.. although this wont be the final design you need to implement into the helmet.. but if you want to try and simulate.. that might get you closer to a working circuit.
     
    Dio and devildog12 like this.
  22. devildog12

    devildog12 Active Member

    Trophy Points:
    361
    Ideally you wanna have your servos connected to a 5v regulator because if not, there is going to be alot "noise". This is going to lead to random servo movement when you don't want it, not moving at all, or even moving really slow. A common 5v regulator that I use is the L7805- it outputs 5v at 1.5 amps I believe. http://www.mouser.com/ProductDetail/STMicroelectronics/L7805ACV-DG/?qs=UOUhb9503hEO7qX1qhGGyg==

    - - - Updated - - -

    EL sheets usually have their own inverters which means most of the time they can't be integrated into different circuits.
     
    Dio and tijojo98 like this.
  23. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    I didnt see one in the app/simulator he wants to use (is using).. (a voltage regulator)
     
  24. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    Thanks for the suggestion. Here is what I did.

    I did follow your second suggestion and it start working. I also find that the simulation software set the power source default to 5v. So I removed MOSFET and 0.33uf capacitor (I assume this is for the LM7805 (MOSFET in my case) only)

    After that this is how it looks like when I power it on:

    Test 3.jpg

    However after I push the pushbutton it looks like this:

    Test 4.jpg

    As you can see the good thing is the lights are turned on. But the servo turned downward instead of back up.

    May I ask how should I fix this issue?

    Seems like I'm really close:)

    Thanks

    Dio
     
  25. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi Devildog12,

    Thanks for this knowledgeable info. Will keep this in mind.

    Dio
     
  26. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    @Dio-

    I tried the 123D circuits thing.... seems to be working for me.

    open the serial monitor and watching the output..

    and shouldnt the faceplate (servos) be down when the lights are on? and off. when the face plate is up? (seems correct to me)..

    when you power it on for the first time.. it opens the face plate up.. so you can see..get your head in..etc.. initial button press closes it.. and starts eye sequence.


    simulation text:
    https://123d.circuits.io/circuits/1601796-arduino-motorized-iron-man-faceplate-simulation



    you can play with the servo open/close angles.... but really that wont matter too much until you get to installign things.. and how you mount the servo..and what angles you'll need to adjust to for your own setup
     
    Last edited: Feb 13, 2016
    Dio likes this.
  27. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    How do we take a circuit from the arduino uno and plug it on a mini ?

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  28. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi Xl97,

    Thanks for the explanation. Now I'm just waiting my shipment and try it in real:D

    About the 0.33uf and 0.1uf polarized capacitors. They are to ensure the stability of the circuit, right?

    By the way do you know any good source about the hinge system?

    Thanks

    Dio
     
  29. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    Its no different..

    Min just doesnt have barrel jack.. on-board USB..etc..

    all the same pins match up..

    - - - Updated - - -

    Yes.. the caps are for the voltage regulator.. to smooth things out.. (decoupling it is referred to as)

    I would suggest using them.. some regulators may not even work without them.


    As far as the hinge stuff goes.. I do not. As every helmet is unique and the place is unique.. I find its always a custom job.. not real one size fits all.. (unless it made for a specific run of casts..etc)

    but there have been so many good ideas.. Im sure one will suit your needs.
     
  30. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    Thanks for all your help. Will keep you posted once I received my electric parts:)

    Have a good day.

    Dio
     
  31. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    Sorry to bother you again. I have another question. If I want to replace the button to an IR sensor, which part of your code need to be change? I just realize the UNO starter kit that I bought has IR sensor and IR remote. If there is a way I can replace the button to the IR senser then I can control the helmet remotely, right?

    Thanks

    Dio
     
  32. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    should be a simple drop in replacement? I think pin....2? is the button? I'd have to look at the code.. how many wires are on the PIR sensor? link to part?
     
  33. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    Sorry about the late reply. It looks like this:

    IR Sensor.jpg

    It also come with a IR Remote. Looks like this:

    IR Remote.jpg

    You are right, pin 2 is for the button. What I have heard is that it also need to program the remote to control the sensor. Since I have no background, not sure what to do next.

    Dio
     
  34. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    not sure about the remote part...

    but when sending a signal/command to the sensor.. what does it send out from the 'out' pin?

    I think there are some basic IR tuts out there...

    looks like its a bit more involved than a reed switch:

    https://www.youtube.com/watch?v=iFpAqG90zY0

    I'm sure it can be done.. but the code above wont work as is.
     
    Last edited: Feb 16, 2016
  35. Dio

    Dio Jr Member

    Trophy Points:
    92
    I have no idea about the out pin. I just find out that the UNO starter kit I bought include these two parts. So I thought this is may be a good idea to remote control the helmet:D

    The 123D site has these parts as well.
     
  36. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    from what I saw in the vid.. looks like it spits out some hex code (or something).. matching whatever button was pressed.
     
  37. Dio

    Dio Jr Member

    Trophy Points:
    92
    This is what I find on the web for turn on and off led code for IR sensor:



    #include <IRremote.h>


    int RECV_PIN = 11;
    int LED = 10;
    IRrecv irrecv(RECV_PIN);
    decode_results results;


    void irdisplay(unsigned long value)
    {
    switch(value){
    case 0xFFA25D:
    digitalWrite(LED, LOW);
    break;
    case 0xFFE21D:
    digitalWrite(LED, HIGH);
    break;
    }
    }


    void setup()
    {
    pinMode(LED,OUTPUT);
    Serial.begin(9600);
    irrecv.enableIRIn();
    }


    void loop() {
    if (irrecv.decode(&results))
    {
    irdisplay(results.value);
    irrecv.resume();
    }
    }

    Just wonder how should I apply this code into your code.
     
  38. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    I think I figure it out. I tired the modified code on 123D and it seems working.

    Here is the code:



    //import servo lib
    #include <Servo.h>
    #include <IRremote.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 = 1; //delay between init blink on/off
    unsigned long currentPWM = 0;
    boolean isOpen = true;
    int openAngle = 180;
    int closeAngle = 0;


    #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.


    //New
    int RECV_PIN =2; // 红外线接收器OUTPUT端接在pin 2
    IRrecv irrecv(RECV_PIN); // 定义IRrecv 对象来接收红外线信号
    decode_results results; //解码结果放在decode_results构造的对象results里


    void irdisplay(unsigned long value) // 按下按键后,显示本遥控对应的按键
    {
    switch(value){ //判定按下的是哪个按键,串口显示按钮名称
    case 0xFD00FF:
    digitalWrite(RECV_PIN, LOW); //电源键按下,执行关闭LED灯
    break;
    }
    }
    //New End


    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(openAngle);
    myservo1.write(openAngle);
    state = S_IDLE;
    break;


    case S_SERVODOWN:
    lastTime = millis(); // Remember the current time
    Serial.println("servo down.........");
    myservo.write(closeAngle);
    myservo1.write(closeAngle);
    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;
    }
    }

    The color in red is what I added on your code. For the IR sensor, I connect the gnd pin to gnd, vcc pin to 5v and out pin to 2 on the R3 board.

    Could you help me check it out? I just want to make sure there is no mistake.

    Thanks

    Dio
     
    Last edited by a moderator: Nov 8, 2018
  39. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    How do we put text in the code editor please when I open it i cant add text is it normal ? :)

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
    Last edited by a moderator: Nov 8, 2018
  40. Dio

    Dio Jr Member

    Trophy Points:
    92
    Not sure what do you mean by out text in the code editor. What code editor you are using?
     
  41. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    On 123d

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  42. Dio

    Dio Jr Member

    Trophy Points:
    92
    I think you turn the "start simulation" on. In that mode you can't edit the code since the system is currently using it. Just turn it off then you will be able to add text again.
     
  43. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    Oh ok thank you :)

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  44. Dio

    Dio Jr Member

    Trophy Points:
    92
    No problem:)
     
  45. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    I dont think that will work as you have it... doesnt look complete.

    You havent added in any code to actually check the code being sent form the remote..

    looks like you have added a function to do so.. but where is that function being called?

    You'll probably want to put the sensor on another pin.. .. and then when you get a code that you identify as being the open/close command..

    toggle the pin2 (basically you wont have a push button anymore.. you will check the sensor.. and have code toggle the pin for you..

    before this line.. you'll want to check the IR code.. and pull pin2 low..

    then probably after this line..

    lastButtonState = buttonState;

    you want to put the pin2 back to its original state..


    Your code also looks suspicious to me as well..

    have you tried following this tutorials instead:

    https://brainy-bits.com/tutorials/ir-remote-arduino/
     
  46. Dio

    Dio Jr Member

    Trophy Points:
    92
    Hi xl97,

    Since I have no electric code background, I just the cut from the IR control LED code that I posted earlier and then paste into your code at the position that I think is right.

    I haven't check this tutorial yet will check it and see if I can figure out something.

    Thanks
     
  47. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    I think im gonna keep it simple and use 7sinzz tutorial since that i dont know anything in electronic and programming if I follow this tutorial is it going to be good? And how can I stop the little servo sound in rest position ?

    Envoyé de mon SM-G530W en utilisant Tapatalk
     
  48. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    most of the code in 7sinnzz tutorials is mine.. so feel free to follow whatever you want.
     
  49. tijojo98

    tijojo98 Active Member

    Trophy Points:
    467
    Can we stop the sound the servo make in rest position that sound like they are always moving a littlebit ?
     
  50. xl97

    xl97 Sr Member

    Trophy Points:
    1,711
    you can adjust the servo position in the code..

    while they may say 180 degree servos... most can NOT move a full 180 degree..

    change the angle in the code.


    also,.. make sure you have all grounds connected.
     

Share This Page