think the wiring is correct (see pic)
but got the following error message when verify the code for two motors
“motorPin3 was not declared in this scope” regarding this line of code
“pinMode(motorPin3, OUTPUT);”
not sure what to do, I just tried to look at the existing code and replicate to add two additional input/output pins to the L293 for operation of the second motor.
even with 2nd motor hooked up everything with first motor still works fine
Here is the code:
// Project 16 - Using an L293D Motor Driver IC
#define switchPin 2 // switch input
#define switchPin 7 // switch 2 input
#define motorPin1 3 // L293D Input 1
#define motorPin2 4 // L293D Input 2
#define MotorPin3 6 // L293 Input 3
#define MotorPin4 5 // L293 Input 4
#define speedPin 9 // L293D enable Pin 1
#define potPin 0 // Potentiometer on Analog Pin 0
#define potPin 1 // Potentiometer 2 on Analog Pin 1
int Mspeed = 0; // a variable to hold the current speed value
void setup() {
//set switch pin as INPUT
pinMode(switchPin, INPUT);
// set remaining pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(speedPin, OUTPUT);
}
void loop() {
Mspeed = analogRead(potPin)/4; // read the speed value from the potentiometer
analogWrite(speedPin, Mspeed); // write speed to Enable 1 pin
if (digitalRead(switchPin)) { // If the switch is HIGH, rotate motor clockwise
digitalWrite(motorPin1, LOW); // set Input 1 of the L293D low
digitalWrite(motorPin2, HIGH); // set Input 2 of the L293D high
}
else { // if the switch is LOW, rotate motor anti-clockwise
digitalWrite(motorPin1, HIGH); // set Input 1 of the L293D low
digitalWrite(motorPin2, LOW); // set Input 2 of the L293D high
}
void loop() {
Mspeed = analogRead(potPin)/4; // read the speed value from the potentiometer
analogWrite(speedPin, Mspeed); // write speed to Enable 1 pin
if (digitalRead(switchPin)) { // If the switch is HIGH, rotate motor clockwise
digitalWrite(motorPin3, LOW); // set Input 1 of the L293D low
digitalWrite(motorPin4, HIGH); // set Input 2 of the L293D high
}
else { // if the switch is LOW, rotate motor anti-clockwise
digitalWrite(motorPin3, HIGH); // set Input 1 of the L293D low
digitalWrite(motorPin4, LOW); // set Input 2 of the L293D high
}
}
here is video from project 16
No comments:
Post a Comment