Hi, I am trying to make a project where the aim is to move a stepper motor to a certain point when a PIR is activated. I am using a 28byj-48 stepper which seems to be a fairly standard cheap 5v motor used in varios arduino projects. The problem i am having seems to be with the sequencing of the motor. I have been playing around with somew of the example sketches and the motor just seems to vibrate and all four LEDS on the driver board light up. the sequencing im told to use is 1,3,2,4. i have tried changing the sequencing and have manged to get interaction with the motor but not the desired action.
Im thinking as this was such a cheap motor and driver package that it may be A faulty or B just not a particually decent motor.
Has anyone encountered similar problems with this motor? if so is there a better small project 5v stepper i could be using?
any suggestions would be very helpful
Thanks
Jim
You need to post a link to the datasheet for the driver you are using.
With those motors it is easier to use one of the stepper libraries as it figures out all the complex timing.
...R
Thanks for the reply, thankfully i found a link where someone else was having the same issue. For a unknown reason the sequencing is a differnt set up to the sequence on the data sheet
Hi, im looking for some advice
Im new to programming and i am having issues with my stepper motor project.
The project is to make a device that uses a 3 PIR sensors, a stepper motor and a 12v windscreen washer pump kit.. my idea is when a cat crosses the path of a one of the sensors, the stepper will move to the centre point of the activated pir and then activate the pump for 5-10 seconds, spraying water at the cat and preventing them from shitting in the garden.
Im starting with just 1 PIR and a stepper motor and trying to get some control. At the moment im getting the stepper to move 90 degrees when the PIR is high, i want it to move back to the starting point when the sensor is low but my code is saying move -90 whenever the sensor is low, meaning its just constantly in reverse when the sensor is low.
my design
#include <Stepper.h>
const int stepsPerRevolution = 2050;
//2050 = 360deg
//1025 = 180deg
//512.5 = 90deg
//5.6944 = 1deg
#define motor_Pin_1 8
#define motor_Pin_2 9
#define motor_Pin_3 10
#define motor_Pin_4 11
int previous = 0;
//*************************************************
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 10;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;
int pirPin = 12; //the digital pin connected to the PIR sensor's output
int ledPin = 13;
int pirstate = 0; // variable to store current pir state
int lastpirstate = 0; // variable to store last pir state
Stepper myStepper(stepsPerRevolution, 8,10,11,9);
//*******************************************************
//SETUP
void setup(){
myStepper.setSpeed(14); // sets speed of stepper RPM
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
//***************************************************************
//LOOP
void loop(){
int val = analogRead(0);
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
myStepper.step(512.5); //step 90 degrees
delay (1000); // wait
}
if(digitalRead(pirPin)==LOW){
digitalWrite(ledPin,LOW);
myStepper.step(-512.5); //when sensor goes low stepper moves counterclockwise 90 degrees
delay(50);
myStepper.step(0); // stepper stops
}
probably something really obvious that im not doing but cant seem to get my head round it.
any help or suggestion?
thanks
You need a variable to keep track of the state of the pin - PrevPirPinState perhaps. Change your if statements to only act when the state changes.
You note that when the pin is low, the stepper keeps rotating; looking at the code, I'd expect the same thing when it's high too albeit in the other direction.
You need to arrange your code so that when the PIR changes state it causes a single motor movement to happen. And you should probably put a reasonable wait period between one motor move and the next. Cats don't appear at millisecond intervals.
I'm not sure why there is a need for the motor to move away from the PIR when it is no longer activated. When you have the 3 PIRs the water jet should just point at the activated PIR. Coding for this would probably be easier. Rather than move the motor by X steps you should move it to a position. I know you can do that with the AccelStepper library, but I'm not sure if the Stepper library has that facility.
You will also need a limit switch so that the Arduino can initialize the position of the stepper motor.
This seems like a project that would be much easier to implement with a servo rather than a stepper. If the range of the nozzle is greater than 180deg you could use a sail-winch servo.
...R
thanks guys.. will have a re-think
Those little motors are a standard part for car air-conditioning systems, made by several manufacturers who will potentially have different wiring colour codes.
The best advice for a 5-wire unipolar motor like this (where the movement is tiny per
step) is try different permutations until you find one that works. Remember to power
down before changing the wiring (important for inductive loads like motors). One third
of the possible ways to connect the 4 winding wires will work, the rest won't.
With 4, 6 or 8-wire steppers you can figure out the winding connections with a multimeter,
but not for 5-wire unipolar.
StateChangeDetection in the section "02.Digital" of the examples is where to go for inspiration.
This seems to be the same question as in your other Thread. Why am I wasting my time dealing with the same question twice?
DON'T DOUBLE POST.
...R
Threads merged.
thanks Mark I will have a look at that. I know that i am missing a simple command, just wasnt sure what that command was
Robin2:
This seems to be the same question as in your other Thread. Why am I wasting my time dealing with the same question twice?DON'T DOUBLE POST.
...R
In fairness it was a completly differnent question, The original question was about the type of motor i was using and if anyone else had the same issue, it turned out that the sequencing that was on the data sheet was incorrect and other people have had the same issue with these motors.. so the motor does work just not the way the data sheet tells it to work.
My second post was just asking for some advice on the code on what the missing command should be to tell the motor to stop. Like i said i have no programming experience and i was probably something simple.
I do apprieciate the advice but i dont beleive i wasted your time answering the same question twice
JimFlounders:
In fairness it was a completly differnent question,
The background information is almost always very important as part of understanding a question and the sort of advice that will be useful. As far as I could see this was essentially different aspects of the same project and it is much easier to give useful advice when all of the background data is in the same Thread.
And when I am aware that there is another Thread I am always wondering is there data "over there" that I should have to help me with the problem "here" - at the very least it is a distraction for my few grey cells.
...R
cool, In future i will try and keep it all in one thread if possible.