Arduino Code to make motor run at 1RPM

150 views
Skip to first unread message

kk

unread,
Nov 27, 2017, 8:14:12 AM11/27/17
to Bangalore Astronomical Society
Hi All,

I am trying to build a barn door tracker, need help in figuring the code to maket the motor run at 1RPM (The motor I have is Nema 17)

any help in this regard would be much appreciated.

Arun Venkataswamy

unread,
Nov 27, 2017, 8:43:25 AM11/27/17
to b-...@googlegroups.com
On Mon, Nov 27, 2017 at 6:44 PM, kk <keerthi...@gmail.com> wrote:
I am trying to build a barn door tracker, need help in figuring the code to maket the motor run at 1RPM (The motor I have is Nema 17)
any help in this regard would be much appreciated.

What stepper motor driver are you using?
Please provide details about the full power train. From the Arduino to the final gearing.


Regards,
Arun 

http://wondroussky.blogspot.in/ 

"கற்றது கைமண் அளவு, கல்லாதது உலகளவு" - ஔவையார்
Known is a drop, Unknown is an ocean


kk

unread,
Nov 28, 2017, 1:08:55 AM11/28/17
to Bangalore Astronomical Society

Arun Venkataswamy

unread,
Nov 28, 2017, 11:23:37 AM11/28/17
to b-...@googlegroups.com
The stepper motor you are using has a step angle of 1.8°
That means there are (360°/1.8°) 200 steps per revolution.

You need 1 RPM and this implies you require 200 steps to be done in 1 minute.
200 steps in 1 minute = 200 steps in 60 seconds = 200 steps in 60,000 milli seconds

Expressed in milliseconds, you need to make 1 step every (60,000/200) 300 milli seconds.  


Use the following code:
The code assumes that you have connected the Arduino pins 2,3,4,5 to the ULN2003 driver. Change them to your preferred pins if required.
 
#define A        2                     
#define A_bar    3 
#define B        4 
#define B_bar    5 

#define delayStep 300 

void setup() {

  pinMode(A, OUTPUT);
  pinMode(A_bar, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(B_bar, OUTPUT);

}

void loop() {  

    digitalWrite(A, HIGH);
    digitalWrite(A_bar, LOW);
    digitalWrite(B, HIGH);
    digitalWrite(B_bar, LOW);
    delay(delayStep);

    digitalWrite(A, LOW);
    digitalWrite(A_bar, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(B_bar, LOW);
    delay(delayStep);

    digitalWrite(A, LOW);
    digitalWrite(A_bar, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(B_bar, HIGH);
    delay(delayStep);

    digitalWrite(A, HIGH);
    digitalWrite(A_bar, LOW);
    digitalWrite(B, LOW);
    digitalWrite(B_bar, HIGH);
    delay(delayStep);

}

Let me know how it goes.
Do verify with a stop watch application wether you are actually getting 1 RPM.


Regards,

keerthi kiran

unread,
Nov 28, 2017, 1:17:03 PM11/28/17
to BAS
Can ULN2003 drive such a big motor? You may need a H-bridge instead. 

Thanks and Regards,
Keerthi

--
You received this message because you are subscribed to the Google Groups "Bangalore Astronomical Society" group.
To unsubscribe from this group and stop receiving emails from it, send an email to b-a-s+unsubscribe@googlegroups.com.
To post to this group, send email to b-...@googlegroups.com.

kk

unread,
Nov 29, 2017, 12:36:15 AM11/29/17
to Bangalore Astronomical Society
Keerthi,

I am really a non tech guy based on online videos and others have arrived at a decision I also have a (5V-Stepper-Motor-28BYJ-48)

@Arun: Please let me know does the code change if I use a Hbridge as suggested by Keerthi here?

To unsubscribe from this group and stop receiving emails from it, send an email to b-a-s+un...@googlegroups.com.

kk

unread,
Nov 29, 2017, 12:44:57 AM11/29/17
to Bangalore Astronomical Society
Also Keerthi does this Hbridge work? (
Click to view larger image and other views
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
  • L293d-Dual-Motor-Driver-H-BRIDGE-Module-Board-V-2-0-for-Arduino-Raspberry-Pi
Have one to sell? Sell it yourself

L293d Dual Motor Driver H-BRIDGE)

Karthik Subramanian

unread,
Nov 29, 2017, 2:49:05 AM11/29/17
to Bangalore Astronomical Society
On Tuesday, 28 November 2017 23:47:03 UTC+5:30, keerthi wrote:
Can ULN2003 drive such a big motor? You may need a H-bridge instead. 

Hi Keerthi,

From what I remember (and my memory is very rusty), most of these steppers
draw something like 350mA. I don't remember the current draw under stall conditions,
however. The ULN2003 can support 500mA.

So ... it might just work :)

That said, an H-Bridge is probably the right thing to do.

K.

Arun Venkataswamy

unread,
Nov 29, 2017, 3:09:32 AM11/29/17
to b-...@googlegroups.com

@Arun: Please let me know does the code change if I use a Hbridge as suggested by Keerthi here?


I have not used a H-bridge directly.  I don't know the firing pattern for the coils when connected to a H-bridge.

I had assumed that you want to only use the ULN driver.
The most practical way to drive a stepper motor is this:

I use it my barn door. It also allows up to 1/32 micro-stepping increasing the resolution of movement. At ~ ₹200 it is a no brainer for DIY projects involving bipolar stepper motors. You don't have to worry about firing patterns for each coil or anything. Just pulse one port pin and the stepper motor makes 1 step (or microstep)

The code will be different though.

Arun Venkataswamy

unread,
Nov 29, 2017, 3:40:51 AM11/29/17
to b-...@googlegroups.com
On Tue, Nov 28, 2017 at 11:46 PM, keerthi kiran <info...@gmail.com> wrote:
Can ULN2003 drive such a big motor? You may need a H-bridge instead. 


Keerthi you are right.
The motor mentioned seems to draw 0.6 Amps and that might be difficult for the ULN to drive.

Regards,
Aruns

kk

unread,
Nov 30, 2017, 12:16:57 AM11/30/17
to Bangalore Astronomical Society
Thanks Arun and Keerthi,

I just got this H bridge could you help me with the modified code for this?? sorry for the trouble.




New L293D motor shield, the input voltage DC4.5-25V,

*600mA OUTPUT CURRENT CAPABILITY PER CHANNEL

*1.2A PEAK OUTPUT CURRENT (non repetitive)PER CHANNEL

*ENABLE FACILITY

*OVERTEMPERATURE PROTECTION

*LOGICAL "0" INPUT VOLTAGE UP TO 1.5 V(HIGH NOISE IMMUNITY)

*INTERNAL CLAMP DIODES

Reply all
Reply to author
Forward
0 new messages