Using an H-Bridge (L293E or SN754410) + Arduino it is possible to control the direction of two DC motors. Using the Physical Computing tutorial (DC Motor Control), I've added an additional motor + delay function, which sets timed intervals for each direction. This allows the powered mirror mount to move up/down + side to side. By adjusting the delay intervals + order of code the motor begins to move in a complex way.
Here's is the modified Arduino code:
/* Controlling Two DC Motors Using H-Bridge
* ------------
*
* Uses an H-Bridge (L293E or SN754410) to control the direction of two DC motors.
* Delay functions have been added. Additional DC motor added.
* Modification to Physical Computing tutorial:
* http://itp.nyu.edu/physcomp/Labs/DCMotorControl
*
* Modified 21 February 2007
* By Kyle Janzen
* http://kylejanzen.blogspot.com/
*
* based on an original by Physical Computing @ ITP
*/
int motor1Pin = 3; // H-bridge leg 1
int motor2Pin = 4; // H-bridge leg 2
int motor3Pin = 5; // H-bridge leg 3
int motor4Pin = 6; // H-bridge leg 4
int speed1Pin = 9; // H-bridge enable pin 1-2
int speed2Pin = 10; // H-bridge enable pin 3-4
void setup() {
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(speed1Pin, OUTPUT);
pinMode(speed2Pin, OUTPUT);
// set speedPin high so that motor can turn on:
digitalWrite(speed1Pin, HIGH);
digitalWrite(speed2Pin, HIGH);
}
void loop() {
{
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
digitalWrite(motor3Pin, LOW); // set leg 2 of the H-bridge low
digitalWrite(motor4Pin, HIGH); // set leg 2 of the H-bridge high
delay(5000); // set time 'on'
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
digitalWrite(motor3Pin, HIGH); // set leg 3 of the H-bridge high
digitalWrite(motor4Pin, LOW); // set leg 4 of the H-bridge low
delay(5000); // set time 'on'
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge low
digitalWrite(motor3Pin, HIGH); // set leg 3 of the H-bridge high
digitalWrite(motor4Pin, LOW); // set leg 4 of the H-bridge low
delay(5000); // set time 'on'
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
digitalWrite(motor3Pin, LOW); // set leg 3 of the H-bridge high
digitalWrite(motor4Pin, HIGH); // set leg 4 of the H-bridge low
delay(5000); // set time 'on'
}
}
Video - the motion of the powered mirror mount.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment