Push buttons for motors and servos

Hey all,

Long time lurker, first time poster. I have learned so much with this forum and love the community, so keep up the good work. Just wanted to say that. Now for my issue. I have taken a lot programming courses and learned stuff from Java to C#, so when I finally had to build something physical and saw arduino, I figured this was right up my ally. So I bought an arduino r3, a motor shield r3, and wanted to dive right in.

While searching through the forums, I kept finding things things that were similar to what I needed, but you guys are overachievers, because it always seemed that your projects took steps way past the simple thing I was looking to accomplish.

For my project I have 1 servo and 1 motor, and 2 buttons. The plan is when button1 is pushed, Motor1 will turn CW for 2 seconds (or milliseconds, doesn't matter), and servo1 will turn CW for 3 seconds. Then when button2 is pressed, they will do the same thing, but CCW.

In my head this was simple, I am not using positioning of the servo or anything, and I got the physical parts hooked up to the breadboard, but when I was searching the forums it seemed that people were going above and beyond simple code (projects way cooler than mine). Am I overthinking this or have I underestimated the Arduino beast? :S If you have any questions, please let me know. Thank you.

V/R

theonegoku

P.S starting to wonder if the motor shield was even needed, its only one servo and one motor and each have their own external power supplies...

HI theo -

Go ahead and write your rookie sketch.
Then give it some thoughts based on the reference libray, to catch the most obvious problems.

Try spend a lot of time on your first project debugging and faultfinding, as you then experience a very steep learning curve.

Finally, we are lots of people onboard here, with a friendly approach to newcomers, despite the many experts with elaborated end theoretical approaches in their answers.

Happy coding and welcome :smiley:

Look for some of zoomkat's button-controlled servo examples.

AWOL:
Look for some of zoomkat's button-controlled servo examples.

Definitely love zoomkat. All of the threads I have been reading through seem like they are slowly progressing and then Zoom comes in and is like "oh yea, I got bored in the last 3 minutes and solved your whole problem, here u go" lol. But on a serious note. I have just been finding threads that are kind of like mine and then just picking the pieces that I need. For now its just trial and error.

My main problem is that since I'm used to object oriented programming, I just want to jump straight into IF/Then's but arduino is more friendly than having to map every occurrence, so for now I'm taking it slow and doing the proper method for a, presumably, simple task.

I think you're over-thinking the problem.
About the only issue I foresee is if you want to control the speed of the DC motor with PWM at the same time as using the Servo library, and you happen to choose pins 9 or 10 for your analogWrite.

AWOL:
I think you're over-thinking the problem.
About the only issue I foresee is if you want to control the speed of the DC motor with PWM at the same time as using the Servo library, and you happen to choose pins 9 or 10 for your analogWrite.

You would be correct in thinking that, luckily while messing with the physical set up, I was able to get intended result while having the motor and servo acting independently of each other. The only thing they have in common is that they are connected to the same button. I think it's just the wording of the program. I am currently at work, but when I get out I can post what I currently have, but looking through the libraries I can see the push button as a toggle and I have used center off switches with my motors in the past. Just having issues where the physical push button meets the digital program of "push connect the circuit...maintain the circuit for 2 seconds...disconnect the circuit".

Thing are a lot easier when you can visualize the logic, but all I can see is that the arduino connecting current to and away from the pin is whats making this possible, so now it's just wording it accordingly. :smiley:

Jump right in using the servo library and have a servo move while the button is pressed. Get that working a bask in your success. Then change the program to move the servo when the button becomes pressed. The StateChangeDetection example in the IDE will show you how.

With that under your belt add a second button and move the servo the other way when the second button becomes pressed.

What type of servo is it ? A real one or a bastardised, so called "continuous rotation servo" ? If it is a real servo how many degrees will it move in 3 seconds and how fast will it move ? Do you need to slow it down somehow ? Put that to the back of your mind and get something working, however simple, as long as it is a step along the way to your longer term goal.

UKHeliBob:
What type of servo is it ? A real one or a bastardised, so called "continuous rotation servo" ? If it is a real servo how many degrees will it move in 3 seconds and how fast will it move ? Do you need to slow it down somehow ? Put that to the back of your mind and get something working, however simple, as long as it is a step along the way to your longer term goal.

lol, no worries. I agree with the bastardized ones being what they are, I just got a real one that rotates about 252 degrees. And speed isn't an issue because I mounted it into a gear box. My servo is about torque, not so much speed, so it works out for me. I feel like since I have done what I have done up to this point, that ive gone backwards. Got it all set up, and NOW just working with the programming aspect, but as long as the job gets done, no complaints here :D. Thank again.