Arduino, L293D motor driver shield, 4wd and linear actuator

good day to all! i need help on how to properly code my project.

schematic diagram:

  • i just finished working on how to control the movement of my car using a mobile app from play store, and it works perfectly fine. i used two 3.7v li-ion battery via arduino jack(linear actuator not included yet), but it is kind of slow when it comes to a not flat terrain. so i decided to upgrade my power supply to 12 volts via L293D motor shield ext power (still actuator not included yet), as expected the speed improved but the bluetooth module(hc-05) automatically disconnects after 5 secs controlling the car. can anyone help me in fixing this?
  • i plan to connect a linear actuator (with a 12v power supply) if the above problem is fixed, the linear actuator alone functions really well with a 12v supply. i struggle on how to combine the code of the linear actuator along with the four TT motors. can you help me with this? i want my car to function as forward, reverse, left, and right. then when the car stop for 5 secs the actuator will extend for 10 secs and retract after 10 secs. as it retracts that iss the time i can control its movement again.

NOTE: the 2 items was tested separately

these are the code:
LINEAR ACTUATOR ONLY

#include <AFMotor.h>

// Define motor parameters
AF_DCMotor motor(4); // Motor connected to M1 on the L293D shield

void setup() {
  Serial.begin(9600);           // initialize serial communication at 9600 bits per second
  Serial.println("Linear Actuator Control");

  motor.setSpeed(255);  // Set the motor speed. You can adjust this value.
}

void loop() {
  // Extend the linear actuator
  Serial.println("Extending...");
  motor.setSpeed(255);
  motor.run(FORWARD);    // Set the motor to move in the FORWARD direction
  delay(5000);           // Wait for 5 seconds (adjust as needed)

  // Retract the linear actuator
  Serial.println("Retracting...");
  motor.run(BACKWARD);   // Set the motor to move in the BACKWARD direction
  delay(5000);           // Wait for 5 seconds (adjust as needed)

  // Stop the motor
  motor.run(RELEASE);    // Release the motor, stopping it
  delay(5000);           // Wait for 5 seconds (adjust as needed)
}

CODE for the car's movement:

#include <AFMotor.h>


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);

char command;

void setup()
{
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

void loop(){
  if(Serial.available() > 0){
    command = Serial.read();
    Stop(); //initialize with motors stoped
    //Change pin mode only if new command is different from previous.
    //Serial.println(command);
    switch(command){
    case 'F':
      forward();
      break;
    case 'B':
       back();
      break;
    case 'L':
      left();
      break;
    case 'R':
      right();
      break;
    }
  }
}

void forward()
{
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255);//Define maximum velocity
  motor3.run(FORWARD); //rotate the motor clockwise
}

void back()
{
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
}

void left()
{
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
}

void right()
{
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD); //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
}

void Stop()
{
  motor2.setSpeed(0); //Define minimum velocity
  motor2.run(RELEASE); //rotate the motor clockwise
  motor3.setSpeed(0); //Define minimum velocity
  motor3.run(RELEASE); //stop the motor when release the button
}

(BTW M1 on the motor shield is not functioning properly when i connect a motor)

THat's okay for powering the Arduino, but your motor driver will consume 4V so don't wonder if it won't work well. For a battery driven project better use a modern (MOSFET) motor driver.

I once had a robot kit that implemented a BT master, perhaps you can switch your car to master mode as well.

1 Like

Yeah but my problem is in the bluetooth module (hc05) disconnecting after controlling. When i connect 12v power supply

Show a circuit diagram.Did you forget a freewheel diode?

Your motor driver drops about 3V from the battery to the motor. That is by design which is using bipolar output transistors in a darlington configuration. I concur with DrDiettrich use a MOSFET driver.

Ill just replace my current motor driver to a MOSFET motor driver? Can i ask for a link of the mosfet driver?

Check Adafruit, they are one of many sources.

Thanks. The problem is dont know how to combine the linear actuator code in the car code with 12 v ppwer supply

One of DRV8833, TB6612FNG, and many many others.

For your solenoid you just need a MOSFET to switch it. Just about any logic level power MOSFET will do.

Thank you for your reply. Ill just connect it to the M4 channel of the L293D motor driver shield wherein my linear actuator is connected?

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