Go Down

Topic: Eyeball Construction (Read 1 time) previous topic - next topic

Brainfart14

Hello! So I'm trying to create a prop for my Halloween costume this year. I want to make a "Magic Book" that's been made from dragon skin, and have one of the dragon's eyes looking around on the cover (example image provided). I've bought most of the materials I need; but now it's time to get down to business: creating the code! My goal is to have the eye- controlled by 2 servos- look up, down, left and right, while an eyelid, controlled by a 3rd servo, blink on occasion.
I'm still a relatively new hobbyist in the world of Arduino, so the sketch I've written up is not without its flaws. I'd love for someone to offer some advice/guidance on this project. I've provided the code I've put together so far. Please, feel free to make comments (constructive ones) and corrections! Any assistance is greatly appreciated!

Delta_G

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Brainfart14

Yes I rewrote the sketch to make it more like a basic sweep sketch but it's still not moving in the way that I'd hoped. Now just a clarification, this current sketch isn't the final one, I just wanted to see if I was on the right path. However, it would appear that I'm far from it. When I upload it to my arduino, I end up with a very dull left right, THEN up down eye. I don't want I generic, robotic side to side movements; I'm trying to get them to work in unison. I'm not worried about the blink right now. Another problem for another day. Right now I'm focused on getting more natural-looking movement from the eyeball.

Delta_G

OP's code:

Code: [Select]
#include <Servo.h>
Servo hor;  // horizontal servo
Servo vert; // vertical servo
Servo lid;  //eyelid servo

int hori = 0; //variable for horizontal servo pos
int verti = 0; //variable for vertical servo pos
int lidi = 0; //variable for eyelid servo pos

void setup() {
vert.attach(9); //attach to pin 9
hor.attach(10); //attach to pin 10
lid.attach(11); //attach to pin 11

}

void loop() {
  for(pos=0; pos<180; pos+=2)
  {hor.write(hori);
  vert.write(verti);
  delay(10);
  }
for(pos=0; pos<180; pos=+1)
 {lid.write(lidi);
 delay(15);
 }
 for(pos=180; pos>=1; pos-=2)
 {hor.write(hori);
 vert.write(verti);
 delay(19);
 }
}
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

You seem to have some sort of misunderstanding about for loops:

Code: [Select]
for(pos=0; pos<180; pos+=2)
  {hor.write(hori);
  vert.write(verti);
  delay(10);
  }


Here you are incrementing the pos variable, but not using it.  And you are writing the same unchanging value ( hori and verti) to the servo over and over.  So this isn't sweeping anything.  It's just writing the same values over and over.  If you want to make it sweep then you need the for loop to work on hori and verti instead of pos.

I'm not sure what you actually want that to do, but something like this:

Code: [Select]
for(hori = 0, verti=0; hori<180; hori+=2, verti+=2)
  {hor.write(hori);
  vert.write(verti);
  delay(10);
  }



The other two for loops are similar in that they don't use the value that they are incrementing and just write the same values to the servos over and over a bunch of times. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

Wait, actually that code doesn't compile.  pos not declared in this scope.

Please post actual code that actually causes the actual issue and talk to us about that.  Don't waste time posting stuff that you aren't actually using. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Brainfart14

Okay, so I just realized that that was a crap code that shouldn't have been posted. My bad. After going through my files, and doing some serious tweaking I found the correct code. This one is generally what I want to do, only I can't get it to work on my board. When I first upload the sketch to the board, the motors move- just barely- and then it's like they freeze, and I'm just looking at/listening to 3 softly buzzing servos. Am I drawing too much power?

Delta_G


You really must learn to do this yourself.  When people are on phones or mobile devices they can't download your code but they can see it this way. 


Code: [Select]
#include <Servo.h>
Servo hor;  // horizontal servo
Servo vert; // vertical servo
Servo lid;  //eyelid servo

int servoPos = 0; //variable for servo pos (PWM 9-10-11)


void setup() {
vert.attach(9); //attach to pin 9
hor.attach(10); //attach to pin 10
lid.attach(11); //attach to pin 11

}

void loop() {
  for(servoPos = 0; servoPos < 180; servoPos+20)  //horizontal looks from L to R
  {hor.write(servoPos);
  delay(10);
  }
 
for(servoPos = 0; servoPos <=180; servoPos=+150)        //lid covers eye
 {lid.write(servoPos);
 delay(100);
 }

 for(servoPos = 180; servoPos > 0; servoPos--)   //lid recedes
 {lid.write(servoPos);
delay(100);
  }
 
 for(servoPos = 180; servoPos > 0; servoPos-20)  //horizontal looks from R to L
 {hor.write(servoPos);
 delay(30);
 }
 
 for(servoPos = 0; servoPos < 180; servoPos+45)  //vertical looks U and D
 {vert.write(servoPos);
 delay(30);
 }

 for(servoPos = 180; servoPos > 0; servoPos--)   //vertical looks D and U
 vert.write(servoPos);
 delay(15);
}
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

#8
Sep 08, 2018, 07:23 am Last Edit: Sep 08, 2018, 07:24 am by Delta_G
Quote
Am I drawing too much power?
How would I be able to tell that from just the code?  Got a picture of this circuit?


Code: [Select]
for(servoPos = 180; servoPos > 0; servoPos--)   //lid recedes
 {lid.write(servoPos);
delay(100);
  }


18 seconds to open the eye?
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

#9
Sep 08, 2018, 07:26 am Last Edit: Sep 08, 2018, 07:26 am by Delta_G
Code: [Select]
for(servoPos = 0; servoPos < 180; servoPos+20)

So what does servoPos+20 do?  Calculate a value and throw it away?  Shouldn't there be an = in there somewhere?

Code: [Select]
for(servoPos = 0; servoPos < 180; servoPos+=20)

Similarly in almost all your loops.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

slipstick

I'm just looking at/listening to 3 softly buzzing servos. Am I drawing too much power?
Very likely. What type of servos are they and how are they powered? If the answer is "From the 5V pin" and/or "through a breadboard" then yes.

Steve

Brainfart14

Very likely. What type of servos are they and how are they powered? If the answer is "From the 5V pin" and/or "through a breadboard" then yes.
[/quot

That is how I have them set up. But also tried to add a battery into the mix. So, I guess I either need a bigger battery (I used a 9V), or I have to redo my setup to make sure that the battery was actually part of the equation and not just there 'looking pretty'.
The servos I'm using are Emakefun MG90S Mini Metal Geared Micro Servos. I saw them in a few video tutorials where they were praised, and the site I bought them from also had good reviews for them; so I assumed they'd be great.
*Quick note, I do have 2 older servos that I bought from RadioShack a few years ago that still work great. I tried my sketch with them too and got the same result. So I don't think it's the motors.

slipstick

If you power the servos with their own battery it is more likely to work. 4 x AA rechargeable NiMH would be ideal but 3 x 1.5V Alkaline AAs would also probably get you going. The breadboard may be o.k. but some of them can't handle the current that a servos need.

Steve

Brainfart14

The breadboard may be o.k. but some of them can't handle the current that a servos need.

Steve
Alright. Any suggestions for better breadboards or alternatives?

Brainfart14

So I tried the sketch again- this time powering the servos with their own battery. Confusedly, *nothing* happened this time. I'm worried that I overpowered my arduino board last night. I did add a battery last night too, but even then all I got was a soft buzzing from the motors. Really, really hoping that I didn't kill my board :smiley-confuse: and I'm just hoping that it's something else preventing my sketch from working. I've added a picture of my wiring for a second opinion/analysis. 


Go Up