Servo Motor on L293D Motor Board

Hi there,
I'm a new Arduino user and I started to learn from the board after working with other boards such as the GENIE 18 Board for other school projects. For my final state exam before university (Irish Leaving Certificate) project, I decided to use an Arduino since I really want to try new paths and I came up with this. I've learned the code and basics on Arduino's Software Editor and I made a script that can automatically determine the distance and rotating the project I made to suit the brief.

However the theme is disability, and I decided to go a step further adding a platform that allows wheelchair users to get into the vehicle and allow some form of accessibility.

Here are some screenshots based on my project from SolidWorks (All self made with only the board, motors and sensors that are from GrabCad) and the code is attached in this post also.

I'm really confused on one thing which is programming the platform. For my project I plan to turn on the SPST Switch and then the platform goes down and waits for 10 seconds before going back up again. But I'm really concerned if one bit of code can interfere with the main code which I'm using right now

For my project I'm using the L293D 4-Channel Motor Board and an Arduino Uno R3 with a battery (6x AAA) so I'm concerned if there would be a lot of load on the batteries since I'm using 2 Servo's (1 is the Sensor, 1 is the Platform, 4 Gearbox Motors to control the vehicle and 4 LEDs that are connected to the same terminal block with the gearbox motors)

Drive Link: Technology Leaving Certificate Project 2022 - Google Drive


(Platform Down - Allows people to get in with limited ability)

Here is the Code:

//Arduino Uno R3 Vehicle Test Code//

//AFMotor Library https://learn.adafruit.com/adafruit-motor-shield/library-install //
//NewPing Library https://github.com/livetronic/Arduino-NewPing// 
//Servo Library https://github.com/arduino-libraries/Servo.git //
// To Install the libraries go to sketch >> Include Library >> Add .ZIP File >> Select the Downloaded ZIP files From the Above links //


#include <AFMotor.h>  
#include <NewPing.h>
#include <Servo.h> 

#define TRIG_PIN A0 
#define ECHO_PIN A1 
#define MAX_DISTANCE 200 
#define MAX_SPEED 190 // sets speed of DC  motors
#define MAX_SPEED_OFFSET 20

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); 

AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
Servo myservo;   

boolean goesForward=false;
int distance = 100;
int speedSet = 0;

void setup() {

  myservo.attach(10);  
  myservo.write(115); 
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop() {
 int distanceR = 0;
 int distanceL =  0;
 delay(40);
 
 if(distance<=15)
 {
  moveStop();
  delay(100);
  moveBackward();
  delay(300);
  moveStop();
  delay(200);
  distanceR = lookRight();
  delay(200);
  distanceL = lookLeft();
  delay(200);

  if(distanceR>=distanceL)
  {
    turnRight();
    moveStop();
  }else
  {
    turnLeft();
    moveStop();
  }
 }else
 {
  moveForward();
 }
 distance = readPing();
}

int lookRight()
{
    myservo.write(50); 
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(115); 
    return distance;
}

int lookLeft()
{
    myservo.write(170); 
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(115); 
    return distance;
    delay(100);
}

int readPing() { 
  delay(70);
  int cm = sonar.ping_cm();
  if(cm==0)
  {
    cm = 250;
  }
  return cm;
}

void moveStop() {
  motor1.run(RELEASE); 
  motor2.run(RELEASE);
  motor3.run(RELEASE);
  motor4.run(RELEASE);
  } 
  
void moveForward() {

 if(!goesForward)
  {
    goesForward=true;
    motor1.run(FORWARD);      
    motor2.run(FORWARD);
    motor3.run(FORWARD); 
    motor4.run(FORWARD);     
   for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
   {
    motor1.setSpeed(speedSet);
    motor2.setSpeed(speedSet);
    motor3.setSpeed(speedSet);
    motor4.setSpeed(speedSet);
    delay(5);
   }
  }
}

void moveBackward() {
    goesForward=false;
    motor1.run(BACKWARD);      
    motor2.run(BACKWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);  
  for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
  {
    motor1.setSpeed(speedSet);
    motor2.setSpeed(speedSet);
    motor3.setSpeed(speedSet);
    motor4.setSpeed(speedSet);
    delay(5);
  }
}  

void turnRight() {
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);     
  delay(500);
  motor1.run(FORWARD);      
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);      
} 
 
void turnLeft() {
  motor1.run(BACKWARD);     
  motor2.run(BACKWARD);  
  motor3.run(FORWARD);
  motor4.run(FORWARD);   
  delay(500);
  motor1.run(FORWARD);     
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}  

Any help or guidance would be really appreciated thanks!

This outdated driver consumes too much energy, you better use a newer (MOSFET) driver.
Also note that each motor requires 2 half-H-bridges for fwd/back movement.

Are these for both the Uno and the motors?

2 motors may be easier to control. You added speed feedback to each motor?

Lots of dreams telling nothing about the current situation. What's the closest issue?
Learn to handle every single piece of hardware first. When You manage all of them You can integrate them and build the system.
So far all those "dreams" only adds disturbing masses of text.

Programming "the platform"....... What other pieces do You know how to program?

For the UNO and the motors yes, I tried with 4.5 V and the motors weren't recieving enough voltage and caused a lot of issues with my project.

Initially my teacher told me to try a 2 motor system, but it couldn't rotate and drive so I had to move to a 4 motor system due to the deadline which is next week.

9V isn't for the long term, since I'm only using it temporarily to see if the project actually works.

Everything else works, since I've watched numerous videos and tutorials that are similar to my project. The code works and everything and the project, I'm just confused on where to add a simple command on the actual code itself. (At the very beginning when the switch turns on.) It's only a minor modification to support the brief which was in my project.

It's only a rotatable platform you see on taxis and some cars that allow wheelchair users nothing else.

Adding a "command"... What will generate, make the "command", wanted.
Understand that household talk is very unprecise.
Before starting coding a plan for the execution needs to be made. They are called "flow charts".
Also use the // and add comments in the code.
Reading the code it's a mystery what's done and what is next to do.
Flow charts would give a good overview

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