Author Options:

Running a single DC motor for a specific amount of time using Arduino Uno.? Answered

This will be my first experience with arduino or any  micro controller as well as my first dip into android app development.
I need to run a single bi-directional DC motor in one direction for a set amount of time, say 10 sec, and then later run it in the reverse direction for the same amount of time. The time between these operations will average a couple of hours. The command will be sent from an Android app via Bluetooth to the Uno. I don't need variable speeds, just the ability to set the run-time duration and direction. Also the run-time will be set once and stay the same, it does not vary.

I assume I can develop an app that sends some sort of command (C1) to the arduino and when the arduino receives C1 it can turn the motor on for a set amount of time in direction 1 then turn it off. Similarly when the app sends a new command, C2, the arduino then could run the motor in direction 2 for a set amount of time.
Is this assumption correct?
What sort of commands would the app have to send to make this happen?
Is there an easier way (run-time set in app not arduino code for example)?
I also assume I can use one of the simple motor control circuits here on instructables with this setup. Yes or no?

Sorry if these are incredibly simple questions and thanks for helping a Arduino virgin out.


I'm trying to set an amount of time for my robot to turn so that I can determine the severity of the turn, but I can't figure it out

hi. I connect sensor with dc motor. and I want timer on if the sensor detect an object. my problem is when I add the code of timer with code of motor the timer works as counter its count the motion of the motor? if you have any idea please help me?

hello I want an arduino code for my recent project which makes the motor work for 20 seconds at every 6 hr interval

How you do this will depend on a couple of things. First, does the Arduino need to do anything else at all or just wait and run the motor and then wait again? If it doesn't then simply setting up a massive delay and then looping your run command should be enough. You might need to use several smaller delyas as 6 hours in milliseconds might be too high for the Arduino to keep in its memory.

If you need it to check other sensors or do other things while it waits the you should be able to use a While...or Do While... loop. I belive Arduino has a built in timer function so you just reset it before entering the loop, loop through the stuff you need to do and then check the timer. The one problem with this is that it would almost never catch the timer right at 6 hours but would miss by a few milliseconds, depending on how big your loop was. Over time your that error would add up if you were trying to keep it in sync with a world clock.

Other options include internet enabling your Arduino so it can check a clock webpage to get the time or interfacing it with a separate digital timer.

Thank you very much bwrussell for your awesome idea but I am a begginer at arduino and only bought it yesterday so could you please guide me to write the arduino code for it . I have an arduino uno . please help me out !. By the way thanks again for your prompt response.

Sorry for the slow reply.

The best way to learn is to just start doing things. The best resource for learning specific code and syntax is the arduino website, www.arduino.cc

Try poking around with the built in example codes and stuff you find under the resource tab on the website. If you take a shot at the code and can't get it working feel free to PM me with it attached and i'll try to take a look at it or try to answer any specific questions you have.

thank you very much for your reply I am very pleased with your work all the best for the future . thanks once again


Hello, I am needing something really similar and can't find a solution to it. I would like to know how did you solve you'r problem. please contact me to silvestre.lottero@gmail.com

Here's the end result project that I was working on when I asked.Check out this awesome Instructable.


If that doesn't help feel free to ask some more specific questions.

The thing I'm trying to do a box that has a lock that is timed to open every 48 hours, what possible solution can you imagine for that? thank you very much for the help

You can buy electronic locks that an Arduino can interface with, either directly or through a relay or transistor. Simply have the Arduino trigger the lock every 48 hours (172800000 milliseconds). If that is all you need it to do there probably are simpler ways to do it with some sort of timing chip but they will be more complex to setup.

The locks are almost all either solenoid or electromagnet based so you could just buy a small solenoid (that is out while underpowered and retracts under load) and build a lock of your own design.

That is exactly what I want to do, but the thing is I bought the Arduino 2 days ago and do know anything about programing, how would you say is the best way to learn how to program something like this? thanks

I learned using the reference and learning sections of the Arduino website and by just looking at code from other projects that have sections that are similar to what I'm doing. The example sketches included in the software are also very helpful.

If you ever get stuck feel free to PM me and I can try to help with your code or circuit.


Best Answer 6 years ago

Understand that the motor will not be in the same exact position it started in when it goes through its cycle of forward then reverse.  You've described an 'open loop' system whose position errors will build up over time.  This of course could be acceptable depending on what you want to do or could be disasterous. 
If this was, say, opening a garage door, you would not want it time based but based upon the position of the door, which would use limit switches to sense its 'fully open' and 'fully closed' states.  If time based, after opening and closing a few times there could easily be a gap between the door and the floor when you said to close the door.

Best Wishes

That's an excellent point. It wouldn't be a disaster but i would have to adjust the timing or correct the position once it got to far off. A switch could be hard to integrate but maybe switching to stepper motors and counting steps would work. It wouldn't be smooth but I'll defiantly consider what you said.

Stepper motors have a lot of torque at low slow speed.
It would take forever to open if it did not accelerate on starting
and decelerate to a stop.
At higher speed the stepper motor can slip steps if the door
has a high friction spot ( loose place again )

Today all doors have two end of travel limit switches and one light beam
interrupt set about ten inches high to prevent car crunch.

It's not a garage door actually. It needs to roll and unroll a piece of fabric a couple of feet long. The drum diameter will be as large as the motor/stepper torque allows. Right now I'm thinking a small high torque gear box motor withtravel limit switches.


6 years ago

The timing is a single delay(10000) statement in milliseconds.
How much motor current ?
Do you want to do it with two relays or six transistors ?