Iron man motorised faceplate electronics tutorial!!!

You are the man sir... I guess you have 2 transistors because of the mAh?

Here are my servos HS-82MG Servo
HS-82mg
Current Drain (4.8V): 8.8mA/idle and 220mA no load operating
Current Drain (6.0V): 9.1mA/idle and 280mA no load operating

He have 2 transistors cause he is using 2 pins to control it individually, but he could use only 1 transistor, since the ones he is using can support 1A loads. In my case, i'm usung 2 of them cause they only support 200mA on the output, and i like to work with some extra space on the specs of the components.

and mA/h is a measure of current delivering in a period of 1 hour, the value of current usage is expressed in Amper (A) or milli Amper (mA)

seeing the specs of the servos, you can use only one LM7805 regulator for your entire project (including the leds) just make sure to use the proper resistor value for each one of the leds. (would be a very small resistor)
 
He have 2 transistors cause he is using 2 pins to control it individually, but he could use only 1 transistor, since the ones he is using can support 1A loads. In my case, i'm usung 2 of them cause they only support 200mA on the output, and i like to work with some extra space on the specs of the components.

and mA/h is a measure of current delivering in a period of 1 hour, the value of current usage is expressed in Amper (A) or milli Amper (mA)

seeing the specs of the servos, you can use only one LM7805 regulator for your entire project (including the leds) just make sure to use the proper resistor value for each one of the leds. (would be a very small resistor)

this^ lol
 
its just a generic transistor part in the diagram..

YOU pick/find/use the one that suits your final path... (size, footprint, pinout, costs, specs)

but for my SMD ones.. I am using this:

BC81725MTF Fairchild Semiconductor | BC81725MTFCT-ND | DigiKey

however.. "I" am doing separate eye pcb's keep in mind.. (so I can do battle damage effects..etc.. mine will also have sound)

looking at my image..

there should probably be some coupling caps on that voltage regulator to make things stable.. (might not even work otherwise)
 
Last edited:
there should probably be some coupling caps on that voltage regulator to make things stable.. (might not even work otherwise)

It will work without the capacitors, but it is aways smart to add filters to any kind of power supply (in that case the regulator is the power supply)

anyways, would be nice to add two 10uF capacitors, that amount should fit out the application we are using here, but if you wanna to make it even more smooth, replace the 1st cap for a 10uF and the second one for a 0.33uF (on the LM7805 1 capacitor between the pin 1 and the GND, and 1 capacitor between the pin 3 and the GND) but the 1st option with two 10uF is more used.

where you have +12 you can read as: +7~12V
img00002.gif


it is also smart to put a diode on the project, so you can avoid return current

thats the combination i figured out to my circuit... 10uF cap on the Vin and a 0.33uF ceramic cap on the Vout

20130611_225731.jpg

and yes, my breadboard is all messy with wires going every where, but i understand my ciruit :lol
 
Last edited:
its just a generic transistor part in the diagram..

YOU pick/find/use the one that suits your final path... (size, footprint, pinout, costs, specs)

but for my SMD ones.. I am using this:

BC81725MTF Fairchild Semiconductor | BC81725MTFCT-ND | DigiKey

however.. "I" am doing separate eye pcb's keep in mind.. (so I can do battle damage effects..etc.. mine will also have sound)

looking at my image..

there should probably be some coupling caps on that voltage regulator to make things stable.. (might not even work otherwise)

Current - Collector (Ic) (Max) 800mA this is the current the transistor can handle correct? If so it is the same as 2N2222. If Ic is not the current the transistor can handle then disregard this lol. Just the bc81725 is much smaller?
 
hi 7sinzz

just some inquiry on the code posted on the first page
#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 pos = 0;
int pos1 = 180;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5;
int ledPin2 = 18;
void setup() // run once, when the sketch starts

it declares here the ledpin2 = 18 where pinout up to 13 only.

in void setup >> declared ledpin2
then in void loop >> declared as ledpin

in that coding we can use two pin output ( pin 5, or pin 6) to control the LED.

BTW, i tried to change to ledpin = 6 and copy or repeat the coding but the LED output was not synchronized.

Sorry, just starting to learns SW coding.
thanks
 
Last edited:
not my code... :)


anyways..
pins above 13+ refer to the analog pins A0 = 14, A1 = 15, A2 = 16..etc..etc..



not sure what you mean by this:
in void setup >> declared ledpin2
then in void loop >> declared as ledpin

he has 2 pins it looks like.. led pin1 and led pin2? which is fine:


int ledPin = 5;
int ledPin2 = 18;

not sure what you mean by this either:

in that coding we can use two pin output ( pin 5, or pin 6) to control the LED.

BTW, i tried to change to ledpin = 6 and copy or repeat the coding but the LED output was not synchronized.
 
sorry took so long to respond, your fix did help me out but afteer doing some research i realized i needed to add an external power source as well as use my usb connection, now my problem is thta when i hit the button to make the servos move and lights come on it runs through the whole series twice, it runs the servos and the lights come on then automatically does everything in reverse and goes through it again then waits for me to press the button again i thought i needed to to reset the arduino maybe? or maybe i loaded something wrong? i dont know what i did wrong but i know its not supposed to do this, ill keep researching and if i figure it out ill let you guys know, thanks for pointing me in the right direction originally, i appreciate it
 
hi 7sinzz

just some inquiry on the code posted on the first page


it declares here the ledpin2 = 18 where pinout up to 13 only.

in void setup >> declared ledpin2
then in void loop >> declared as ledpin

in that coding we can use two pin output ( pin 5, or pin 6) to control the LED.

BTW, i tried to change to ledpin = 6 and copy or repeat the coding but the LED output was not synchronized.

Sorry, just starting to learns SW coding.
thanks

If look closer on the code you will see that besides it was called as a variable and declared as a output, the ledPin2 is not in use on the main body of the code (void loop), same thing to pos and pos1

to make that other pin ledPin2 (in your case pin 6) to work like the ledPin(5) you will need to replicate the same things to both, you need to add the same fade sequence and the same turn off point...

here its the code with both pins as leds output (5 and 6) working in synchronization.

Pin 9 and 10 = servos
pin 5 and 6 = leds

Code:
#include <Servo.h>
Servo myservo; //servo1
Servo myservo1; //servo2
int val; // variable for reading the pin status
int val2; // variable for to check consistency
int buttonState;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5; // led array 1 to pin 5
int ledPin2 = 6; // led array 2 to pin 6



void setup() // run once, when the sketch starts
{

myservo.attach(9); //link servo 1 to pin 9
myservo1.attach(10); //link servo 2 to pin 10
pinMode(switchPin, INPUT); // button as input
pinMode(ledPin, OUTPUT);  // led as output
pinMode(ledPin2, OUTPUT);// led2 as output
buttonState = digitalRead(switchPin);
myservo.write(0); // Closes the faceplate if forgot open when turning the circuit off.
myservo1.write(170); //   ^

}

void loop() //main body:

{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); 
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) { //if leds off and faceplate open
servostatus = 1; // close the faceplate and turn leds on

myservo.write(0);
myservo1.write(170);
delay(1000);

//fade sequece
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);


//change the value for a faster or slower fade effect
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {

analogWrite(ledPin, fadeValue);
analogWrite(ledPin2, fadeValue);
delay(30);


}

} else {
servostatus = 0; 

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(15);
myservo.write(170);
myservo1.write(0);






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

I do not tested.

good luck!
 
Is there anyway you can give me this code but instead of using two servo's just one? I have a heck of a time trying to read and write this stuff as I am old and uneducated in this area.
 
smokethewax

I will not give you code ready to use in the way you wanna, but here it's the deal: you can try to make it work the way you wanna, and put it here, if its wrong i will point you in the right direction.
 
Last edited by a moderator:
@smokethewax

I will not give you code ready to use in the way you wanna, but here it's the deal: you can try to make it work the way you wanna, and put it here, if its wrong i will point you in the right direction.

Yeah if I could figure it out do you really think I would be asking someone half my age at minimum for help?

Trust me when I say I have tried several things. I just don't speak geek.
 
Last edited by a moderator:
Hi everyone!

7sinzz you really inspired me, thanks a lot!

After I saw this thread I bought on ebay an arduino starter kit (sainsmart R3) and I tryed to make something.

Heres the result:


I made a different code (for newbies like me) that makes the faceplate close if you keep pushing the buttom:

Code:
#include <Servo.h>

Servo myservo;
Servo myservo1;
int buttonState= HIGH;
int switchPin =2;
int ledPin = 5;
int val;

void setup()
{
myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
myservo.write(180);
myservo1.write(0);
delay(15);
digitalWrite(ledPin, HIGH);
}

void loop()
{
  
  val = digitalRead(switchPin);
  delay(15);

  if (val == buttonState) 
  {
    myservo.write(176);
    myservo1.write(4);
    delay(15);
    digitalWrite(ledPin, HIGH);
  } 
  
  else 
  {
    digitalWrite(ledPin, LOW);
    delay(15);
    myservo.write(90);
    myservo1.write(70);
  }
  
}


Thanks to all for the idea you share!
 
Last edited by a moderator:
Yeah if I could figure it out do you really think I would be asking someone half my age at minimum for help?

Trust me when I say I have tried several things. I just don't speak geek.

Well, it is never late too learn, I'm almost 30 years old, bro, I started to learn those stuff 2 years ago cause i was tired to pay for ppl to fix my electronic things.

If you read a lil bit you will understand the logic of the code.

anyways, here its the code the way you wanna:

-Servo on pin 9
-LEDs on pins 5 and 6
-Button on pin 2
Code:
#include <Servo.h>
Servo myservo; //servo1
int val; // variable for reading the pin status
int val2; // variable for to check consistency
int buttonState;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5; // led array 1 to pin 5
int ledPin2 = 6; // led array 2 to pin 6



void setup() // run once, when the sketch starts
{

myservo.attach(9); //link servo 1 to pin 9
pinMode(switchPin, INPUT); // button as input
pinMode(ledPin, OUTPUT);  // led as output
pinMode(ledPin2, OUTPUT);// led2 as output
buttonState = digitalRead(switchPin);
myservo.write(0); // Closes the faceplate if forgot open when turning the circuit off.

}

void loop() //main body:

{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); 
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) { //if leds off and faceplate open
servostatus = 1; // close the faceplate and turn leds on

myservo.write(0);

delay(1000);

//fade sequece
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);


//change the value for a faster or slower fade effect
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {

analogWrite(ledPin, fadeValue);
analogWrite(ledPin2, fadeValue);
delay(30);


}

} else {
servostatus = 0; 

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(15);
myservo.write(170);


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

*note for the others, this is the last time i change a piece of code in here that is not for my use.
 
Thanks for this I really do appreciate it. I am 50 years old and doing this for my Kid when I have the helmet Done I will post about it and actually send cred your way.
 
hi memebr,

thanks a lot for explanation. Already tested... and great...thanks again...
im starting to learn this.


If look closer on the code you will see that besides it was called as a variable and declared as a output, the ledPin2 is not in use on the main body of the code (void loop), same thing to pos and pos1

to make that other pin ledPin2 (in your case pin 6) to work like the ledPin(5) you will need to replicate the same things to both, you need to add the same fade sequence and the same turn off point...

here its the code with both pins as leds output (5 and 6) working in synchronization.

Pin 9 and 10 = servos
pin 5 and 6 = leds

Code:
#include <Servo.h>
Servo myservo; //servo1
Servo myservo1; //servo2
int val; // variable for reading the pin status
int val2; // variable for to check consistency
int buttonState;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5; // led array 1 to pin 5
int ledPin2 = 6; // led array 2 to pin 6



void setup() // run once, when the sketch starts
{

myservo.attach(9); //link servo 1 to pin 9
myservo1.attach(10); //link servo 2 to pin 10
pinMode(switchPin, INPUT); // button as input
pinMode(ledPin, OUTPUT);  // led as output
pinMode(ledPin2, OUTPUT);// led2 as output
buttonState = digitalRead(switchPin);
myservo.write(0); // Closes the faceplate if forgot open when turning the circuit off.
myservo1.write(170); //   ^

}

void loop() //main body:

{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); 
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) { //if leds off and faceplate open
servostatus = 1; // close the faceplate and turn leds on

myservo.write(0);
myservo1.write(170);
delay(1000);

//fade sequece
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(10);


//change the value for a faster or slower fade effect
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {

analogWrite(ledPin, fadeValue);
analogWrite(ledPin2, fadeValue);
delay(30);


}

} else {
servostatus = 0; 

digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
delay(15);
myservo.write(170);
myservo1.write(0);






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

I do not tested.

good luck!
 
Last edited:
I have really enjoyed reading this post. While most of the code is still way above me, I like the fact that you guys are so willing to help out. Makes me feel better knowing that I have somewhere to turn to for help when I make it to the electronic part of my builds. Awesome job guys. Please keep it up :D
 
Hey guys. I've been away for a fair few weeks busy on a commission project. Come back to find 10 extra pages of posts to go through. Absolutely fantastic progress. Within this thread is a literal gold mine of information and some mind blowing talents. I really need to sit down for a couple of hours and collaborate the joint knowledge over this thread and post everything in the first post. The task feel overwhelmingly daunting but will totally be worth it. Credit will be given to each individual for their input.

On another note it was fantastic to see the video a few posts above this one of a faceplate in action using information gathered from our collective information.
It's also great to see the poster (please excuse lack of name, I'm on tapatalk), using the same hook up I eventually intend to use, utilising the slits above the face plate. Maybe a closer look at your hook up would prove beneficial.

Fantastic work guys. You all deserve much more credit than me. I just got the ball rolling. This thread LITERALLY has everything you need to know, buried within its many pages.

For those of you that send me PMs, please excuse me for not replying individually. Your questions are much better suited in this thread where everyone can see the answers. Dont be scared, even if you ask a stupid question, you're only a screen name, banter is healthy, and certainly not personal. The majority of PMs I'm receiving are all asking similar questions, to which the answers are located here.

Also, a quick check and this thread has now had 51,300 views :) It appears to be one of the most popular currently active threads. Happy days.

The techniques can be used in a vast array of other applications too, with a little imagination. Any chance of a mod making it sticky? :)

Dani
 
Last edited:
Back
Top