코드
https://dronebotworkshop.com/stepper-motors-with-arduino/
/*
Stepper Motor Demonstration 2
Stepper-Demo2.ino
Demonstrates Two 28BYJ-48 Unipolar Steppers with ULN2003 Driver
Uses Accelstepper Library
DroneBot Workshop 2018
https://dronebotworkshop.com
*/
// Include the AccelStepper Library
#include <AccelStepper.h>
// Define Constants
// Define step constants
#define FULLSTEP 4
#define HALFSTEP 8
// Define Motor Pins (2 Motors used)
#define motorPin1 8 // Blue - 28BYJ48 pin 1
#define motorPin2 9 // Pink - 28BYJ48 pin 2
#define motorPin3 10 // Yellow - 28BYJ48 pin 3
#define motorPin4 11 // Orange - 28BYJ48 pin 4
#define motorPin5 4 // Blue - 28BYJ48 pin 1
#define motorPin6 5 // Pink - 28BYJ48 pin 2
#define motorPin7 6 // Yellow - 28BYJ48 pin 3
#define motorPin8 7 // Orange - 28BYJ48 pin 4
// Define two motor objects
// The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
void setup()
{
// 1 revolution Motor 1 CW
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(50.0);
stepper1.setSpeed(200);
stepper1.moveTo(2048);
// 1 revolution Motor 2 CCW
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(50.0);
stepper2.setSpeed(200);
stepper2.moveTo(-2048);
}
void loop()
{
//Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
stepper1.run();
stepper2.run();
}
https://dronebotworkshop.com/stepper-motors-with-arduino/
참고
https://www.youtube.com/watch?v=0qwrnUeSpYQ
반응형
'만들기 > 아두이노' 카테고리의 다른 글
1602A LCD 디스플레이 가변저항 표시하기 (0) | 2022.09.08 |
---|---|
DC - DC 컨버터 (0) | 2022.09.01 |
아두이노를 이용한 워터펌프 (pwm 신호 제어) (0) | 2022.08.27 |
온도조절 펌프 만들기 ( 아두이노, 펠티어, 열선) (0) | 2022.08.13 |
포텐셔미터(가변저항)으로 360도 서보모터 방향 속도 조절하기 (0) | 2022.07.14 |