01
Overview
モーター制御と応用
Arduinoとモーター
ステッピングモーターとモータードライバを使い、回転制御を行う。
使用機材
· ステッピングモーター
· モータードライバ
02
Output
おみくじルーレット
明るい状態から指でセンサーを覆い暗くすると回転開始。
指を離して明るくすると、徐々に減速して停止する仕組み。
Arduino — プログラム
const int cdsPin = A0;
const int stepPin = 9;
const int dirPin = 8;
const int threshold = 760;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int lightValue = analogRead(cdsPin);
if (lightValue < threshold) {
while (analogRead(cdsPin) < threshold) {
stepMotor(1000);
}
for (int speed = 1000; speed < 8000; speed += 10) {
stepMotor(speed);
}
}
delay(100);
}
void stepMotor(int delayTime) {
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepPin, LOW);
delayMicroseconds(delayTime);
}
03
Demo
使用動画
デモ動画
▶ 動画を見る →
04
Reflection
感想
コードも配線も難しかったが、前回の内容を応用して作品として完成させることができた。
05
Process
制作風景