「Arduino Mega 2560 LESSON:31 ULN2003 と ステッパーモーター」の版間の差分
編集の要約なし |
編集の要約なし |
||
| 78行目: | 78行目: | ||
[[|380px||none|PCB図]] | [[ファイル:Mega2560 L31 02 PCB図.png|380px||none|PCB図]] | ||
| 84行目: | 84行目: | ||
[[|380px||none|3Dプレビュー図]] | [[ファイル:Mega2560 L31 03 3DPreview図.png|380px||none|3Dプレビュー図]] | ||
2026年11月13日 (金) 16:13時点における最新版
概要
電源供給モジュールとステッピングモーターとULN2003を接続するレッスンです。
完成図は以下のとおりです。
PCB図は以下のようなものです。
3Dプレビュー図は以下のようなものです。
コードは以下のようなものです。
//www.elegoo.com
//2018.10.25
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
*/
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 15; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
myStepper.setSpeed(rolePerMinute);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}