Trying to make a dc motor stop

I'm trying to make a dc motor stop. This is my code, but it doesn't work.

int motor1Speed = 100;

int motorPin1 = 9;
long int stop1;

void setup() {
stop1=millis()+10; // 3 seconds

void loop() {
if (millis())

I don't see how that makes the motor go, let alone stop.

Your program does nothing.


How should I fix it then.
BTW I normally work in Python.

stop1=millis()+10; // 3 seconds
millis() + 10 is not 3 seconds

if (millis()) will return true after the sketch has run for 1 millisecond until 49 and a bit days has elaplsed

stop1 is a variable, not a function so what do you think this line of code does ?

For advice on using millis() see Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

How is the motor connected to the Arduino? Did you work it out yourself or are you following a tutorial or online project?

1 Like

The tutorial you linked looks plausible.

Have you tried to simply duplicate the project it details?

If so, with what results?

If not, why not? :wink:


I did didn't work

Which Arduino? Which motor? Which motor controller? How are you supplying motor power? Describe in detail what you are trying to do.

That's a bit vague; you could say more about what you did, what did or didn't work or make sense &c.

Please note any parts that you used that were not exactly what was specified in the tutorial.

Until you (with our help) can get something basic like that tutorial's code and circuitry to work, it makes no sense to start trying to stop a motor after ten seconds.

Who knows? Maybe the tutorial has errors you have uncovered in your experimenting. Again, we can help with that.

We might also benefit from knowing what your immediate and longer term goals are - do you have a larger idea in mind that will involve motors and microprocessors? It may be simpler to start with LEDs and switches and stuff like that - interfacing to motors can introduce new problems, it is best to get a grip on the basics.

Python isn't C/C++, but if your Python chops are anything to speak of you will find picking up basic programming in a new language very easy. What kind of work do you do with Python? We might be able to avoid treating you like you know nothing if we know where it is you are coming from.


This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.