Iron man MKVII helmet w/ arduino nano help!

ShitBag

New Member
So recently I took it upon me to build MoeSizzllac's Iron man Mk VII helmet. I have the board loaded with his code, and the servos work with it.
The problem I am having is the board constantly tells the servo's to move back and forth for a few seconds, and then stops. I can make
out what the code means, but I honestly have no clue to what to change to get it to stop. Much appreciation to everyone and all! Here is the code he wrote for it. Dude is amazing for labeling his lines, that helps a bunch.



#include <Servo.h>

Servo myservo; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo

int inPin = 6; // the number of the input pin
int outPin =3; // the number of the output pin for the LEDS
int outPin2 =4; // the number of the output pin for the LEDS

int state; // the current state of the output pin
int reading; // the current reading from the input pin
int pos = 0; // variable to store the servo positions
int pos2 = 0; // variable to store the servo positions

// the follow variables are long's because the time, measured in miliseconds,will quickly become a bigger number than can be stored in an int.

long time = 0; // the last time the output pin was toggled
long debounce = 50; // the debounce time, increase if the output flickers
//the two lines above are not really used in my code anymore

void setup() {
pinMode(outPin, OUTPUT); // Make Pin 3 (D3) an Output
pinMode(outPin2, OUTPUT); // Make Pin 4 (D4) an Output
pinMode(inPin, INPUT); // Make Pin 6 (D6) an input

}


void openfaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob
for (pos = 170; pos >= 0; pos -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'

for(pos2 = 0; pos2 <= 170; pos2 += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos'


delay(350);
}

void closefaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob

for(pos = 0; pos <= 170; pos += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position 'pos'

for (pos2 = 170; pos2 >= 0; pos2 -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos


delay(350);
}

void lightson(){
digitalWrite(3, HIGH); // Set D3 High
digitalWrite(4, HIGH); // Set D4 High
}

void lightsoff(){
digitalWrite(3, LOW); // Set D3 Low
digitalWrite(4, LOW); // Set D4 Low
}

void loop ()
{
reading = digitalRead(inPin);
state = digitalRead(outPin);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && state == LOW) {
delay(15); // software debounce
if (reading == HIGH && state == LOW) {
closefaceplate();
delay(10);
lightson();
}

}

if (reading == HIGH && state == HIGH) {
delay(15); // software debounce
if (reading == HIGH && state == HIGH) {
lightsoff();
delay(10);
openfaceplate();
}
}

}
 
Do the servos twitch or complete the full movement repeatedly? Does it respond to the button or just run as soon as the arduino is programmed? Are you using the same servos as the original project?

My first thought is to check the wiring all corresponds to the definitions in the code.
 
Do the servos twitch or complete the full movement repeatedly? Does it respond to the button or just run as soon as the arduino is programmed? Are you using the same servos as the original project?

My first thought is to check the wiring all corresponds to the definitions in the code.

Twitchy servo's!I am using two sg90 servo's as the creator had, and It seems to be in the code the more I look into it. I did find out another issue was that the power to the servo's had to be on a switch, else the faceplate will fling up and down rapidly. Twas my uneducated understanding that he had programmed it to move one motion per button switch. I was dead wrong. Currently watching some video's as how to program these myself. He did add some resistors to the main negative terminal on the battery and led lights, though I disregarded the led lights and the resistor on ground. Are those quite important to using these boards?
 
The resistors are to limit the current draw. Without them there's a chance the arduino will burn out trying to power the LEDs. They can also be used to adjust the intensity without using code. Depending where they are they could also be pulling the line down to ensure the LEDs turn off promptly.

The code looks to see if the LEDs are on or not to determine what to do when the momentary button is pressed. If they're on it turns them off and opens, if off it closes and turns them on.

Without the resistors on the LEDs they may be pulling the output pins too high to count as off for this check.
 
Back
Top