Help Arduino Uno Circuit/Code for Iron Man auto faceplate

Don't want to see this ad? Sign up for anRPF Premium Membershiptoday. Support the community. Stop the ads.


zombienoms

Active Member
Found a tutorial on here by 7sinzz for an automated iron man helmet faceplate as found here

http://www.therpf.com/f24/iron-man-motorised-faceplate-electronics-tutorial-170853/

I got the materials listed and the only thing that I've done differently is use a prewired LED instead of a separate resistor and LED, and instead of using a button switch I want to use a rocker switch. Other than that I followed the directions given by 7sinzz and input the following code in order to get the flicker fade on effect in the leds which is as follows


#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
{
//servo 1

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

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(0);
myservo1.write(180);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);


// 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(180);
myservo1.write(0);






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



So my issue is I plug things in upload the code but instead of working with the switch or not working at all the LED and the Servos just go on their own accord with no seeming pattern, rhyme, or reason.

I'm electronics illiterate and I'm simply following directions. What am I doing wrong and can someone please help!

My desired outcome is to have about 8-10 LEDs and the 2 servos set up so I flick the switch and the helmet shuts and does the flicker fade on, then flick the switch back and it opens lights shut off, as in the youtube video on the other thread.

Attached photos are of my set up for the board any further information needed just ask I'll provide photos or info to help this along
 

Don't want to see this ad? Sign up for anRPF Premium Membershiptoday. Support the community. Stop the ads.

7sinzz

Well-Known Member
Post this within the thread as well bro. The guys in there have mind lowing knowledge.

If you wish to use a rocker switch with my code. The action will be as follows.

Rock to on and the servos will move and the LEDs will light up as described.

To move the servos again you will need to rock to off then back on again.

I think a rocker switch isn't your best bet for the desired outcome.
 

zombienoms

Active Member
I just put it up there too I'm just gonna shotgun everywhere see what comes back! I appreciate you posting all your stuff in the first place I wouldn't even have the guts to try without your tutorial it was clear and clean so thank you. hopefully I figure out where I went wrong with enough heads put together

In regards to the rocker switch I used it because it was something I found in radioshack and I thought it would be chunky enough to mount and take some abuse.

Also the button switches that I found in there were too small for the bread board and couldnt make the listed connections. Can I solder extension wiring to the button switch and put those connections in the bread board so 1) they reach and 2) I can then mount the button somewhere else?
 

xl97

Master Member
1.) make sure you have all the correct switches/buttons on the correct pin that is used in the code.

2.) make sure everything is wired correctly as well...
I also wouldnt use those pre-wired leds...

if you need pre-wired.. get some more in tune with the battery pack you'll be using.. (ie: not a 9v)

3.) in the pic with the breadboard & wires.. what are you doign with the red wire in the lower right hand corner? seems to go form ++ rail to...??? (or the blue wire or the yellow one?)

4.) do you have pull-up resistor enabled in code? (maybe the button is floating?)
 
Last edited:

michaudtime

Active Member
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 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
{
//servo 1

myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(0);
myservo1.write(175);
pinMode(ledPin2, OUTPUT);

Serial.begin(9600);  // this will enable your arduino and computer to talk ******
}

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

// Check the status of your value variable
Serial.print("val = ");
Serial.print(val);
Serial.print("\n");  // code for the start of a new line

// Output should be something like this "Val = X"

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(0);
myservo1.write(180);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);


// 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(180);
myservo1.write(0);






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

Look at the code above, I added what you need to start the serial command as well as one implementation of how to view the value of one of your variables. go through your code and add more as you need, then when you upload your sketch on your arduino click the small magnifying glass on the Arduino IDE that is just under the close X in the top right. This is a very basic thing but it will help you out A LOT.
 

Don't want to see this ad? Sign up for anRPF Premium Membershiptoday. Support the community. Stop the ads.

zombienoms

Active Member
1.) make sure you have all the correct switches/buttons on the correct pin that is used in the code.

2.) make sure everything is wired correctly as well...
I also wouldnt use those pre-wired leds...

if you need pre-wired.. get some more in tune with the battery pack you'll be using.. (ie: not a 9v)

3.) in the pic with the breadboard & wires.. what are you doign with the red wire in the lower right hand corner? seems to go form ++ rail to...??? (or the blue wire or the yellow one?)

4.) do you have pull-up resistor enabled in code? (maybe the button is floating?)

in reply:
1) everything is set the same except for a lack of resistors being placed because I just plugged the prewired LED in the marked section for LED and left the resistor off the board, the switch has been an issue, I've the push button that I got didnt fit the breadboard and was too small even attempting to shape the legs to reach it was simply not enough, so I got the rocker switch which has 4 terminals. I recently also got a momentary push to come on switch with 2 terminals. I was hoping button swapping wasn't going to be a big issue but i guess it is

2) Frankly I've been going with the prewired LED because I figured it would avoid the hassle/showing my ignorance of dealing with resistors and calculation and be a quicker plug and play?

3) the wires seeming to go to no where are meant to be connecting the switch but since I don't know what to use in the picture its just removed but the tutorial I'm going from specifically says button switch using the ports 25g, 25i, 28g, and 28i

4) have no idea what that last part means

I'm really not good with this stuff and I have no idea what I'm doing like I said I saw the tutorial, looked easy and quick enough, obviously I've underestimated it
 

zombienoms

Active Member
Code:
}
Look at the code above, I added what you need to start the serial command as well as one implementation of how to view the value of one of your variables. go through your code and add more as you need, then when you upload your sketch on your arduino click the small magnifying glass on the Arduino IDE that is just under the close X in the top right. This is a very basic thing but it will help you out A LOT.


I uploaded the code and attempted to put in the switch in a few orientations but each time it just sort of spazzed out going on and off quick with no consistency overall or sometimes the servos would give a quick twitch with the light but not really move. I removed the switch and and noted the amount of time the servos came on and stayed on, and then the time they went off. This resulted in the following observation

ON: 30 seconds
off: 24 seconds
ON: 1:16 quiver off for a split second then stay on another 4:30 (minute:seconds)
off: 48 seconds
ON: 53 seconds
off: 1-2 seconds
ON: 1:07
off: 1-2 seconds
ON: 10 seconds quiver off for split second stay on

The times are approximations within a few seconds but paint a good picture of my conclusion that there's no seeming rhyme or reason in the pattern? I know that this is without a switch and running a code that is asking for one but shouldn't there be more consistency?

I also had the serial command open during all this, when the switch was on the board there was rapid switching between the 2 variables at random points going back so quick that no visible change in the servos or LED happened it was just the code that rapidly flicked. Then it would in times of rest continue with 1 or the other variable, and at times when it switched over it usually wasn't a single change but a quick series before it settled on a state.

These results are confusing since granted I know less than nothing but I figured things would either work or not work, instead they seem like they try but the information is constantly changing. Frustrating because I've plugged in the switch flicked it and things had a seemingly proper reaction but then it just continued to operate on it's own accord showing that it didn't really have control
 

xl97

Master Member
I would start VERY simple..

with JUST a simple button command/sketch/code.. to ensure you understand how the switch needs to be wired up..etc..

if you do NOT have a switch in place.. then the pn the switch is suposed to be hooked up is most likely 'floating'..

I dont know whos code your using..(doesnt look like mine) but check to ensure the pin is pulled-up (HIGH).. and that going to GND (LOW) when the button is pressed executes your servo/led code.
 

Fawbish

Sr Member
Possibly go even more simple than that. leave the code for 10 minutes, and wire up an LED straight from the arduinos 5v output. Look at the LED, look at the resistors. It CAN be an exact science but there is also room for loose interpretation.

A small resistor might not be big enough to limit the current (which is what it's purpose is, to limit the current to the LED so that it doesnt pop) - most LEDs are around 25mA. with a 5 volts supply, anything between 500~ ohms and higher will protect the LED, and the higher you go, the less bright it will be. Resistors are simple - they have 3 distinct colours on them. There are tons of charts out there that let you know which is which.

Get a very basic circuit done. Then add in a switch (still JUST a circuit). From that point, you can start to work with the code for JUST the LED. Then the LED and switch. etc. You have to get basic steps covered.

https://123d.circuits.io/lab < this is a great resource for building circuits and testing code before you even put wire to breadboard.
 

Don't want to see this ad? Sign up for anRPF Premium Membershiptoday. Support the community. Stop the ads.

Top