Iron man motorised faceplate electronics tutorial!!!

ok,

you gonna need to make some changes on the code

depending on the code you are using:

change the minimum value (0º) to 5º
change the max value (180º or 175º) to 140º

Use this code to test it out:
Code:
#include <Servo.h>
//servo 1
Servo myservo;
Servo myservo1;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState;
int servostatus = 0;
int switchPin = 2; // Switch connected to digital pin 2
int ledPin = 5;
void setup() // run once, when the sketch starts
{
//servo 1

myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(5);
myservo1.write(140);
}

void loop() // run over and over again

//servo 1
{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (servostatus == 0) { // is the light off?
servostatus = 1; // turn light on!

myservo.write(5);
myservo1.write(140);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(5);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(5);


// fading
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delay(30);


}

} else {
servostatus = 0; // turn light off!


digitalWrite(ledPin, LOW);
delay(15);
myservo.write(140);
myservo1.write(5);






}
}
}
buttonState = val; // save the new state in our variable
}
}



and try again, your electric setup is good now, it should work without any problems now.

also, i have a question, are those digital servos?
 
Last edited:
ok,

you gonna need to make some changes on the code

depending on the code you are using:

change the minimum value (0º) to 5º
change the max value (180º or 175º) to 140º

Use this code to test it out:
Code:
#include <Servo.h>
//servo 1
Servo myservo;
Servo myservo1;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState;
int servostatus = 0;
int switchPin = 2; // Switch connected to digital pin 2
int ledPin = 5;
void setup() // run once, when the sketch starts
{
//servo 1

myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(5);
myservo1.write(140);
}

void loop() // run over and over again

//servo 1
{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (servostatus == 0) { // is the light off?
servostatus = 1; // turn light on!

myservo.write(5);
myservo1.write(140);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(5);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(5);


// fading
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delay(30);


}

} else {
servostatus = 0; // turn light off!


digitalWrite(ledPin, LOW);
delay(15);
digitalWrite(ledPin2, LOW);
myservo.write(140);
myservo1.write(5);






}
}
}
buttonState = val; // save the new state in our variable
}
}



and try again, your electric setup is good now, it should work without any problems now.

also, i have a question, are those digital servos?


I will try that now. Thank you! The servos are EMAX ES08A microservos that came with the Arduino ultimate pack. Figured I would try with those before I use more expensive ones.
 
It should work now, most of the servos don't make 180º

if it didn't work, remove that line from the code: "digitalWrite(ledPin2, LOW);" i forgot to remove, but i edited the post i made with the code
 
That seems to be working much better. The only thing I see as an issue with this is servo 2. It moves to the fully open position (140 i assume) and then moves back half way and then back to fully open.
 
That seems to be working much better. The only thing I see as an issue with this is servo 2. It moves to the fully open position (140 i assume) and then moves back half way and then back to fully open.

Thats normal with the setup you are running now!

To avoid that use a battery pack to power the servos, make sure to regulate it to 5V, otherwise you will burn them!
 
Last edited:
Thats normal with the setup you are running now!

To avoid that use a battery pack to power the servos, make sure to regulate it to 5V, otherwise you will burn them!

Thank you for all of your help. I will mess around with it a little bit. As for regulating it to 5V, do you mean once I remove the breadboard and use a power supply? Also, do you have any suggestions on better servos?
 
Thank you for all of your help. I will mess around with it a little bit. As for regulating it to 5V, do you mean once I remove the breadboard and use a power supply? Also, do you have any suggestions on better servos?


Been told this is a great servo T-Pro MG996R HIGH TORQUE METAL GEARED DIGITAL SERVO. As it states it as metal gears rather than plastic hope that help :)
 
The MG995 is faster than the 996R, both are the same servo actually, but the 996 have slightly different gears sizes to make the torque a lil bit better, and that reduces the speed.

all of these are 55g servos, except the 996R that is 65g

MG995 -> 11~15kg/cm²
MG996 -> 11~13kg/cm²
MG996R -> 15~19kg/cm²

All are sold under the brand: Tower Pro
 
You guys have all been very helpful. I was able to get everything working, after a lot of issues and trial and error. Next step I will be putting everything together without the breadboard as soon as I pick up my new servos. I'm sure I will be back here asking more questions. Thank you all.
 
Hi all.
Getting much closer in finishing the mechanism for my helmet.
Electronics are still getting on my nerves.. not my specialism so 2 speak.

Most of it works but i cant seem to figure out how to get my electronics to work with an external power source.
My setup is really like in the first post. now with the breadboard and my arduino nano attached..

With the usb from my Imac to the NANO, the 2 servos work perfectly directly of the Nano 5V output.
I first tried to attach a 9v battery to the Vin of the Nano. and a 6V (4AA) batterypack to the servos. Did not work. Switch didnt work, light did not came on, and on of the servos fried! (yes i also tried 4 rechargable AA = 4,8V). NO Working servos.

Then i yesterday came across a GP portable USB charger, that gives 5V and 1000 Mah output. Same as a PC. But still didnt work. light of the NAno was on but no servo action and light action. I really thought this little thing was the perfect solution. WHERE DOES THIS GO WRONG?

Also i have little trouble with the light. I first tried LEds in serial, but for best light result i want to attach a 9V battery to the LED strips i bought. They light up really nice. The only problem i have now... How to attach this to the NANO to get the blinking and fading effect. Will some kind of Relais do the trick? S/+/-?

Any help would be VERYYYYY welcome.

Thanks guys!
 
So I have a bit of an update and wanted to share as well as get a few opinions. After plug and testing everyone's code. I realized quickly I had no idea what I was doing. So, I bought a book to learn a little about programming the Arduino. I read through the entire thing and came up with some code that works for me (mostly).

I dont plan on using the led's in conjunction with this circuit for a few reasons. The biggest reason is I dont want wires connecting from the back of the helmet to the faceplate and worrying about clearance when the faceplate opens and closes. So, I made them separate. I will keep all of my LED eyes wired directly to the back of the faceplate, and the motorized faceplate will be in the back. Problem solved.

So one thing that I wanted to do was find a center position of the servos at 90 degrees. I added that to the initial set up of the code so that when you power the circuit up, the servos move to the center position. I did this for two reasons. First I want the faceplate to be up when put on or take off the helmet so the center (90) position will have both servos facing up through the top slits of the helmet. I also did this so that when I originally mount them in the helmet I can get them lined up perfectly because that could cause issues if they were even a few degrees off. The coding then tells the servos to move in opposite directions by 90 degrees(either to 0 or 180).

Below is the simple code I created for this process and seems to work really well. Again this is for anyone who wants to use the faceplate without the led eyes being controlled by the same circuit. This is also will only work if you have the faceplate installed in the up position.

Code:
#include <Servo.h> 
 
Servo leftservo;  // create left servo object 
Servo rightservo;  // create right servo object
// this constant won't change:
const int  buttonPin = 2;    // pushbutton attached to pin 2
// Variables will change:
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int buttonPushCounter = 0;   // counter for the number of button presses
int centerPos = 90;
boolean currentButton = LOW;

void setup() {
  
   leftservo.attach(9); // left servo attached to pin 9
   rightservo.attach(10); //right ervo attached to pin 10
  // tell both servos to go to center position
  leftservo.write(centerPos);
  rightservo.write(centerPos);
  
  delay(15); 
  
  pinMode(buttonPin, INPUT); // initialize the button pin as a input:
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}


void loop() {
  
  buttonState = debounce(buttonPin); // read the pushbutton input pin:
  
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter++;
    } 
    else {
    }

    // save the current state as the last state, 
    lastButtonState = buttonState;
  }
  
  /* moves the servo every other button push by 
  checking the modulo of the button push counter.
   the modulo function gives you the remainder of 
   the division of two numbers: */
  if (buttonPushCounter % 2 == 0) {
  //move to position 90  
   rightservo.write(centerPos); 
   leftservo.write(centerPos); 
   delay(15); 
  } else {
  //OR: move back to position 0  
   leftservo.write(0); //move left servo 90 degrees ccw from center
   rightservo.write(180); // move right servo 90 cw from center
   delay(15); 
  } 
}

Tell me what you think, and I hope this can be useful.
 
Here are some pics of my build. :)
Photo A.jpgPhoto B.jpgPhoto C.jpgPhoto D.jpgPhoto E.jpgPhoto F.jpgPhoto G.jpg
 
Hi all.
Getting much closer in finishing the mechanism for my helmet.
Electronics are still getting on my nerves.. not my specialism so 2 speak.

Most of it works but i cant seem to figure out how to get my electronics to work with an external power source.
My setup is really like in the first post. now with the breadboard and my arduino nano attached..

With the usb from my Imac to the NANO, the 2 servos work perfectly directly of the Nano 5V output.
I first tried to attach a 9v battery to the Vin of the Nano. and a 6V (4AA) batterypack to the servos. Did not work. Switch didnt work, light did not came on, and on of the servos fried! (yes i also tried 4 rechargable AA = 4,8V). NO Working servos.

Then i yesterday came across a GP portable USB charger, that gives 5V and 1000 Mah output. Same as a PC. But still didnt work. light of the NAno was on but no servo action and light action. I really thought this little thing was the perfect solution. WHERE DOES THIS GO WRONG?

Also i have little trouble with the light. I first tried LEds in serial, but for best light result i want to attach a 9V battery to the LED strips i bought. They light up really nice. The only problem i have now... How to attach this to the NANO to get the blinking and fading effect. Will some kind of Relais do the trick? S/+/-?

Any help would be VERYYYYY welcome.

Thanks guys!


Did you use a voltage regulator when connecting the servos to external battery power? 6v should have been ok , but I guess it depends on the servo and if it was really only putting out 6v. I tested mine with a multimeter and my 6.5 v power supply was actually putting out 7.2. Thankfully I had bought some voltage regulators already. My opinion, you should definitely check your voltages and current (for LED's) even with the regulator to make sure you are not above the voltage specifications.
 
Did you use a voltage regulator when connecting the servos to external battery power? 6v should have been ok , but I guess it depends on the servo and if it was really only putting out 6v. I tested mine with a multimeter and my 6.5 v power supply was actually putting out 7.2. Thankfully I had bought some voltage regulators already. My opinion, you should definitely check your voltages and current (for LED's) even with the regulator to make sure you are not above the voltage specifications.

Mike, no i didn"t use anything between. Didn't think is wat necessary. But also with the 4AA rechargables, 4.8V it didnt work.
But my biggest surprise was that the GP external Power charger for ipad and stuff didnt work... i really hoped it would.
 
Mike, no i didn"t use anything between. Didn't think is wat necessary. But also with the 4AA rechargables, 4.8V it didnt work.
But my biggest surprise was that the GP external Power charger for ipad and stuff didnt work... i really hoped it would.

Did you try the 4.8v before after you used the 6v? The servos could have already been damaged.
 
Back
Top