Human following car using L293d motor shield

HI!,
I have a problem about this code below

#include<AFMotor.h>

#define Lir 6
#define Rir 7

#define trig 2
#define echo 4

AF_DCMotor RF (4);
AF_DCMotor RR (3);
AF_DCMotor LF (1);
AF_DCMotor LR (2);

byte mspeed = 255;

void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(Lir, INPUT);
pinMode(Rir, INPUT);
Serial.begin(9600);

RF.setSpeed(mspeed);
RR.setSpeed(mspeed);
LF.setSpeed(mspeed);
LR.setSpeed(mspeed);

goFront();
}

i'm testing my components before starting my project. when i testing my motor driver.
i included pinMode for my ir sensors and the ultrasonic sensor.after i including the pinMode my motors are not working. when i comment them my motors are running good.what is the reason for that?

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

you forgot to add newPing library..

is it want ?

you are using ultrasonic sensors so , us should include newping library.

ok,but including the pinMode motors R not work !

send me the circuit diagram and all the parts

ok:)

give me some time i will code and submit... :grinning:

ok:)

bro upload this sketch and try ,

first check the pins properly i may assigned the pins inorder

#include <AFMotor.h>
#include <NewPing.h>
#define RIGHT 6
#define LEFT 7
#define TRIGGER_PIN A0
#define ECHO_PIN A1
#define MAX_DISTANCE 100

NewPing sonar(TRIGGER_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);

void setup()
{
Serial.begin(9600);
pinMode(RIGHT, INPUT);
pinMode(LEFT, INPUT);
}

void loop()
{
unsigned int distance = sonar.ping_cm();
Serial.print("distance");
Serial.println(distance);

int Right_Value = digitalRead(RIGHT);
int Left_Value = digitalRead(LEFT);

Serial.print("RIGHT");
Serial.println(Right_Value);
Serial.print("LEFT");
Serial.println(Left_Value);

if((Right_Value==0) && (distance>=10 && distance<=30)&&(Left_Value==0)){
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(200);
Motor3.run(FORWARD);
Motor4.setSpeed(200);
Motor4.run(FORWARD);
}else if((Right_Value==0) && (Left_Value==1)) {
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(0);
Motor3.run(BACKWARD);
Motor4.setSpeed(0);
Motor4.run(BACKWARD);
}else if((Right_Value==1)&&(Left_Value==0)) {
Motor1.setSpeed(0);
Motor1.run(BACKWARD);
Motor2.setSpeed(0);
Motor2.run(BACKWARD);
Motor3.setSpeed(200);
Motor3.run(FORWARD);
Motor4.setSpeed(200);
Motor4.run(FORWARD);
}else if((Right_Value==1)&&(Left_Value==1)) {
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}else if((Right_Value==0) && (Left_Value==0)) {
Motor1.setSpeed(200);
Motor1.run(FORWARD);
Motor2.setSpeed(200);
Motor2.run(FORWARD);
Motor3.setSpeed(200);
Motor3.run(BACKWARD);
Motor4.setSpeed(200);
Motor4.run(BACKWARD);
}
else if(distance > 1 && distance < 10) {
Motor1.setSpeed(0);
Motor1.run(RELEASE);
Motor2.setSpeed(0);
Motor2.run(RELEASE);
Motor3.setSpeed(0);
Motor3.run(RELEASE);
Motor4.setSpeed(0);
Motor4.run(RELEASE);
}
}

did you try this code.....,.. :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning: :grinning:

If you are going to post code then please do it properly

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

thanx bro,but when goes forward 1 motor is not working!

and doesn't turn left

ok i will fix you also check your motor driver

ok bro:)

post a video of it

my motor driver is working goood
because i made a bluetooth car last week .