Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Learning and need help trouble shooting
|
Learning and need help trouble shooting
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Datammwv
(1 post) Bio
|
| Date
| Sat 08 Feb 2014 10:38 PM (UTC) |
| Message
| I have this Arduino code to open and close some blinds using a stepper motor. I thought I solved it when I came upon you switch area. I put a resister in the pull up location as you suggested. I even tried one in the negative position and I still get "random switching of the blinds"
When connected everything works when I hit the button. (blinds turn) Hit button again blinds turn other way. I is just whenever they want they also turn.
This is my first ever project and I am not that knowledgeable in the electronics area.
/**
* This sketch waits for the button to be pressed. The motor starts in forward direction,
* then every time the button is pressed the motor moves in the other direction.
*/
#include <StepperMotor.h>
// 4 pins of the stepper motor board
#define _PIN1 11
#define _PIN2 10
#define _PIN3 9
#define _PIN4 8
// Intderruption on PIN2, push-button connected to pull-up
#define ITR_PIN 2
#define ITR_NB 0
volatile boolean forward = false;
volatile boolean start = false;
volatile boolean first = true;
StepperMotor stepper(_PIN1, _PIN2, _PIN3, _PIN4);
/**
* This method is called on the interruption raised on the falling front of the PIN2
* The start flag is used to avoid rebound front. Interruptions are disabled inside the
* interrupt vector method.
* start is reset once it has been processed in the main loop()
*/
void buttonPressed()
{
if (!first)
{
if (!start)
{
forward = !forward;
start = true;
}
}
else
{
first = false;
}
}
void setup()
{
cli();
stepper.setPeriod(5);
pinMode(ITR_PIN, INPUT_PULLUP);
attachInterrupt(0, buttonPressed, FALLING);
sei();
}
void loop()
{
if (start)
{
if (forward)
{
stepper.move(8192); //allines close
stepper.stop();
}
else
{
stepper.move(-8192); //Allines open
stepper.stop();
}
start = false;
}
}
Wiring is very simple Steper 28byj-28 connected to uln2003. The uln2003 is connected to arduino nano 3.0 positive & negative. The D2 on the Arduino is connected to the switch. The switch is a Remotec ZFM-80 | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sun 09 Feb 2014 12:16 AM (UTC) |
| Message
| |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Shaitan
(3 posts) Bio
|
| Date
| Reply #2 on Sun 09 Feb 2014 12:17 AM (UTC) |
| Message
| I don't have any advice on your particular programming problem, but I did want to give you a tip. When giving code snippets in a forum post I find it's helpful to post a link to a gist instead of pasting the code directly into a forum post because forum posts generally do a really bad job at formatting the code.
https://gist.github.com/ | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Sun 09 Feb 2014 03:41 AM (UTC) |
| Message
| That's because he didn't use code tags.
 |
To make your code more readable please use [code] tags as described here.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Sun 09 Feb 2014 03:42 AM (UTC) |
| Message
| |
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
21,365 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top