Hello I'm having problem of my project. Below is the explanation of my project:
When someone comes in front of the escalator the IR sensor detects motion and gets LOW. It sends signal to Arduino’s digital pin number 7 . Then the stepper motor starts rotating. We can increase the "step" in the code and the motor will run for more times. Then it stops. In the mean time while its running , if someone comes in front of the escalator , it will continue rotating. While no motion is detected , the escalator remain stationary and it does not run.
However, I'm not able to make it continue rotating in the mean time the IR sensor detects the any motion (while it's still rotating)
I'm using Arduino Uno,28BYJ-48 stepper motor(with driver board) and obstacle sensor.
This is my code :
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
int IR=7;
Stepper stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
float steps2take=STEPS_PER_MOTOR_REVOLUTION*32; //adjust to take how much it rotates
void setup() {
pinMode(IR,INPUT);
}
void loop()
{
int value=digitalRead(IR);
if(value==LOW)
{
stepper.setSpeed(500); //speed
stepper.step(steps2take);//steps to take
}
else
{
stepper.step(0); //steps to take
}
}
OR
Should I change to other motor? e.g DC motor. Please help
Uhmm that doesnt realy say anything i only see 2 lines from the error.
i also see they did not put the stepMotor function on the list on this page Link
ahh i see know its a Private function.
the point is you need to create your own function.
stepper motors are realy easy to controll.
google and you will find allot about it.
you MUST! look at the blink without delay sketch to add a delay to the steps (Speed control).
and you must add this otherwise the arduino will switch the pins REALY! fast and the stepper can not handle this.
you can also look at accelstepper.
also "STEPS_PER_MOTOR_REVOLUTION 32" seems a bit low. never seen stepper with 32 steps per rev.
mostly they are 200 steps per/rev.
I already try accelstepper and it works! The library has class that contain non blocking code. However there is a problem. I want the stepper other sensor disable when the stepper motor is running. It means, when IRcw ( IR sensor for clockwise) get LOW, the stepper motor will running clockwise. While it is STILL running, the IRccw cannot give signal to arduino to make the stepper motor running anticlockwise. Is it possible?
Here is my code :
#include <AccelStepper.h>
#define HALFSTEP 8
int IRcw=8;
int IRccw=9;
// Motor pin definitions
#define motorPin1 2 // IN1 on the ULN2003 driver 1
#define motorPin2 3 // IN2 on the ULN2003 driver 1
#define motorPin3 4 // IN3 on the ULN2003 driver 1
#define motorPin4 5 // IN4 on the ULN2003 driver 1
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin2, motorPin3, motorPin4);
void setup() {
pinMode(IRcw,INPUT);
pinMode(IRccw,INPUT);
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(200.0);
stepper1.setSpeed(200);
}//--(end setup )---
void loop() {
int valueCW=digitalRead(IRcw);
int valueCCW=digitalRead(IRccw);
//Change direction when the stepper reaches the target position
if (valueCW==LOW &&valueCCW==HIGH ) {
stepper1.move(8000);
}
else if(valueCCW==LOW &&valueCW==HIGH){
stepper1.move(-8000);
}
stepper1.run();
}