Iron man motorised faceplate electronics tutorial!!!

how much current can you pull form the battery pack? is it fully charged?

it probably doesnt have enough voltage for the servo's.. (they might need 6v)..

or it cant provide enough current for the servos.. (but you said they werent under load?.. so I'm ot sure.. they can each take up to 1A when under load I believe)

you said it doesnt buzz when you hook up only one.. either one?.. if both work individually without buzz.. then I'd say they fine.. and the Arduino is fine as well..

I feel like its more power related..

do you have a bench top power supply? use that to power the servos.. (skip the regulator..and give stable 6v...not 5v)

So i've tested some more and I couldn't find it.The testing was confusing. 1 time it did'nt buzz and next it did buzz. So went to my local electronics store and bought an arduino uno.
Just to make sure my nano wasn't broken. changed some wiring(again). and used the capacitors. Now de buzzing is only very light or a little buzz and then it stops.
So I think I will leave it at that. I tried everything I can think off, except changing the accu pack(will do that in time need to find a good pack and charger and battery holder,any idea?).Maybe now I'm just nitpicking but I'm happy for now.

So, now on to the code. XL95, I used your code and altered it a bit. When i removed the battery and reconnected it the servo's got out of alignment. So when you have the faceplate
on it is going crooked when you power it.I have altered the code so that it does not go out of alignment as much,only a little. can you maybe take a look at my (your)code ;)
and tell me if I did it right. 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
int pos = 120;
int pos1 = 40;

// 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
  myservo.write(40);
  myservo1.write(120);
  }
  

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(200);
    //two blinks
    
    analogWrite(leftEye, 155);
     analogWrite(rightEye, 155);
     delay(blinkSpeed);
     analogWrite(leftEye, 0);
     analogWrite(rightEye, 0);
     delay(150);
     //three blinks
         analogWrite(leftEye, 155);
     analogWrite(rightEye, 155);
     delay(blinkSpeed);
     analogWrite(leftEye, 0);
     analogWrite(rightEye, 0);
     delay(100);
     //four blinks
         analogWrite(leftEye, 155);
     analogWrite(rightEye, 155);
     delay(blinkSpeed);
     analogWrite(leftEye, 0);
     analogWrite(rightEye, 0);
     delay(40);
     
     
    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(120);
    myservo1.write(40);
    state = S_IDLE;    
    break;

  case S_SERVODOWN:
    lastTime = millis();  // Remember the current time
    Serial.println("servo down.........");   
    myservo.write(40);
    myservo1.write(120);
    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;
  } 
}
 
I believe there are some steps you should/need to do to servo the servos out... I dont recall off hand.. and not sure I even did it.. but read it over on the Arduino.cc forums..

sending a pulse to some position.. then attaching any arms at that point.. so when they power on.. they start at (whatever) position.. and move accordingly..

as far as the code.. what parts did you edit..

you should only really need to edit the:

int pos = 120;
int pos1 = 40;

positions..


so one goes clockwise (so to speak), and the other goes counter-clockwise..
 
Some updates for setting up the servos people use: (as I had mentioned before)

1.) Whenever you get a new servo, you need to send a 1500 usec pulse to center it, then check that the servo horn is positioned to the proper central position, and remove and re-position if necessary.

2.) You should .write() the position you want to start at BEFORE you .attach() the servo pin. If you don't specify a position first it will head for some default position and then possibly change direction when you do the first .write().

Once the servo position is set and the servo attached it will try to maintain that position until you specify a new position or detach.


If you notice.. #2 is NOT done in my code ....

I would do #1... then switch the lines of code in my supplied code example..

see if this helps anyone with their servo troubles/movement range..etc
 
I finally got it working! The servo's don't buzz anymore. I supplied my servo's with a separate battery pack of 4 aa's.
tried this before and must have done something wrong. I think the nicd pack I'm using is also the culprit. I now ordered a li-ion pack to power everything. Thank's xl95 and others for your input. Next is to get the servo's to align properly. I will try the suggestions you made in your last post. Don't know if I have the time for it because in the next month or two I will be moving to another house.
 
Good news butbull! :)

giving the servo's 6v and separating power supplies... (still keeping all grounds tied together though...correct?)
 
Haha, you called me buttbull.LOL. that was funny. Anyway, yes I tied all the grounds together. I think I screwed up the last time. When you try different setups it is easy to overlook something. Thanks again!
 
Doh!.. was a typo! (U and I keys are right next to each other!) But in fairness you called me xl95! HAHA..

I understand fully.. things are new.. your scrambling for a fix.. trying different suggestions from many people.. it all kind of blurs together! :)

No worries.. as long as it all works in the end! thats what counts!
 
Oh cr*p! You are right. Well we are even then XL97.LOL.

Well on to the next problem to tackle.
Cheers.
 
Last edited:
haha.. no worries! (I dont care about that one bit)

just glad it all worked out for ya in the end!

post up pics when your done!
 
Reading the thread and thinking to myself: i still need to finish my helmet.

I might start a new project soon (another helmet, the last one got a little weird with the time)

Sent from my toaster using Tapatalk.
 
(has same thoughts)..

I put some time into a helmet I got, and was on the fence about if putting in the time & effort was even worth it... (I believe it to be a bit warped, not symmetrical..etc) :(

if I could pick up a nice 3-piece helmet for a decent price, I would get it... but most are $200+ which is a bit pricey IMO.. with all the rest of the work that needs to go into it. (finishing, priming, painting, electronics....etc..etc)

might need to get off my lazy behind and sling some electronics kits to get some spending cash! :)
 
So had some time today, can't figure out why the servo's go out of alignment for 1sec and the move to the correct position. the servo's move in oposite direction's,
so when you have the faceplate on it wil get crooked. I tried everything I can think of but no luck.

Some updates for setting up the servos people use: (as I had mentioned before)

1.) Whenever you get a new servo, you need to send a 1500 usec pulse to center it, then check that the servo horn is positioned to the proper central position, and remove and re-position if necessary.

2.) You should .write() the position you want to start at BEFORE you .attach() the servo pin. If you don't specify a position first it will head for some default position and then possibly change direction when you do the first .write().

Once the servo position is set and the servo attached it will try to maintain that position until you specify a new position or detach.


If you notice.. #2 is NOT done in my code ....

I would do #1... then switch the lines of code in my supplied code example..

see if this helps anyone with their servo troubles/movement range..etc

Tried this but no luck. Even with a simple servo sketch it keeps happening.
I'm wondering if other people have had these problems.
 
I have not tried to align/set my servos yet.. (no real bucket to work with unfortunately... maybe I'll trade an electronics kit with audio like in my video for a nice bucket?) :)

anyways...

how are you initially centering your servos? and then setting the 'arms'?

did you update the code as well?
 
Got my li-ion battery's, holder and charger today.wired everything back up to power off 1 power source.And guess what. It all works great!!!. No buzzing, no twitching, no going out of alignment when powering up,nothing. Finally I can get the stuff into my helmet.:D. So thank's again u all.
 
that set-up wont work.

you should use 9v batteries.. they stink.. and usually not enough current.

you look to be missing resistors

I see no transistors? any single Arduino pin can usually drive (power) no more than 1 maybe 2 pins. (depending on the current you give each one)

there are several diagrams posted here that are safe and work..
 
thanks for answering , which are neither to serve the components is the first thing I do with hardware and arduino , hope to go slowly learning , I will try to use your designs and programs to see if I understand this world a little more :)
A Greeting.
 
(kinda hard to understand because of the language barrier)

but in general, some thing sot keep in mind..

1.) Any single Arduino pin can only give roughly 20mA of current to any device/component. (some say 40mA is the limit..but safely 20mA)
that means only low current accent leds and other small current pull parts.. not motors, servos, high powered leds..etc. as they will fry/blow your Arduino. (worst) or not work (best)

2.) An Arduino can (depending on which one you have) needs +5v or +3.3v to run.. you can usually use a higher voltage battery pack since there is an on-board voltage regulator. That being said.. its still not great to power the Arduino from say 12v.. when the Arduino only needs +5v.. that means roughly 6+ volts or being dropped/chopped by the regulator, and turns into heat (heat + electronics = bad!)

3.) Most of the time an Arduino is just used to CONTROL devices.. (not power/drive them).. and they use a transistor/MOSFET/relay to control the power given tot he device.

4.) Many components/parts require a different (often higher) voltage/power source than the Arduino.. Using separate/unique power sources is often done.. but make sure you connect all GNDs together..


For this type of project.. your servos probably require a REGULATED +6v.... (and your Arduino of course gets +5v.. or whatever you connected to vRegulator which regulates it to a steady/stable +5v)

you can use:

A.) separate battery packs.. connecting GNDs together with Arduino.
or
B.) single battery pack/source with 2 x voltage regulators to get your stable power sources.


Same things goes for your LEDS.. any SINGLE Arduino pin can probably power/drive 1/2 accent leds like this.. but more than that, and your exceeding the current limit the Arduino pin can provide.

So you use a transistor, to supply the power.. and the Arduino toggles that transistor.. (schematics and even board files posted here I believe)

If you have no Arduino experience. I woudl say.. walk through a bunch of single/separate tutorials.. to get comfortable with how things work..

simple blink..

then blink without delay (understanding how without delay works if KEY/ESSENTIAL for advancing to more complicated code/sketches.. (IMHO)

some basic analog & pwm tutorials...

then add in a POT to control the pwm brightness...etc


I suggest Jeremy Blum and Tronixstuff.com for a nice collection of tutorials for all levels of experience.

good luck!
 
Hello again , and I returned to do another scheme with what little they have learned and , if not beginning to be functional , make no voltage regulators or other parts ? that place should put them? Also the arduino code for the circuit did you step see what you think :)


Untitled Sketch_bb.jpg

int estadoboton1=0;
int estadoboton2=0;
int estadoboton3=0;
int estadoboton4=0;
int estadoanteriorboton1=0;
int estadoanteriorboton2=0;
int estadoanteriorboton3=0;
const int tiempoAntirebote=10;
int ojos = 13; // Pin de salida para el LED ojos
int manos= 12; // Pin de salida para los leds de manos
int arc=8; // Pin de salida para el reactor arc
int servo=11; // Pin de salida del servo
const int boton1= 2; // Pin de entrada para regular ojos y servo
const int boton2 = 3; // Pin de entrada para el arc
const int boton3= 4; // Pin de entrada para las manos
int estadob1; // Guarda el estado del boton 1
int estadob2; // Guarda el estado del boton 2
int estadob3; // Guarda el estado del boton 3
int salida1=0; // 0=led apagado, 1=encendido
int salida2=0;
int salida3=0;
int estadoanteriorb1;
int estadoanteriorb2;
int estadoanteriorb3;
int cuentab1=0;
int cuentab2=0;
int cuentab3=0;
int val;

#include <Servo.h>
Servo myservo; // Define our Servo


/*Función antirebote boton 1*/
boolean antirebote (int pin1 ) {
int contador1 =0;
boolean estado1; // guarda el estado del boton
boolean estadoAnterior1; // guarda el ultimo estado del boton

do {
estado1 = digitalRead (pin1);
if (estado1 != estadoAnterior1 ){ // comparamos el estado actual
contador1 = 0; // reiniciamos el contador
estadoAnterior1 = estado1;
}
else{
contador1 = contador1 +1; // aumentamos el contador en 1
}
delay (1);
}
while (contador1 < tiempoAntirebote);
return estado1;
}


/*Función antirebote boton 2*/
boolean antirebote2 (int pin2 ) {
int contador2 =0;
boolean estado2; // guarda el estado del boton
boolean estadoAnterior2; // guarda el ultimo estado del boton

do {
estado2 = digitalRead (pin2);
if (estado2 != estadoAnterior2 ){ // comparamos el estado actual
contador2 = 0; // reiniciamos el contador
estadoAnterior2 = estado2;
}
else{
contador2 = contador2 +1; // aumentamos el contador en 1
}
delay (1);
}
while (contador2 < tiempoAntirebote);
return estado2;
}

/*Función antirebote boton 3*/
boolean antirebote3 (int pin3 ) {
int contador3 =0;
boolean estado3; // guarda el estado del boton
boolean estadoAnterior3; // guarda el ultimo estado del boton

do {
estado3 = digitalRead (pin3);
if (estado3 != estadoAnterior3 ){ // comparamos el estado actual
contador3 = 0; // reiniciamos el contador
estadoAnterior3 = estado3;
}
else{
contador3 = contador3 +1; // aumentamos el contador en 1
}
delay (1);
}
while (contador3 < tiempoAntirebote);
return estado3;
}



void setup() {
pinMode(ojos, OUTPUT);
pinMode(manos, OUTPUT);
pinMode(arc, OUTPUT);
pinMode(servo, OUTPUT);
pinMode(boton1, INPUT);
pinMode(boton2, INPUT);
pinMode(boton3, INPUT);

Serial.begin(9600); //Iniciamos la comunicacion serial
myservo.attach(9); // servo on digital pin 9
}


void loop () {

//antirebote, encendido y servo del casco V1


estadob1 =digitalRead (boton1); //leemos el estado del boton
if (estadob1 != estadoanteriorb1) { //si hay cambio con respeto al estado
if (antirebote (boton1)){ //checamos si esta preionado y si lo esta

salida1 = 1-salida1; //encendemos el LED
delay(20);
if(salida1==1) { //Si estado esta en alto
}
digitalWrite(4, HIGH); //encendemos el LED
}
else {
digitalWrite(4, LOW); //Apagamos el LED
}
estadoanteriorboton1=estadoboton1; //Guarda el valor actual

if(salida1==1) { //Si estado esta en alto
digitalWrite(ojos, HIGH); //encendemos el LED
myservo.write(160); //Posiciona el servo
delay(150);

}
else {
digitalWrite(ojos, LOW); //Apagamos el led
myservo.write(1); //posiciona el servo
delay (150);

Serial.println (cuentab1);
}
}
estadoanteriorb1 = estadob1; // guardamos el estado del boton







//antirebote y encendido V2


estadob2 =digitalRead (boton2); //leemos el estado del boton
if (estadob2 != estadoanteriorb2) { //si hay cambio con respeto al estado
if (antirebote2 (boton2)){ //checamos si esta preionado y si lo esta
salida2 = 1-salida2; //encendemos el LED
delay(20);
if(salida2==1) { //Si estado esta en alto
}
digitalWrite(4, HIGH); //encendemos el LED
}
else {
digitalWrite(4, LOW); //Apagamos el LED
}
estadoanteriorboton2=estadoboton2; //Guarda el valor actual

if(salida2==1) { //Si estado esta en alto
digitalWrite(arc, HIGH); //encendemos el LED
}
else {
digitalWrite(arc, LOW); //Apagamos el LED //aumentamos la cuenta
Serial.println (cuentab2);
}
}
estadoanteriorb2 = estadob2; // guardamos el estado del boton


//antirebote y encendido V3


estadob3 =digitalRead (boton3); //leemos el estado del boton
if (estadob3 != estadoanteriorb3) { //si hay cambio con respeto al estado
if (antirebote3 (boton3)){ //checamos si esta preionado y si lo esta
salida3 = 1-salida3; //encendemos el LED
delay(20);
if(salida3==1) { //Si estado esta en alto
}
digitalWrite(4, HIGH); //encendemos el LED
}
else {
digitalWrite(4, LOW); //Apagamos el LED
}
estadoanteriorboton3=estadoboton3; //Guarda el valor actual

if(salida3==1) { //Si estado esta en alto
digitalWrite(manos, HIGH); //encendemos el LED
}
else {
digitalWrite(manos, LOW); //Apagamos el LED //aumentamos la cuenta
Serial.println (cuentab3);
}
}
estadoanteriorb3 = estadob3; // guardamos el estado del boton



}
 
Back
Top