|
Research & Learning Class pages
Shop Admin
ITP Help Pages |
DC 1 L 293 H BridgeInitial report by Carlyn?, 23, March, 2006 This report is designed to allow you to create a reusable module for Always-On DC motor applications based on a L293D H-Bridge. This report is draws heavily from Tom Igoe’s Intro to Physical Computing resources. Applications and BackgroundThe DC Motor are simple motors to conrol and generally used for speed and power. There are two terminals, and when you apply direct current to one terminal and ground the other, the motor spins in one direction. When you apply current to the other terminal and ground the first terminal, the motor spins in the opposite direction. By switching the polarity of the terminals, you reverse the direction of the motor.The L293D is a standard Quadruple Half-H Driver and it is used in the case of DC motor control to mediate switching directions. A simple transistor like the TIP120 can be used if no direction switching is required. The L293D can easily be replaced with the SN754410. More general disscussion of DC motorshttp://tigoe.net/pcomp/motors.shtml Datasheets for L293D and SN754410http://focus.ti.com/docs/prod/folders/print/l293d.html Circuit DiagramBreadboard Stylehttp://flickr.com/photos/pcomp/sets/72057594082854160/ Perfboard StylePrinted Board StyleCodePicBasic Pro code:' switch is on RC4: switchPin var portc.4 input switchPin ' H-bridge is on RC2 and RC3. Enable is on pin RC1 motor1Pin var portc.2 motor2pin var portc.3 speedPin var portc.1 output motor1Pin output motor2pin output speedPin ' start with speed on: high speedPin main: ' switch direction: if (switchPin = 1) then low motor1Pin high motor2Pin else low motor2Pin high motor1Pin endif ' blinking LED to tell that the program is still running: high portb.0 pause 50 low portb.0 pause 50 goto main Wiring Code (for Arduino board):/*
DC motor control
by Ryan Holsopple
modification of Tom Igoe's DC motor code
I added function to start motor turning in one direction
I raised the threshold for my pot to work
**r.holsopple
Created 8 Feb. 2006
*/
int sensorValue = 0; // the variable to hold the analog sensor value
int sensorPin = 0; // the analog pin with the sensor on it
int motorPin = 9; // the digital pin with the motor on it
int threshold = 300; // the theshold of the analog sensor below which the motor should turn on
int forwardPin = 7;
int backwardPin = 8;
// prototype of the function that changes the motor's speed:
void changeMotorSpeed();
//function to begin motor turning in one direction
void forwardDirection();
void setup() {
// declare the inputs and outputs:
pinMode(motorPin, OUTPUT);
pinMode(forwardPin, OUTPUT);
pinMode(backwardPin, OUTPUT);
pinMode(sensorPin, INPUT);
}
void loop() {
// read the analog sensor
sensorValue = analogRead(sensorPin);
// determine whether its above or below the threshold
if (sensorValue > threshold) { // it's above the threshold
// turn off the motor
digitalWrite(motorPin, LOW);
}
else {
//start motor turning forward
forwardDirection();
// change the speed of the motor based on the sensor value:
changeMotorSpeed();
}
}
////////////////////////////////////////
void forwardDirection(){
digitalWrite (forwardPin, HIGH);
digitalWrite (backwardPin, LOW);
}
void changeMotorSpeed() {
analogWrite(motorPin, sensorValue);
}
The simple version:
int motorPin = 9; // where the transistor's base is attached
int analogPin = 0; // Analog input number for the potentiometer
int analogValue = 0; // variable for the analog reading
void setup() {
pinMode(motorPin, OUTPUT);
}
void loop() {
analogValue = analogRead(analogPin);
if (analogValue > 512) {
// turn the motor on
digitalWrite(motorPin, HIGH);
} else {
// turn the motor off
digitalWrite(motorPin, LOW);
}
}
|