␡
- Overview of the L293D Chip
- Example Circuit
- Programming Code for the Motor
- Summary
Like this article? We recommend
Programming Code for the Motor
Next, upload the following sketch to your Arduino. It’s pretty simple! The motor goes forward for two seconds and then backward for two seconds, looping forever. PWM sets the speed at 50.
//set the L293D’s three control pins to 9, 10, and 11 on the Arduino int enablePin = 11; int 1Pin = 10; int in2Pin = 9; void setup() { pinMode(enablePin, OUTPUT); pinMode(in1Pin, OUTPUT); pinMode(in2Pin, OUTPUT); } void loop() { analogWrite(enablePin, 50); // this sets the speed for the motor at 50 digitalWrite(in1Pin, HIGH); digitalWrite(in2Pin, LOW); delay(2000); // delays for 2 seconds analogWrite(enablePin, 50); digitalWrite(in1Pin, LOW); digitalWrite(in2Pin, HIGH); delay(2000); // delays for 2 seconds }