PIR SENSOR WITH ARDUINO ACTIVATE STEPPER MOTOR

22,558

52

12

Introduction: PIR SENSOR WITH ARDUINO ACTIVATE STEPPER MOTOR

ACTIVATE STEPPER MOTOR USING MOTION SENSOR

Step 1: PIR WITH ARDUINO ACTIVATED STEPPER MOTOR

Hi this instactable to rotate stepper motor foreword and backward when pir read some motion.

Step 2: PART REQUIRE

1-ARDUINO UNO

2-PIR(HUMAN MOTION SENSOR)

3-L293D (MOTOR DRIVER)

4-UNI-POLAR STEPPER MOTOR(28BYJ-46)

5-SOME WIRES

Step 3: STEPPER AND PIR

Step 4: CODE

/*

Arduino with PIR motion sensor

activate camera motor projects

Writes by Engineer Mohanad Hameed */

#include //include stepper library int led = 13; // the pin that the LED is attached to

int sensor = 2; // the pin that the sensor is attached to

int state = LOW; // by default, no motion detected

int val = 0; // variable to store the sensor status (value)

int in1Pin = 12; //the pin that the phase 1 is attached to

int in2Pin = 11; //the pin that the phase 2 is attached to

int in3Pin = 10; //the pin that the phase 3 is attached to

int in4Pin = 9; //the pin that the phase 4 is attached to

int step_num =700;

Stepper motor(64, in1Pin, in2Pin, in3Pin, in4Pin);

void setup() {

pinMode(led, OUTPUT); // initialize LED as an output

pinMode(sensor, INPUT); // initialize sensor as an input

pinMode(in1Pin, OUTPUT); // initialize in1pin as an output

pinMode(in2Pin, OUTPUT); // initialize in2pin as an output

pinMode(in3Pin, OUTPUT); // initialize in3pin as an output

pinMode(in4Pin, OUTPUT); // initialize in4pin as an output

motor.setSpeed(300); //speed of the motor }

void loop(){

val = digitalRead(sensor); // read sensor value

if (val == HIGH) { // check if the sensor is HIGH

digitalWrite(led, HIGH); // turn LED ON

motor.step(step_num); //rotate the motor foreword

delay(1000); // delay 300 milliseconds

motor.step(-step_num); //rotate the motor backward

delay(300);

if (state == LOW)

{ state = HIGH; // update variable state to HIGH

}

}

else {

digitalWrite(led, LOW); // turn LED OFF

motor.step(0);

if (state == HIGH) {

state = LOW; // update variable state to LOW

}

}

}

Step 5: CIRCUIT

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    12 Discussions

    0
    tomatoskins
    tomatoskins

    5 years ago on Introduction

    This is cool! Any plans as to what you are going to do with it?

    0
    mohannadh
    mohannadh

    Reply 5 years ago on Introduction

    OK.We can use it To control the camera So that the camera is moving toward the persons Or it can be used to open the door and so on .

    0
    nimranimo32
    nimranimo32

    Reply 2 years ago

    can you please help me

    0
    PsycheQ
    PsycheQ

    3 years ago

    CAN i get a right code?

    0
    dancopy
    dancopy

    4 years ago

    Hello Friend!
    The code line 4 must be some mistake because it is showing the following: #include expects "FILENAME" or <FILENAME>
    Any tips? Thank you

    0
    RameshB11
    RameshB11

    Reply 3 years ago

    Hi

    Please see this line

    motor.setSpeed(300); //speed of the motor }

    there is flower bracket is diseble so enable the flower bracket code is working fine.

    0
    AriffI1
    AriffI1

    Reply 3 years ago

    i can get the right code

    0
    MarcoO28
    MarcoO28

    Reply 4 years ago

    by chance you have the code well

    0
    AriffI1
    AriffI1

    3 years ago

    if only 5V can motor move?

    0
    MarcoO28
    MarcoO28

    4 years ago

    the code has some error, some solution

    0
    JamesW139
    JamesW139

    5 years ago

    error in code says that 'Stepper' does not name a type