For tech demo 3 I created a belt-driven fan. To make the system work, a stepper motor rotates a set of gears which drives a belt to rotate an axle that is attached to the fan blades.

My code is a minimalistic version of the ServorSweep demo we used in class.

#define DIR_PIN 2
#define STEP_PIN 3
#define ENABLE_PIN 4
void setup(void)
{
// Initialize the stepper driver control pins to output drive mode.
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);

// Drive the /ENABLE pin low to keep the motor always energized.
digitalWrite(ENABLE_PIN, LOW);

// Initialize the serial UART at 9600 bits per second.
Serial.begin(9600);
}

void rotate_stepper(int steps, float speed)
{
int dir = (steps > 0)? HIGH:LOW;
digitalWrite(DIR_PIN, dir);
int pulses = abs(steps);
unsigned long wait_time = 500000/speed;
unsigned int msec = wait_time / 1000;
unsigned int usec = wait_time - (1000*msec);
for(int i = 0; i < pulses; i++) { digitalWrite(STEP_PIN, HIGH); if (msec > 0) delay(msec);
if (usec > 0) delayMicroseconds(usec);

digitalWrite(STEP_PIN, LOW);
if (msec > 0) delay(msec);
if (usec > 0) delayMicroseconds(usec);
}
}

void loop(void)
{
rotate_stepper(-1000, 250.0);
}