Go Down

Topic: timed motor running. PAID GIG!!! (Read 407 times) previous topic - next topic

Bullet_96

Hi guys. I am brand new to coding and arduino in general. I have been trying to learn this but it seems it is a but to advanced for me to understand at this point in time. A project of mine will need a dc motor to run for "x"amount of time that is set in code, then shut one motor off and run a second DC motor for a different "x" amount of time pre-set in code then reverting back to initial motor again.
I was thinking about using "millis()" to control this but just havent been able to succeed. I am willing to pay someone to write a code that would make me be able to achieve this or even supply me witha code that is easy to adapt.
components i currently have are Arduino uno, a sensor shield, 2 dc motors and 2 mosfet for the switching, i will be utilizing an external 12V power supple as well.
I would love to take time and learn all this but my deadline is unfortunaely quickly approaching.

any and all help would be much appreciated.

patduino

Hi Bullet,

How precisely do you need to control the motors?  Can you describe the setup a little better? 

Have you considered using limit switches instead of running them for "x" milliseconds?
There are 10 types of people in the world, those who understand binary, and those that don't.

Dmitron1036

#2
May 05, 2017, 10:55 am Last Edit: May 05, 2017, 11:02 am by Dmitron1036
Do you need to reverse you motors? If so, 2 mosfets is not enouth. Use bridge schematic (or 2 relays + mosfet).

As about code:
You may use delay or millis function

For example:
Code: [Select]

loop(){
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);

digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);

delay(1000);
}

or
Code: [Select]

loop(){
unsigned long int time; // time, ms

time = 1000;

if (millis() >= time){
 digitalWrite(13, HIGH);

}

time = 2000;

if (millis() >= time){
 digitalWrite(13, LOW);

}

time = 3000;

if (millis() >= time){
 digitalWrite(12, HIGH);

}

time = 4000;

if (millis() >= time){
 digitalWrite(12, LOW);

}

}

PaulMurrayCbr

#3
May 08, 2017, 06:19 am Last Edit: May 08, 2017, 06:31 am by PaulMurrayCbr
Quote
A project of mine will need a dc motor to run for "x"amount of time that is set in code, then shut one motor off and run a second DC motor for a different "x" amount of time pre-set in code then reverting back to initial motor again.
No problem. This sketch runs motor a, then runs motor b, then "goes back to motor A". You can test this by putting a couple of LEDs on pins 4 and 5.

Code: [Select]

// motors are on pins 4 and 5

const byte motorA = 4;
const byte motorB = 5;

void setup() {
  pinMode(motorA, OUTPUT);
  pinMode(motorB, OUTPUT);
  digitalWrite(motorA, HIGH);
  delay(500); // half a second
  digitalWrite(motorA, LOW);

  digitalWrite(motorB, HIGH);
  delay(2000); // two seconds
  digitalWrite(motorB, LOW);
 
  // go back to motor A
  digitalWrite(motorA, HIGH);
}

void loop() {}


But maybe that's not what you want. Maybe what you want is for the sketch to continuously cycle between A and B.

Code: [Select]

// motors are on pins 4 and 5

const byte motorA = 4;
const byte motorB = 5;

void setup() {
  pinMode(motorA, OUTPUT);
  pinMode(motorB, OUTPUT);
}

loop() {
  digitalWrite(motorA, HIGH);
  delay(500); // half a second
  digitalWrite(motorA, LOW);

  digitalWrite(motorB, HIGH);
  delay(2000); // two seconds
  digitalWrite(motorB, LOW);
}


This will do also what you have asked. But I'm betting that there are requirements that you haven't mentioned.

Another way to do this, incidentally, would be to wire up a multivibrator with resistors and capacitors. A circuit like that would possibly be able to drive your motors directly.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Go Up