Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Is there a way to display to the tenth on the serial monitor? on: December 01, 2011, 07:13:04 pm
Is there a way to display to the tenth decimal on the serial monitor?
2  Using Arduino / Programming Questions / Re: How to make remote control button #1 as an on off switch? on: October 27, 2011, 05:15:42 pm
You'll need to get the button ids. These are unique codes generated my each remote. If you're using Ken Shirriffs library, I think its irrecvdump.pde that shows these.
Save them into your program as consts and compare them to what you receive via IR.


Yeah I was just trying to get a foundation for my code before I got any deeper and started getting the button codes and implementing them into my program. So of course once I figure out what button 1 is shooting out, I'll assign that to my if statement.
3  Using Arduino / Programming Questions / Re: How to make remote control button #1 as an on off switch? on: October 27, 2011, 05:02:08 pm
Quote
How do I make it so that pressing the #1 button will act as an on off switch?
Do you have the appropriate hardware? Something to read the signal generated by the remote control?

There is an IR library available.

Yes I am using the appropriate hardware and using the IR library.
4  Using Arduino / Programming Questions / How to make remote control button #1 as an on off switch? on: October 27, 2011, 04:46:02 pm
I want to make it so that when I press the #1 button on the Sony remote control to my IR receiver, it should start up the code, and when I press it again, it will turn off the code. Buttons 2, 3, 4 will make my servo motor move to 0, 90, and 180 degrees respectively. How do I make it so that pressing the #1 button will act as an on off switch?

Can I use an if statement within an if statement? ie. if 1 is pressed, then enter another if loop to turn the servo motor depending on what buttons are pressed on the remote. and if 1 is pressed again, exit out of the loop.
5  Using Arduino / Motors, Mechanics, and Power / What do the 6 wires of a stepper motor represent? on: October 20, 2011, 05:14:11 pm
I've been using a stepper motor that has 5 wires to it. Orange, black, red, yellow, and brown. Now I'm going to use another stepper motor but this one has 6 wires. Colors yellow, red, orange, black, green, and brown. What does the extra color green wire do?
6  Using Arduino / Programming Questions / Using 4 pushbuttons and stepper motor to simulate a 3 story elevator? on: October 13, 2011, 10:27:21 pm
Push button 1,2,3 correspond to their floors respectively. The fourth button will be an emergency stop button. My question is, how would I let it know what floor it's currently on and to adjust for the amount to spin the stepper motor so that it can arrive at the appropriate floor? Ex: if it's already on the 3rd floor, and now I want to go to the 2nd floor, how do I let it know that?
7  Using Arduino / Programming Questions / Re: How to make a for loop run only once then stop? on: October 13, 2011, 08:47:16 pm
Thanks got it.
8  Using Arduino / Programming Questions / How to make a for loop run only once then stop? on: October 13, 2011, 01:40:47 pm
I just want it to run once then stop and wait and see if I will push the push button again for it to run again.

Here's the part of code that I want to run only once. How would I do that?

Code:
  if (ButtonMode == 1) {                //

    for (int s = 0; s <= 20; s++){
      for (int i = 1; i <= 12; i++){
        digitalWrite(8, HIGH);
        digitalWrite(9, LOW);
        digitalWrite(10, HIGH);
        digitalWrite(11, LOW);
        delay(10);
        digitalWrite(8, HIGH);
        digitalWrite(9, LOW);
        digitalWrite(10, LOW);
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW);
        digitalWrite(9, HIGH);
        digitalWrite(10, LOW);
        digitalWrite(11, HIGH);
        delay(10);
        digitalWrite(8, LOW);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, LOW);
        delay(10);

      }
    }
      delay(2000);
      for (int r = 0; r <= 15; r++){
        for (int i = 1; i <= 12; i++){
          digitalWrite(8, LOW);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, LOW);
          delay(10);
          digitalWrite(8, LOW);
          digitalWrite(9, HIGH);
          digitalWrite(10, LOW);
          digitalWrite(11, HIGH);
          delay(10);
          digitalWrite(8, HIGH);
          digitalWrite(9, LOW);
          digitalWrite(10, LOW);
          digitalWrite(11, HIGH);
          delay(10);
          digitalWrite(8, HIGH);
          digitalWrite(9, LOW);
          digitalWrite(10, HIGH);
          digitalWrite(11, LOW);
          delay(10);
        }
      }
   
  }
9  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 12:46:28 pm
I asked you earlier to put each { on it's own line, and use the Tools + Auto Format tool. If you will do that, I think you will see what the problem is.

If not, create a function to rotate step the motor 4 times. That is what the 4 blocks of digitalWrite and delay statements are doing. Call that function in the inner for loop. That will shorten your code considerably, moving the { and } closer together, to make it easier for you to see the problem.

(Yes, I see it.)

I found out what was wrong. It was my for loops. Now it's working fine. My logic was wrong. I didn't know that it would multiply if I put another for loop inside another for loop.
10  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 11:49:22 am
Quote
I am doing a active-low button setup and I know that's working too cause when I press the button, the stepper motor starts moving.
I missed this earlier. The motor starts when you press the switch. It takes about 1/2 a second per revolution. The 20 revolutions will take about 10 seconds. Then, the motor should pause for 2 seconds, and rotate back 15 revolutions, taking another 7.5 seconds.

Does that agree with what you are seeing, or not?

No the stepper motor isn't doing that. Based on the most recent code I pasted above your post, It's doing 3-4 revolutions, stopping for 2 seconds, then doing about 64 revolutions in the opposite direction then it starts doing the whole cycle over again.
11  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 11:39:08 am
For a start, I suggest removing the lines:

  Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);

and
 
  stepper.setSpeed(120);

Either you're using the Stepper library to drive the motor, or your'e driving it yourself. Don't try to do both at once.

[EDIT: and have you actually waited for the 39 or so seconds it takes to go through the code you've written to do 20 revolutions?]

Alright, so I took out those guys and edited my if loops on the bottom of the code. It goes 3 revolutions forward, stops for 2 seconds, then goes backwards 64~ revolutions, stops then goes back to the 3 revolutions and so on.

12  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 11:30:04 am
Quote
I know my wiring of it is correct cause the stepper motor works
All that this means is that the wiring for the stepper motor is correct. It says nothing about the wiring for the switch.

How is the switch wired (2nd request)?

It is wired like this. All of this is in one row on my breadboard.

13  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 10:50:58 am
What order are the pins connected to the motor windings?  A+/A-/B+/B- ??

I have the RED wire from the stepper connected to my 9V power supply.

Yellow to pin 8.

Orange to pin 9.

Brown to pin 10.

Black to pin 11.

All of these wires are going through a TIP120 then into the Arduino.
14  Using Arduino / Programming Questions / Re: Stepper motor won't spin like I want it to on: October 13, 2011, 10:48:53 am
Nope. That code is WAY to hard to read. Put the { on a new line. Run Tools + Auto Format to properly indent the code. Delete extra blank lines.


You are not using the internal pullup resistor, so you must have an external pullup or pulldown resistor wires with the switch. You haven't told us how the switch is wired.

Code:
Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);
So, why aren't you using the stepper.step() method to make the motor move?

What kind/size is it? What motor shield are you using?

Sorry. I am very weak in programming thus I use a lot of spacing to make things understandable for me and also I use a lot of comments to let myself know what each line is doing.

I'm not using the stepper.step() cause it's just how the instructor wants us to do this assignment. He wants us to first use the digitalWrite() to control each of the four pins and see that it can work like that too before going on to using the stepper.step().

The stepper motor is a PM4222-09 7.5 degree 100 ohm. I know my wiring of it is correct cause the stepper motor works so I'm guessing it's my coding. I set up my circuit by following this: http://img.azega.com/wp-content/uploads/2009/04/Arduino_Stepper_bb.png

I am doing a active-low button setup and I know that's working too cause when I press the button, the stepper motor starts moving.
15  Using Arduino / Programming Questions / Stepper motor won't spin like I want it to on: October 12, 2011, 10:37:20 pm
the problem I'm having is that the stepper motor is just spinning in the forward Clockwise direction forever. What's wrong?

Here's my code:

Code:
#include <Stepper.h>                          

int buttonPin = 2;              // pushbutton switch is connected to pin 2
int ButtonMode = 0;
int pushbutton;                        // variable for reading the pin status
int doublecheck;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state; initial


const int stepsPerRevolution = 48;
Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);


void setup() {
  pinMode(buttonPin, INPUT);    // Declare pushbutton as input


pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
 
stepper.setSpeed(120);
  
  Serial.begin(9600);          
  buttonState = digitalRead(buttonPin);   // read the initial state
}

void loop(){
  
  pushbutton = digitalRead(buttonPin);      // read input value and store it in pushbutton
  delay(10);                                // 10 milliseconds
  doublecheck = digitalRead(buttonPin);     // read the input again to check for bounces
  if (pushbutton == doublecheck) {          // make sure we got 2 consistant readings
    if (pushbutton != buttonState) {        // the button state has changed
      if (pushbutton == LOW) {             // check if the button is pressed
        if (ButtonMode == 0) {               // if its off
          ButtonMode = 1;           // First time push
    } else {
          if (ButtonMode == 1) {             // After first push
            ButtonMode = 0; // Go back to intial button state
          
            
          }
        }
      }
    }
    buttonState = pushbutton;                 // save the new state in our variable
  }




  // Different motor modes for each push of the button
  if (ButtonMode == 0) {                // initial mode
  
  digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW);
  
  }





  if (ButtonMode == 1) {                //
  
 
for (int s = 0; s <= 20; s++){
  for (int i = 0; i <= 48; i++){
  digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW);
  delay(10);
  digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH);
  delay(10);
  digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, HIGH);
  delay(10);
  digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, HIGH); digitalWrite(11, LOW);
  delay(10);

}
}

delay(2000);
for (int r = 0; r <= 15; r++){
for (int i = 0; i <= 48; i++){
digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, HIGH); digitalWrite(11, LOW);
delay(10);
digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, HIGH);
delay(10);
digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH);
delay(10);
digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW);
delay(10);
  }
}
}
}
Pages: [1] 2 3