DC Motor Control Using the 754410 H-Bridge
NYU Lab Asignment with Schematics and Photos
Buy them at Sparkfun
Sample code:
int PWM = 3; // use PWM to control the speed
int A = 4; // used for direction: A=HIGH & B=LOW
int B = 5; // will spin in 1 direction, A=LOW &
// B=HIGH will spin in the other,
// and A=LOW, B=LOW turns it off
void setup()
{
pinMode(PWM, OUTPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
}
void loop()
{
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
analogWrite(PWM, 255);
delay(5000);
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
analogWrite(PWM, 255);
delay(5000);
}
MOSFET Control
See page 34 of Programming Notebook excepts its nice to add a small .1uF capacitor between motor + and -. This filters out bad mojo. Remember: this only spins the motor 1 way.
Following is a simple program to scale a potentiometer value (or other analog sensor) to the speed of a motor hooked to a MOSFET:
int motorPin = 3;
int analogValue;
int analogPin = 0;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
analogValue = analogRead(analogPin);
analogValue /= 4;
analogWrite(motorPin, analogValue);
}
Comments (0)
You don't have permission to comment on this page.