I am somewhat new to the Arduino, I have been using it for the past few weeks and now that I have a better idea of how it works I am looking to apply it to a project. I need to control a Servo as well as a DC motor to the same Arduino and control the timing of both. Meaning that I need to control when the DC motor comes on and how long it spins and also when the servo comes on and move it to 180 degrees and back. Any general ideas for setup of the circuit as well as the code? I have figured out how to do each easily on their own but I am just starting to experiment with how to control them at the same time.
Oh and I am hoping to wire up 3 simple buttons and 2 LEDs. 2 of the buttons will control how long the motor runs (one will make it run for 4 secs one will make it run for 6 secs). The other button will turn on the servo. The LEDs will just indicate which of the 2 DC buttons you pressed (4 secs or 6).
A servo only has three wires - power, ground, and control. Do NOT connect the power wire to the Arduino. Only connect the other two. Connect the power wire, and ground, to a real power supply.
as well as the code?
You've waved your arms uselessly. You have not written a proper specification document. Without decent requirements, and pin numbers, etc., you'd be wasting your time trying to write code.
The other button will turn on the servo.
No, it won't. The servo will be on all the time. The switch might tell the Arduino to make the servo move.
The LEDs will just indicate which of the 2 DC buttons you pressed (4 secs or 6).
Switches are NOT DC devices. Nor are they AC devices.
Thank you for the quick reply. I was simply just asking for recommendations from people who have used this combination of motors before and how to integrate buttons and LEDs. I understand that with the Arduino the servo is constantly running and that the Arduino never stops unless disconnected from power. I mentioned the buttons as DC buttons just to simply tell the reader that the buttons I am referring to are the ones controlling the DC motor.
As you can probably tell this is the first time I have posted here. What kinds of questions are you looking for that will help other people help me?
Have a look at the demo Several Things at a Time. It has much of what you need, a button, timing, a servo.
If you need your motor to go backwards as well as forwards you will need a h-bridge motor driver that can supply the current needed by the motor.
You may wish to consider using a continuous rotation servo in place of the DC motor as they are in a neat package that includes all the drive electronics and reduction gears. However as you have given no idea of the task the motor must perform or the loads and speeds involved it may or may not be suitable.
You need to keep the terms straight. A servo is not a stepper. Which are you using?
If the only control of the motor is that it runs for 4 seconds or runs for 6 seconds and you're not controlling the direction it turns then why do you think need an L298N?
Your specification so far is:
Switch Arduino on, it does nothing
Press Button1 the motor runs for 4 seconds
Press Button2 the motor runs for 6 seconds
Press Button3 the servo moves to 180 degrees and instantly back to 0.
I have a feeling there's more to it than that. E.g. am I allowed to press button3 while the motor is running? What happens if I press button2 then press buttton1 before the 6 seconds has elapsed and the motor has stopped?
If you have all the individual parts working then make an attempt to put them together. Post that and details of any problems you have.