Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 22, 2013, 08:21:23 pm
Ok I have tried that sketch but I can't figure it out... I need help trying to figure out how to keep track of how many steps the stepper takes from when it is powered up and if I can get that then I should be able to get the rest... any ideas on how to do this? Here is my code....


Code:
#include <Stepper.h>

Stepper myStepper = Stepper(200,8,9,10,11);

int ledpin = 13;
int pirpin = 4;
int pirstate = 0; // variable to store current pir state
int lastpirstate = 0; // variable to store last pir state
int pirpin2 = 7;
int pirstate2 = 0;
int lastpirstate2 = 0;
int bothpirstate = 0;
int lastbothpirstate = 0;


void setup() {
 
  myStepper.setSpeed(60); // sets speed of stepper
 
  pinMode(ledpin, OUTPUT);
  pinMode(pirpin, INPUT);
  pinMode(pirpin2, INPUT);
}

void loop() {
 
  int pirpinstate = digitalRead(pirpin);
  int pirpin2state = digitalRead(pirpin2);
  const int pos1 = 50;
  const int pos2 = 100;
 
 
 pirstate = digitalRead(pirpin);
 
  if(pirstate != lastpirstate) {
    if(pirstate == HIGH) {
    digitalWrite(ledpin, HIGH);
    myStepper.step(pos1);
  } else {
    digitalWrite(ledpin, LOW);
    myStepper.step(-pos1);
  }
}
lastpirstate = pirstate;

  pirstate2 = digitalRead(pirpin2);
 
  if(pirstate2 != lastpirstate2) {
    if(pirstate2 == HIGH) {
      digitalWrite(ledpin, HIGH);
      myStepper.step(pos2);
    } else {
      digitalWrite(ledpin, LOW);
      myStepper.step(-pos2);
    }
  }
lastpirstate2 = pirstate2;
}


2  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 17, 2013, 05:02:43 pm
Thanks PaulS when PIR1 is HIGH and PIR2 is HIGH is when i get confused on my programming... I will try your sketch!! thanks!
3  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 17, 2013, 04:35:51 pm
Ok sorry for being unclear....

when pir1 senses motion i want stepper to step 50 steps counter clockwise
when pir1 is low(no motion) and pir2 senses motion i want stepper to step 100 steps counter clockwise
when pir1 is senses motion (already at the 50 step counter clockwise position) and then pir2 senses motion I want stepper to step 50 steps counter clockwise (to reach the position it supposed to be at when just pir2 senses motion.)

does that make more sense?

thanks
4  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 17, 2013, 04:17:19 pm
Ok thanks for your help and now that I have got that figured out I would like to add a few more pir sensors. Here is what I want to accomplish... When pir#1 goes high(senses motion) the stepper will turn to that direction and stop until it goes low then return to original position. Ok so far the sketch I have works perfectly for that. Now I add pir#2... when pir#1 is high and pir#2 goes high then it rotates to far. If pir#1 is low and pir#2 goes high then the stepper turn to the right position and works fine. Does this make sense?? Here is the code...

do I need to use interrupts to accomplish this?

thanks

Code:
#include <Stepper.h>

Stepper myStepper = Stepper(200,8,9,10,11);

int ledpin = 13;
int pirpin = 4;
int pirstate = 0; // variable to store current pir state
int lastpirstate = 0; // variable to store last pir state
int pirpin2 = 7;
int pirstate2 = 0;
int lastpirstate2 = 0;
int LED = 12;

void setup() {
 
  myStepper.setSpeed(60); // sets speed of stepper
 
  pinMode(ledpin, OUTPUT);
  pinMode(pirpin, INPUT);
  pinMode(pirpin2, INPUT);
  pinMode(LED, OUTPUT);
 
}

void loop() {
 
  pirstate = digitalRead(pirpin);
 
  if(pirstate != lastpirstate) {
    if(pirstate == HIGH) {
    digitalWrite(ledpin, HIGH);
    myStepper.step(50);
  } else {
    digitalWrite(ledpin, LOW);
    myStepper.step(-50);
  }
}
lastpirstate = pirstate;

  pirstate2 = digitalRead(pirpin2);
 
  if(pirstate2 != lastpirstate2) {
    if(pirstate2 == HIGH) {
      digitalWrite(ledpin, HIGH);
      myStepper.step(-100);
    } else {
      digitalWrite(ledpin, LOW);
      myStepper.step(100);
    }
  }
lastpirstate2 = pirstate2;

}
5  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 16, 2013, 01:32:07 pm
hey I got it!!! :-) thanks for ya'lls help!!! here is the code i came up with...

Code:
#include <Stepper.h>

Stepper myStepper = Stepper(200,8,9,10,11);

int ledpin = 13;
int pirpin = 4;
int pirstate = 0; // variable to store current pir state
int lastpirstate = 0; // variable to store last pir state
int pos = 50;
int pos2 = -50;

void setup() {
 
  myStepper.setSpeed(60); // sets speed of stepper
 
  pinMode(ledpin, OUTPUT);
  pinMode(pirpin, INPUT);
 
}

void loop() {
 
  pirstate = digitalRead(pirpin);
 
  if(pirstate != lastpirstate) {
    if(pirstate == HIGH) {
    digitalWrite(ledpin, HIGH);
    myStepper.step(pos);
  } else {
    digitalWrite(ledpin, LOW);
    myStepper.step(pos2);
  }
}
lastpirstate = pirstate;
}
6  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 16, 2013, 12:34:37 pm

here is my latest sketch.... i'm getting hung up on my delay function or do I need to use a variable to store the value of the "pirpin"?? I am fairly new to this :-) if you can't tell but am willing to learn

Code:
#include <Stepper.h>

Stepper myStepper = Stepper(200,8,9,10,11);

int ledpin = 13;
int pirpin = 4;

int pos = 50;
int pos2 = -50;

void setup() {
 
  myStepper.setSpeed(60); // sets speed of stepper
 
  pinMode(ledpin, OUTPUT);
  pinMode(pirpin, INPUT);
 
}

void loop() {
 
  if (digitalRead(pirpin) == HIGH) {
    digitalWrite(ledpin, HIGH);
    myStepper.step(pos);
  }
 
  if(digitalRead(pirpin) == LOW) {
    digitalWrite(ledpin, LOW);
    myStepper.step(pos2);
  }
}
7  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 16, 2013, 12:01:29 pm
Thanks for you help so far! :-) I have written a simple code to control the stepper and have it stop at 90, 180, 270, and 360 degrees then rotate back to the original starting position. It delays 1 second at each spot but I want it to stay there for as long as the pir stays high. If I take out the " delay(1000);" then it just keeps spinning until the pir goes low. Does this make sense? I will be glad to clarify more!

Here is the code...

Code:
#include <Stepper.h>

Stepper myStepper = Stepper(200,8,9,10,11);

int pos = 50;
int pos2 = 50;
int pos3 = 50;
int pos4 = 50;
int pos5 = -200;

void setup() {
 
  myStepper.setSpeed(60);
 
}

void loop() {
 
  myStepper.step(pos);
  delay(1000);
  myStepper.step(pos2);
  delay(1000);
  myStepper.step(pos3);
  delay(1000);
  myStepper.step(pos4);
  delay(1000);
  myStepper.step(pos5);
  delay(1000);
 
}
8  Using Arduino / Programming Questions / Re: Sketch for Stepper motor?? on: February 15, 2013, 08:10:01 pm
yes I have looked at those sketches but all they do is either go by one step at a time or keep rotating back and forth. And that is not what I want. I want to be able to tell the motor to turn to position x and stay there all day if need be...not keep moving.
9  Using Arduino / Programming Questions / Sketch for Stepper motor?? on: February 15, 2013, 07:18:58 pm
Ok I am working on a project and this is what I would like to do.

When pir sensor senses motion this stepper motor https://www.sparkfun.com/products/9238? with this motor driver https://www.sparkfun.com/products/10267? would turn 90 degrees and stay there until the sensor goes low(stops sensing motion).

My question is... how do I write a simple sketch to accomplish this?

Here is my sketch that I want to insert the new stepper sketch into...

Code:
#define DIR_PIN 2
#define STEP_PIN 3

const int sensorPin = 4;
const int ledPin = 13;

void setup() {
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop(){
 
  if(digitalRead(sensorPin) == HIGH) {
    digitalWrite(ledPin, HIGH);
  }

if(digitalRead(sensorPin) == LOW) {
  digitalWrite(ledPin, LOW);
}
}
10  Topics / Robotics / Re: Automated focus stacking controller on: February 09, 2013, 07:06:52 pm
Looks really nice!! How did you make your housing for it?
11  Using Arduino / Motors, Mechanics, and Power / Re: 360* Servo?? on: February 06, 2013, 05:05:38 pm
Thank ya'll for your help!! I wish I would have done more research on servo's before I bought one but oh well I'll find a use for it sometime. But yea I have decided to go with a stepper motor maybe one like this one https://www.sparkfun.com/products/10551 and use this motor driver https://www.sparkfun.com/products/10267 . Do you think this is a good choice or would you recommend something else?

Thanks again  smiley-mr-green
12  Using Arduino / Motors, Mechanics, and Power / 360* Servo?? on: February 04, 2013, 07:45:19 pm
I am working on a project and need a servo that rotates 360*. Here is what i would like to accoumplish. Have 4 pir sensors pointed in 4 different directions. When one of those senses movement my arduino uno will tell a servo to turn to that sensor. And i will have a camera mounted to it also to take a pic. So my question is.... does someone make a servo that would work for my project? Thanks for your help!
13  Using Arduino / Programming Questions / Re: how to control servo's stopping point? on: January 05, 2013, 06:45:42 pm
thanks PaulS
14  Using Arduino / Programming Questions / Re: how to control servo's stopping point? on: January 05, 2013, 06:37:18 pm
just in case you haven't figured it out by now I'm a beginner so any advice would be appreciated!!
15  Using Arduino / Programming Questions / Re: how to control servo's stopping point? on: January 05, 2013, 06:20:57 pm
the line i made runs perpendicular with the white plastic arm
Pages: [1] 2 3