L293D MOTOR CONTROLLER PROBLEMS

L293d motor controller problems. I am trying to build a circuit using the L293d h-bridge. I need bidirectional control of two small dc motors. I have tried circuit after circuit from the internet, and the best I have done is to get control in one direction only. Most of the circuit and programs I have tried had problems. My final goal is to use an arduino nano with my homebuilt L293 chip. I was originally trying to get it to work with a Uno, but for some reason the serial com port kept changing and dropping out, which is another matter. Right now Im trying to get it to work with a mega. But for some reason, any of the programs. The below code seems to only respond to: digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D high
I can't get the motors to reverse!
Does anyone have or know of a TESTED circuit diagram AND corresponding program that works, forward, and reverse.
I have spent many hours trying to get this to work. Please don't suggest a bought motor shield, as I am working with students, and each student needs to pay for parts, and we need to keep the cost as low as possible,
Thanks for ANY help!
one of the programs include:
void loop() {
// if the switch is high, motor will turn on one direction:
if (digitalRead(switchPin) == HIGH) {
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D high
}
// if the switch is low, motor will turn in the opposite direction:
else {
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
}
 
thanks in advance for any help
 
Are you actually getting the correct logic levels on pins 2 & 7 as you change the switch, and do you have the enable pin set high?
 
Maybe you got a bad chip or it's an insufficient power supply. I request you to test the L293D separately. Disconnect it from your circuit and test it with a DC power supply and multimeter. See if the L293D works according to its truth table.
 
if using a Laptop, your charger may interfere with USB serial port due to both power supplies having CM noise. Connect Laptop to PE gnd to reduce interference using short wire or 100 nF cap for AC gnd to shunt CM noise.

If it works in battery mode on Laptop, that confirms my suspicion. Some USB cables have large CM chokes.
 
GPT-4 result

To control a bidirectional motor using an Arduino Nano and an L293D motor driver, you will need to do the following:

1. Connect the L293D to the Arduino Nano.
2. Write the code to control the motor.

Here is a basic connection diagram and an example code to get you started:

Connection Diagram:
1. Connect the EN1 pin of L293D to a PWM-capable pin on the Arduino Nano for speed control (e.g., D9).
2. Connect Input 1 and Input 2 of L293D to two digital pins on the Arduino Nano for direction control (e.g., D2 and D3).
3. Connect the Motor to Output 1 and Output 2 of the L293D.
4. Connect the VSS of the L293D to the 5V pin on the Arduino Nano if you’re running a 5V motor (for logic supply).
5. Connect the VS of the L293D to an external power source suitable for your motor (for motor supply).
6. Don't forget to connect the grounds (GND) of the Arduino, L293D, and the external power source together.

Arduino Code:

// Define the motor control pins
const int motorPin1 = 2; // Input 1 of the L293D IC
const int motorPin2 = 3; // Input 2 of the L293D IC
const int enablePin = 9; // Enable pin of the L293D IC
void setup() {
// Set motor control pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);

// Start with the motor stopped
analogWrite(enablePin, 0);
}
void loop() {
// Spin motor in one direction
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin, 255); // Full speed
delay(2000); // Run for 2 seconds

// Stop the motor
analogWrite(enablePin, 0);
delay(1000); // Wait for 1 second

// Spin motor in the opposite direction
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
analogWrite(enablePin, 255); // Full speed
delay(2000); // Run for 2 seconds

// Stop the motor
analogWrite(enablePin, 0);
delay(1000); // Wait for 1 second
}

This code will run the motor in one direction at full speed for 2 seconds, stop for 1 second, and then run in the opposite direction at full speed for another 2 seconds. The cycle repeats indefinitely.

Make sure to adjust the pin numbers in the code based on how you connect your motor driver to the Arduino Nano.

Is there a specific part of the code or setup you need more clarification on or help with?

 
thank you so much for your suggestion
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…