User Tools

Site Tools


tutorials:arduino:stepper_motor

This is an old revision of the document!


Stepper Motor

How to do this,please refer to light led and how to connect cubieboard and arduino

About this Article

Abstract

400 400

Schematics

400

Sorce Code

#include <Stepper.h>

// 这里设置步进电机旋转一圈是多少步
#define STEPS 100

// attached to设置步进电机的步数和引脚
Stepper stepper(STEPS, 8, 9, 10, 11);

// 定义变量用来存储历史读数
int previous = 0;

void setup()
{
  // 设置电机每分钟的转速为90步
  stepper.setSpeed(90);
}

void loop()
{
  // 获取传感器读数
  int val = analogRead(0);

  // 移动步数为当前读数减去历史读数
  stepper.step(val - previous);

  // 保存历史读数
  previous = val;
}
/*
 * 步进电机跟随电位器旋转
 * (或者其他传感器)使用0号模拟口输入
 * 使用arduino IDE自带的Stepper.h库文件
 */

#include <Stepper.h>

// 这里设置步进电机旋转一圈是多少步
#define STEPS 100

// attached to设置步进电机的步数和引脚
Stepper stepper(STEPS, 8, 9, 10, 11);

// 定义变量用来存储历史读数
int previous = 0;

void setup()
{
  // 设置电机每分钟的转速为90步
  stepper.setSpeed(90);
}

void loop()
{
  // 获取传感器读数
  int val = analogRead(0);

  // 移动步数为当前读数减去历史读数
  stepper.step(val - previous);

  // 保存历史读数
  previous = val;
}

Headline

See Also

tutorials/arduino/stepper_motor.1393553695.txt.gz · Last modified: 2014/02/28 10:14 by sam