1

I’m trying to write an arduino sketch that makes a dc motor turns one full rotation every 60s similar to a clock. The arduino will be connected to the gate of a typical mosfet and the dc motor will be connected to the drain of the mofset such that the arduino controls the speed of the motor. Any suggestions on how I go about this? I’m using an arduino mega 2560 in case that’s relevant.

  • 1
    What exactly do you have problems with? Timed things are mostly done via delay() or (better) via millis() (like in the BlinkWithoutDelay example). Have you tried these? – chrisl Oct 30 '20 at 21:54
  • 1
    I having trouble balancing the speed and delay of the motor so that it turns one full rotation every 60s. – John Oct 31 '20 at 1:07
  • 1
    You can't rotate a dc motor with just an arduino output, as you can't control the acceleration. You need a stepper motor to have a clean 360° rotation. Or an encoder or this sensor: AS5048A to detect the exact position of your motor. – Adriano Oct 31 '20 at 19:38
1

The best way would be to check the datasheet: https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf and set an interrupt on one of the timer.

Example code of this application can be found on this stack here : How to make 1 second delay more accurate?

Another way of doing it if you don't need to do anything between rotation would be to wait by just waiting using delay in a for loop. Be aware that this is less precise than interrupts driven wait. https://www.arduino.cc/reference/en/language/functions/time/delay/

edit : if you want to complete one full rotation every 60s

int i = 0;
while(1) {
  i++;
  delay(1000);
    if( i == 60){
    doFullRotation();
    i = 0;
    }
}
  • 1
    Sorry my bad, I was not clear in the question. I don’t want it to start turning every 60s, I want it to complete one full rotation every 60s. – John Oct 31 '20 at 1:10
  • oh wait, you mean you want it to rotate one turn over 60 sec? 1 turn per 60 sec? – Marianne Primeau Breton Oct 31 '20 at 2:23
  • 1
    In that case, you will have trouble with dc motor, since you can't precisely make them turn over a precise angle without feedback from an encoder. Id suggest getting something like a servo or a stepper motor depending on your needs – Marianne Primeau Breton Oct 31 '20 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.