Sunday, December 27, 2015

SN754410 H-Bridge Motor Controller

One of our upcoming projects is a wireless controller for model railroading. A tiny Arduino installed in the engine with a wireless receiver and a H Bridge motor controller chip will allow us to go forward, reverse, coast, brake, and have speed control. Today we are testing the H Bridge chip, a SN754410 from Sparkfun ($2.35).




No additional circuitry is needed, just the motor, the chip, and the Arduino. We are using Pulse Width Modulation on the Enable pin to control the speed, and sending a high or a low to the two motor direction pins to control direction.




// SN754410 connections 
// https://www.sparkfun.com/datasheets/IC/SN754410.pdf

// Motor 1
// connect 1A (pin 2) to Arduino 7
// connect 2A (pin 7) to Arduino 8
// connect 1,2EN (pin 1)  to Arduino 9 (PWM)
// connect 1Y (pin 3) and 2Y (pin 6) to Motor1

// Motor 2 (optional)
// connect 3A (pin 10) to Arduino 3
// connect 4A (pin 15) to Arduino 4
// connect 3,4EN (pin 9)  to Arduino 5 (PWM)
// connect 3Y (pin 11) and 4Y (pin 14) to Motor2


// connect VCC1 (pin 16) to Arduino 5v
// connect VCC2 (pin 8) to Motor Source +
// connect pins 4,5,12,13 to Arduino and Motor Source Gnd.

// Forward: EN=H. 1A=H, 2A=L
// Reverse: EN=H. 1A=L, 2A=H
// Brake: EN=H, 1A=H, 2A=H
// Coast: EN=L

void setup() {

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  
  digitalWrite(9, LOW);  

}

void loop() {


  //forward
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
//stop to full,back to stop
for (int i=0; i <= 255; i++){
analogWrite(9, i);  
delay(10);
}
for (int i=255; i >= 0; i--){
analogWrite(9, i);  
delay(10);
}
//stop
digitalWrite(9, LOW); 
delay(1000);

  //reverse
digitalWrite(7, LOW);
digitalWrite(8, HIGH);  
//stop to full,back to stop
for (int i=0; i <= 255; i++){
analogWrite(9, i);  
delay(10);
}
for (int i=255; i >= 0; i--){
analogWrite(9, i);  
delay(10);
}
//stop
digitalWrite(9, LOW); 
delay(1000);
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...