(UPDATED POST) RC car bluetooth L293D motor driver

Can someone please help me. I cant properly control my rc car (im following a tutorial on YT). I did everything on the tutorial, i dont think im missing something but yeah i cant control it properly.
This is how i wire it and as you can see i didn't solder it yet because i want to make sure it works first.

The bluetooth rc contoller i used:

Schematic diagram:

is this connection possible?(i use the same l293d above)

The code:

#include <AFMotor.h>

AF_DCMotor motor1(1);  // Motor 1 connected to M1 port of L293D
AF_DCMotor motor2(2);  // Motor 2 connected to M2 port of L293D
AF_DCMotor motor3(3);  // Motor 3 connected to M3 port of L293D
AF_DCMotor motor4(4);  // Motor 4 connected to M4 port of L293D

int linearActuatorEnablePin = 11; // L298N Enable pin
int linearActuatorInput1 = 10;    // L298N Input 1
int linearActuatorInput2 = 9;     // L298N Input 2
int linearActuatorDelay = 3000;    // Delay before linear actuator movement (in milliseconds)
int linearActuatorMoveTime = 10000; // Time for linear actuator to extend and retract (in milliseconds)
unsigned long lastMoveTime = 0;

void setup() {
  Serial.begin(9600);  // Initialize serial communication
  motor1.setSpeed(255); // Set motor speed (0-255)
  motor2.setSpeed(255);
  motor3.setSpeed(255);
  motor4.setSpeed(255);
  pinMode(linearActuatorEnablePin, OUTPUT);
  pinMode(linearActuatorInput1, OUTPUT);
  pinMode(linearActuatorInput2, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    executeCommand(command);
  }

  // Check if the car is not moving for 3 seconds
  if ((millis() - lastMoveTime) > linearActuatorDelay) {
    // Extend and retract the linear actuator after 10 seconds
    if ((millis() - lastMoveTime) > (linearActuatorDelay + linearActuatorMoveTime)) {
      moveLinearActuator();
      lastMoveTime = millis();
    }
  }
}

void executeCommand(char command) {
  switch (command) {
    case 'F':
      moveForward();
      break;
    case 'B':
      moveBackward();
      break;
    case 'L':
      turnLeft();
      break;
    case 'R':
      turnRight();
      break;
    case 'S':
      stopMoving();
      break;
  }
}

void moveForward() {
  motor1.setSpeed(255);
  motor2.setSpeed(255);
  motor3.setSpeed(255);
  motor4.setSpeed(255);
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
  lastMoveTime = millis();
}

void moveBackward() {
  motor1.setSpeed(255);
  motor2.setSpeed(255);
  motor3.setSpeed(255);
  motor4.setSpeed(255);
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
  lastMoveTime = millis();
}

void turnLeft() {
  motor1.setSpeed(255);
  motor2.setSpeed(255);
  motor3.setSpeed(255);
  motor4.setSpeed(255);
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
  lastMoveTime = millis();
}

void turnRight() {
  motor1.setSpeed(255);
  motor2.setSpeed(255);
  motor3.setSpeed(255);
  motor4.setSpeed(255);
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
  lastMoveTime = millis();
}

void stopMoving() {
  motor1.setSpeed(0);
  motor2.setSpeed(0);
  motor3.setSpeed(0);
  motor4.setSpeed(0);
}

void moveLinearActuator() {
  digitalWrite(linearActuatorEnablePin, HIGH);
  digitalWrite(linearActuatorInput1, HIGH);
  digitalWrite(linearActuatorInput2, LOW);
  delay(linearActuatorMoveTime);
  digitalWrite(linearActuatorEnablePin, LOW);
}
1 Like

If battery life is important chose a H-bridge with MOSFET outputs. Your existing one loses 3V from the battery to the motor which is burnt up as heat.

1 Like

what about L298n?

The voltage drop is inherent in the design of the L293. It has bipolar output transistors in a darling ton configuration. One for the High side one for the Low side. Each will drop about 0.7V per transistor so in a darling ton that is 0.7 * 1 or 1.4V to keep math simple and pick up wiring losses I round it up to 1.5V. See page 8 of the data sheet: https://www.ti.com/lit/ds/symlink/l293.pdf?ts=1700100271447&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FL293 This voltage drop is in each output pin. So with a motor connected it is ~2.8V less to the motor then the supply. Assuming a 6V battery the loss is about 50% which is burnt as heat in the part. Hopefully that helps explain what is happening. Using a MOSFET output I would expect the voltage drop to be maybe 0.1V or less.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.