Hello,
I must note that I am a complete beginner in the world of Arduino, thank you in advance for your patience.
For the project I am working on we require a stepper motor to lift an object up and down, easy!
So far I have got the motor (Nema 23) wired into a Adafruit Motor shield V2, the motor performs well moving the object up and down.
However I need to make the stepper motor locate its home position on start up.
To do this I hope to fit a limit switch at the top only, when the Arduino is powered the object will rise all the way to the top slowly, hit the limit switch and then lower to the lowest point, and cycle (looped) 100 up, 100 down for example.
The reason for this is if the project loses power, especially at the highest point in the cycle, the object will crush into the motor casing.
I have found forums with similar projects but are difficult to dissect for this project, with one stepper motor and one microswitch.
I also saw a resistor included with microswitch wiring, is this required?
Ideally require guidance with the following:
- Wiring diagram for microswitch / limit switch for motorshield v2.
- Code required for the startup sequence.
I am using the Motor Shield test sketch code:
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control
For use with the Adafruit Motor Shield v2
----> http://www.adafruit.com/products/1438
*/
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
ada
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor->setSpeed(15); // 10 rpm
}
void loop() {
Serial.println("Double coil steps");
myMotor->step(2000, BACKWARD, DOUBLE);
myMotor->step(2000, FORWARD, DOUBLE);
}
Project Specs:
Motor: SY57STH76-2004A Nema 23 Stepper motor
Board: Arduino/Genuino Uno & Ada Motorshield V2