Hi,
I've got an L293D, and I want to run 1 motor, the left one, in forward and reverse at a lower speed using PWM. I'm 100% sure I have got all the wires hooked up properly.
My setup is basically a 12v power supply between pin 8 of the chip to ground of the arduino. I have pin 2 and 7 (input) of the chip to pin 7 and 8 of the arduino. And the enable pin 1 of the chip to pin 9 (PWM) of the arduino. All 4 grounds of chip are grounded to arduino. Pin 16 (vss) is to 5v of arduino. And pin 3 and 6 (output) of chip connected to small dc motor.
I am using a basic code just to run the left motor by itself in forward and reverse which works perfect. I understand that its changing pin 7 and 8 on arduino from + to - and vise versa depending on which direction. Heres the code anyway:
const int Motor1Pin1 = 7;
const int Motor1Pin2 = 8;
void setup() {
pinMode(Motor1Pin1, OUTPUT);
pinMode(Motor1Pin2, OUTPUT);
}
void loop() {
GoForward();
delay(2000);
GoBackward();
delay(2000);
}
void GoForward(){
digitalWrite(Motor1Pin2, LOW);
digitalWrite(Motor1Pin1, HIGH);
}
void GoBackward(){
digitalWrite(Motor1Pin1, LOW);
digitalWrite(Motor1Pin2, HIGH);
}
So my question is, how do I use this enable pin 1 for PWM? What happens to pins (input from chip) 7 and 8 on arduino when I want to use PWM? I have the enable pin 1 to pin 9 on the arduino. Could someone please tell me what part of the code would need to be changed if I want to run the left motor forward and then backward at say 150. Similar to the sketch above but using PWM.
I have tried experimenting with making an 'int' of pwmpin, setting it to output, and using analogWrite(pwmpin, 150); while having digitalWrite(motor1pin1, LOW), changing it from low to high, and the motor1pin1 to pin2 but I'm quite new to programming so I don't really know the way to go about it.
Once I have a basic code, it will help me understand it better because I can see it in front of me and then I can then study the layout of the sketch and experiment with it.
I have searched these forums and google of what I am after but cant find anything that explains well enough what happens to the input pins (as in are they high or low) and enable pin and the code to go with it.
Sorry for the long post and hope someone can help, thanks in advance.
Cheers!