using timer on DC motor ?

LINIX Brushless, VEXTA Brushless, RC Servo, DC Geared, Linear, Stepper, Tamiya.....

using timer on DC motor ?

Postby alung92 » Fri Sep 12, 2014 9:03 pm

i Using Cytron 2A Motor Driver Shield, i tend to stop the motor in certain time period, i using delay(); but not working. Any method make it work?

CODE: SELECT_ALL_CODE
int E1 = 5; 
int M1 = 4;
int E2 = 6;                     
int M2 = 7;                       
 
void setup()
{
    pinMode(M1, OUTPUT);   
    pinMode(M2, OUTPUT);
}
 
void loop()
{
 
    digitalWrite(M1,HIGH); 
    delay(1000*5); 
    digitalWrite(M2, LOW);
 
  analogWrite(E1, 255);   
 analogWrite(E2, 255);
 delay(1000*5);
 } 
alung92
Novice
 
Posts: 17
Joined: Thu Aug 21, 2014 12:57 pm

Re: using timer on DC motor ?

Postby ober » Sat Sep 13, 2014 7:55 am

I don see any code that stop the motor from moving even after the delay, and the loop is an infinite loop, it will keep repeating. So if the motor rotate at the beginning, it will still go back to rotates.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: using timer on DC motor ?

Postby alung92 » Sat Sep 13, 2014 10:37 am

Please guide me how to write the code to stop the motor with certain time period . I want stop the motor after 5 second, no repeating after 5 seconds.
alung92
Novice
 
Posts: 17
Joined: Thu Aug 21, 2014 12:57 pm

Re: using timer on DC motor ?

Postby ober » Sat Sep 13, 2014 10:14 pm

1st try to understand the operation of code, simply giving code will not help you because you will have the same problem.

Which of the code control the start and stop of motor?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: using timer on DC motor ?

Postby alung92 » Sat Sep 13, 2014 10:35 pm

High, low defined as the direction of motor.(0-255)represent the speed of motor.0 mean stop, 255 mean full speed of motor, but at the end i have no idea how stop the motor within the time setting. I want stop the motor in 5 seconds. If using for loop , it will still keep continue moviing after delay statement.
alung92
Novice
 
Posts: 17
Joined: Thu Aug 21, 2014 12:57 pm

Re: using timer on DC motor ?

Postby ober » Sun Sep 14, 2014 12:03 pm

Good! But in your code the E is always 255, even if you put a delay, the motor will still keep running.

In C there are ways to ask the program to pause for infinite time, which is infinite loop. Use while(1); at the end of the program.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to DC Motor

Who is online

Users browsing this forum: No registered users and 8 guests

cron