Go Down

Topic: Activate Stepper Motor with PIR sensor (Read 1 time) previous topic - next topic

arsene2conde

Hello guys,

I am working on a project which will allow a user to open a fridge door using a voice-recognition module.
I am using different components to make this work; linear solenoid, stepper motor, PIR sensor, EasyVR Shield).

I have programmed most of it but I am now stock on something.

I am trying to activate the stepper motor 500 steps if no motion is detected...using a PIR sensor.

So my question is: what would the code look like to move my stepper motor 500 steps once no motion is detected?
If motion is detected, I want the stepper motor to hold its position.  I only want the stepper motor to move 500 steps only after no motion is detected.
I've been trying to use a while loop but can't seem to be working properly, what would be the best way to accomplish this?

Any help will be greatly appreciated!

Thanks

LarryD

The way you have it in your schematic isn't the same as how you have it wired up!

michinyon

Well,   you have some logical condition when motion is detected.

And when you stop detecting the motion,   you remember what time that is,  and you start counting the time.
And if you detect motion,  you go back to the logical condition when motion is detected.

And if 5 seconds go by,   and you still don't detect motion any more,    then you start driving your stepper motor.

So your system has four different states.

State 1:  currently detecting motion
State 2:  not detecting motion,  but had motion in the last 5 seconds
State 3:  running the stepper motor sequence
State 4:  finished running the stepper motor sequence.

And then you implement the logical steps which cause transitions between those 4 logical states.

arsene2conde

Hi,

Thanks for the feedback.
Here is the code I made so far.  Still having trouble...

Any comments?

Thanks

Code: [Select]
//PIR sensor with Stepper motor

#include <Stepper.h>

#define motorSteps 200     // change this depending on the number of steps
                           // per revolution of your motor
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
#define ledPin 13

//int solenoidPin = 9;
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;

// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

void setup() {
  myStepper.setSpeed(30);       // set the motor speed at 30 RPMS:
  pinMode(inputPin, INPUT);     // declare sensor as input
  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }     
} else {
    if (pirState == HIGH){
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
      myStepper.step(-500)
      }
  }

PaulS

Quote
Still having trouble...

Any comments?

Sure. I suggest you tell us what the trouble is.

Go Up