Want Help With My Project (Arduino Car/Robot)

I just wanted help with my arduino car project

Materials I have :

  1. Arduino Uno
  2. L293D Motor Driver
  3. 4 motors with wheels
  4. 4 servo motors
  5. 2 IR sensors
  6. Ultrasonic Sensor
  7. HC-05 Bluetooth module

with these items i want to create a robot car which can move around which i can control using my phone and voice controlled and obstacle avoiding and line following

As of right now i have created it to move around using my phone and it is voice controlled aswell , i want help with adding the obstacle avoidence and line following to my code and how to connect the sensors required to do it

this is my code

#include "AFMotor.h"

const int MOTOR_1 = 1; 
const int MOTOR_2 = 2; 
const int MOTOR_3 = 3; 
const int MOTOR_4 = 4; 

AF_DCMotor motor1(MOTOR_1, MOTOR12_64KHZ); // create motor object, 64KHz pwm
AF_DCMotor motor2(MOTOR_2, MOTOR12_64KHZ); // create motor object, 64KHz pwm
AF_DCMotor motor3(MOTOR_3, MOTOR12_64KHZ); // create motor object, 64KHz pwm
AF_DCMotor motor4(MOTOR_4, MOTOR12_64KHZ); // create motor object, 64KHz pwm

int state;
int Speed = 130; 

void setup() {
motor1.setSpeed(Speed);   // set the motor speed to 0-255
motor2.setSpeed(Speed);
motor3.setSpeed(Speed);
motor4.setSpeed(Speed);  
Serial.begin(9600);
delay(500); 
}

void loop(){   
if(Serial.available() > 0){  //if some date is sent, reads it and saves in state     
state = Serial.read();      
if(state > 10){Speed = state;}      
}
           
motor1.setSpeed(Speed);          // set the motor speed to 0-255
motor2.setSpeed(Speed);
motor3.setSpeed(Speed);
motor4.setSpeed(Speed);
   
//===============================================================================
//                          Key Control Command
//===============================================================================   
     if(state == 1 || state == 'F'){forword(); }  // if the state is '1' the DC motor will go forward
else if(state == 2 || state == 'B'){backword();}  // if the state is '2' the motor will Reverse
else if(state == 3 || state == 'L'){turnLeft();}  // if the state is '3' the motor will turn left
else if(state == 4 || state == 'R'){turnRight();} // if the state is '4' the motor will turn right
else if(state == 5 || state == 'S'){Stop(); }     // if the state is '5' the motor will Stop
else if(state == 8){forwordleft(); }     // if the state is '8' the motor will forword then left
else if(state == 9){forwordright(); }     // if the state is '9' the motor will forword then right
else if(state == 10){backwordleft(); }     // if the state is '9' the motor will backword then left
else if(state == 11){backwordright(); }     // if the state is '9' the motor will backword then right
/////////////////////////////////////END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//===============================================================================
//                          Voice Control Command
//===============================================================================
else if(state == 6){turnLeft();  delay(400);  state = 5;}
else if(state == 7){turnRight(); delay(400);  state = 5;}
/////////////////////////////////////END\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

delay(80);    
}

void forword(){
motor1.run(FORWARD); //forward
motor2.run(FORWARD); 
motor3.run(FORWARD); 
motor4.run(FORWARD);
}

void backword(){
motor1.run(BACKWARD); // backword
motor2.run(BACKWARD);
motor3.run(BACKWARD); 
motor4.run(BACKWARD); 
}

void turnRight(){
motor1.run(FORWARD); // right
motor2.run(FORWARD); 
motor3.run(BACKWARD); 
motor4.run(BACKWARD);
}

void turnLeft(){
motor1.run(BACKWARD); // left
motor2.run(BACKWARD);
motor3.run(FORWARD); 
motor4.run(FORWARD); 
}

void forwordleft(){
motor1.run(RELEASE); // forwordleft
motor2.run(FORWARD);
motor3.run(FORWARD); 
motor4.run(RELEASE); 
}

void forwordright(){
motor1.run(FORWARD); // forwordright
motor2.run(RELEASE);
motor3.run(RELEASE); 
motor4.run(FORWARD); 
}

void backwordleft(){
motor1.run(BACKWARD); // backwordleft
motor2.run(RELEASE);
motor3.run(RELEASE); 
motor4.run(BACKWARD); 
}

void backwordright(){
motor1.run(RELEASE); // backwordright
motor2.run(BACKWARD);
motor3.run(BACKWARD); 
motor4.run(RELEASE); 
}

void Stop(){
 motor1.run(RELEASE); // stopped
 motor2.run(RELEASE);
 motor3.run(RELEASE);
 motor4.run(RELEASE);
}


to this code i wanna add the obstacle avoidance using the ultrasonic sensor and line following with IR sensors can anyone please help me

what type of help do you need? someone writing the code for you (this is typically not what you get on this forum) or you plan to try to integrate obstacle avoidance and line following with IR sensors into your code and would like help to debug your code (more likely to happen).

i have tried to write my own code for adding the obstacle sensor and ir sensors for line follwing but its not okring no matter how much i try so just wanted someone to give me a bit of help with the code

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction

Describe this.

Add a state and a function to call just like your other "key control commands."

I got it my project is working now completed it thanks for the help

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