Monday, April 28, 2014

Motor Shield test

Here is the motor shield in action. The H-Bridge allows the motor to switch directions without any sort of relay setup. Could be useful for controlling robot arms *cough* Dustin *cough* !
These shields can also control stepper motors via onboard buttons or through external means; however, I have not figured out how to set that up in the code yet.

EDIT: I found this awesome tutorial for controlling a motor with just the SN754410 IC found on these motor shields. We could buy a dozen or so and control up to 24 motors (two per IC). They are $1.50 - $3.50 a piece depending on where you buy them. DC Motor Control

Sketch for shield:
// Motor Shield test
// by NKC Electronics
// Test Motor B



int dirapin = 12; // Direction pin for motor A is Digital 12
int speedapin = 10; // Speed pin for motor A is Digital 10 (PWM)
int speed = 250;
int dir = 0;

void setup()
{
pinMode(dirapin, OUTPUT);
}

void loop()
{
digitalWrite(dirapin, dir); // set direction
analogWrite(speedapin, speed); // set speed (PWM)
dir = ((dir == 0) ? 1 : 0); // change direction
delay(5000); // 5 seconds
}

No comments: