PIR-controlled stepper motor project

Hello,

So, I'm sorry beforehand because I am really new to this.

I'm working on an art project in which a stepper motor is controlled by a PIR-sensor, so that when it senses motion, it turns. My coding skills are pretty much 0 though, so I'm trying to put some found code together. To say the least....it's not going anywhere, and I don't understand half of it.

Is there any chance anyone would be willing to help a girl out?

Here's what I've got:

////////////////////////////////////////////////
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 7;

//declare variables for the motor pins
int motorPin1 = 8; // Blue - 28BYJ48 pin 1
int motorPin2 = 9; // Pink - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200; //variable to set stepper speed
int count = 512; // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup()
{
pinMode(pirPin, INPUT);
Serial.begin(9600);

Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}

void loop()
{
long now = millis();
if (digitalRead(pirPin) == HIGH)
{
if (count < countsperrev )
clockwise();
else if (count == countsperrev * 2)
count = 0;

count++;

}
delay(50);

//declare the motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay "motorSpeed" between each pin setting (to determine speed)
void anticlockwise()
{
for(int i = 0; i < 8; i++)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void clockwise()
{
for(int i = 7; i >= 0; i--)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}

Thanks!

The code you posted (incorrectly) does something. You did not explain what.
You want the code to do something. You did not explain what.

Getting from what the code does now to what you want it to do is going to be a problem, with no defined way points.

The code I posted (incorrectly,for lack of forum experience) calibrates the sensor, so it's active and then nothing more.

What I want it to do, is then detect motion and when it does that, then move the motor however much I tell it to.

Maybe I should just start over.

The code I posted (incorrectly,for lack of forum experience) calibrates the sensor

That happens in setup().

so it's active and then nothing more.

Wrong. The state of the PIR is read in loop().

If nothing appears to happen after that, you have the PIR sensor wired incorrectly, you have the motor(s) wired incorrectly, or the code is hosed up. There is FAR too much code to determine where the problem is. Dump 90% of the code, there, and just turn on an LED when the PIR sensor reports HIGH, and off when it reports LOW.

I'm with Paul on that.... you're trying to do much at once. Sometimes that's difficult enough even with experience, but for a neophyte it's a recipe for frustration and stomping on your Arduino.

As a starting point, have a look at this tutorial at Adafruit. It might not be your exact PIR but should help.

The tutorial section Testing a PIR will help you understand what's going on with the PIR without even an Arduino. I did that exact experiment when I first used a PIR. Then the section Using a PIR will help you get it working on the Arduino. It switches the built-in LED on pin 13 on and off. TAKE YOUR TIME to unsderstand the concept of "state" in that tutorial, as embodied in the pirState variable and you'll save yourself a heap of trouble as you progress.

Only once you have this fully understood, should you think of driving a motor.

EDIT .... if you didn't already, you should work through some of the examples in the IDE (File > Examples) which are also available on this very website here

I suspect it will be easier if you use the AccelStepper library to control your stepper motor. Then you won't have to figure out the appropriate step sequences.

...R