Controlling two servos with one button

Hello People!

My desire is to heighten a thing up and then down.

The construction is composed of two continous 360 motors and one button.

What I'd love to happen is: I click the button once: The two servo motors rotate X ammount "upwards" and then when I press the button once more the two servo motors rotate X ammount "downwards"

It's really similar to this topic: One button/2 Servo control - Project Guidance - Arduino Forum
When i tried the first piece of code (by the topic creator), the engines simply whirred, as if they had some electrical issue. I have an external power source and have seen that the two engines work fine with other pieces of code. Then I tried the second code posted in that thread - the servos move a little bit on each button press, which is great, but it isn't the full package of what I want to happen (read above).

My wish is that someone would write the code that could make this work.
I know that it may not be the best way for me to learn to have someone simply write the code for me, but I've been fighting with getting this thing to work for 10 days and I feel like I've hit a wall more permanent than the previous ones... And we're having an exhibition next week, so I would really need to get it to work by then :')

Thank you in advance!,
Alexander

One difficulty I’ve found with ex-servos is that it is hard to get two to rotate at exactly the same speed. If you’re trying to raise or lower a single object, this can be … Awkward.

Is this the problem you are having?

Maybe if you posted your code and your observations of how the code behaves, someone could point you in the right direction.

Otherwise, you could ask a mod to move this topic to the gigs section, and offer an inducement to someone to do it for you.

Hi GrooveFlotilla! I noticed that problem in the beginning, but now that I’ve grounded the external powersource to the arduino board, it seems like it’s syncing well enough… But yes. If they mess up in the slightest, it’s going to mess things up :confused: So far, this is not my problem. Now my problem is to code the thing to make this happen:

Press button once: Both servos rotate “up/forward”
Press button again: Both servos rotate “down/back”

Ad nauseum, that is: Click the button again, and it rotates up/forward… again; down, again: up… =)

I’m unfortunately a complete beginner, so I’ve only been trying to take pieces of code and trying to make them work :G So i have no code that I’ve written myself - the closest I’ve come to functional code is the second replyer of the thread i linked to…

We’re doing a school project and we are presenting in a week (Shiiet!) so it would be so f-ing great to have it working #frustration xD.

I assume that inducement means financial compensation? :slight_smile:
10 bucks to whomever solves this for me! :smiley:

I’ll try to find a mod to help move this thread! :slight_smile:

I am curious about your spec.
Push the button and it goes up. Does it stop?
Push and it goes down. Does it stop?

Well, the code that worked the best was this one:

"
//zoomkat servo button toggle test 4-28-2012

#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;

void setup()
{
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(7); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
servo.write(160);
toggle = !toggle;
}
else
{
servo.write(20);
toggle = !toggle;
}
}
delay(500); //delay for debounce
}
"

When I clicked (I didn’t hold down) the button, the servos would turn for like 2 seconds and then stop… I probably should have said that, on my breadboard, i connected the “control wire” from the two servos and then made it so that it’s only one cable going into the arduino pin 9 (or perhaps it was 7…) - My point being, the code didn’t account for two servos, i kind of made my own little hijack of that to make it work for both of them (Although, it would mean that I would have to mount the one servo upside down to make them move as one)

I’m not sure if that answered your question - did it?

I wrote the admin and asked him to move this thread to the “Gigs” section.

What else is required of me for someone to be able to write code that will work for this thing? I imagine that whoever writes the code will choose which pins i should put stuff into, that’s obviously fine and pretty easy for me to match… But is there something I need to answer or someone else needs to tell me apart from the information I’ve already provided? :slight_smile:

Regards,
Alexander

Some help please! x'D

If this is an assignment, it's stupid. If it is your own project, it's... well... not very clever thought. Two continuous servos don't rotate exactly identically. And connecting one data pin to two servos is wrong. You could perhaps connect the two servo axes to force them to rotate exactly with the same rpm. But still it's a bad idea.
Why must they be two? Do they share the load somehow? Do they have different loads? The only way to make them have exactly the same rpm is probably a rotary encoder. Like those used in robot cars with DC motors. After all, a continuous servo is a DC motor. It just happens to have a built in speed and direction control.

Thanks for your feedback!

I haven't measured how much the thing they're meant to carry actually weighs, but it was kind of a "to be safe" kind of line of logic, and also because the thing it's seppoused to lift had to be lifted straight up and not risk being tipped over, but I think it might actually work with just one now (we got some structure to the thingy, so it's supported on the sides regardless)... Hmm..

I guess then this project is down to one continous servo going up on a press and then going down on a press..

I think where I'm having difficulty is understanding how first one button press activates one part of the code and then the other press activates another part of the code.. but then again, I'm a complete beginner in both arduino and coding.. It's probably just some If - then statements here and there :G

Can you recommend a link where that stuff is taught like I'm 6 years old? :')

Have you figured out everything on how the machine should behave? What happens whem the machine turns on? Nothing, right? Only after a button press, something happens. How far can the servo rotate? You never answered to post #4!

I'd write the code using while instead of if-then.

ah!

Press button once: Motor starts and rotates for 6 seconds at some speed and then stops
Press button twice: Motor starts and rotates opposite direction for 6 seconds at same speed and then stops

then when the button is pressed again (third time) it starts loop again from the top.

Does that answer the question?

Progress.
During the 6 second run, can it ignore user input?

Repeating the process say 30 times, do you have any way of controlling that the system will return exactly to the starting position? A continuous servo doesn't have to be very precise. If you have varying loads, you can't expect the system to move up and down precisely only based on perfect timing. You need feedback.