3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Drive a Stepper Motor with an AVR Microprocessor

Step 4Taking the Motor for a Test Drive

Taking the Motor for a Test Drive
If you're not already tooled up for microprocessor programming, you could do worse than the Ghetto Development Kit or any of the various PIC programmers.

Hook up the wires directly up to your microproc and burn it up with the following code:


/* Playing with getting the small stepper motors driven. */

/* Include delay function */
#define F_CPU 1000000UL
#include 

/* Pin defs for ATTiny2313 */
/* Clockwise order */
#define BLUE     _BV(PB0)
#define BLACK    _BV(PB1)
#define RED      _BV(PB2)
#define YELLOW   _BV(PB3)

#define DELAY  200 /* milliseconds between steps */

int main(void){  
  DDRB = 0xff;    /* Enable output on all of the B pins */  
  PORTB = 0x00;            /* Set them all to 0v */  
  while(1){                     /* main loop here */    
    PORTB = BLUE;    
    _delay_ms(DELAY);    
    PORTB = BLACK;    
    _delay_ms(DELAY);    
    PORTB = RED;    
    _delay_ms(DELAY);    
    PORTB = YELLOW;    
   _delay_ms(DELAY);  
   }
}


How simple is that code? Really simple.

All it does is make some nice definitions so I could refer to the wires by color rather than their pin-names, and then it toggles them on in sequence with an adjustable delay in between. For starters, I selected a half-second delay between steps.

See the short video for the results. If you're really on your game, count the number of steps per cycle to figure out the motor's single-stepping angular resolution.

(Oh yeah. PS. Drives with no load at 3.6v easily. See battery in video.)
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
95
Followers
7
Author:The Real Elliot