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
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