i have this code to run my 2 dc motor forward and reverse but i dont know what is happening my pins are not correct or i making any other mistake please reply fast.
#define trigPin 13
#define echoPin 10
int revright = 4; //REVerse motion of Right motor
int fwdleft = 7;
int revleft= 6;
int fwdright= 5; //ForWarD motion of Right motor
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// put your setup code here, to run once:
}
void loop() {
float duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance = ((duration / 2) * 0.0344);
Serial.print(distance);
Serial.println("CM");
delay(500);
if((distance<=10))
{
digitalWrite(5,LOW); // If you dont get proper movements of your robot,
digitalWrite(4,HIGH); // then alter the pin numbers
digitalWrite(6,HIGH); //
digitalWrite(7,LOW); //
}
else if((distance<20))
{
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
digitalWrite(6,HIGH); //HIGH
digitalWrite(7,LOW);
}
}
You are right there watching the motors and you don't know what is happening, how are we, so far, far away supposed to know. Why not take a minute and figure out what is happening and then let us know.
Paul
its like when i cant figure out the jumpers needs to take off on the motor drivers.
i am giving 12 v supply to motor drivers from the voltage source anf my motors are humming but not running
dhaval2223:
i am giving 12 v supply to motor drivers from the voltage source anf my motors are humming but not running
Please provide details of the motors, motor driver and "voltage source" you're using so we know what you're talking about. And then tell us what you think your code is supposed to do.
But for now I'm going to guess that your "voltage source" is too weak to run the motors. And an L298 based motor driver, being old and inefficient, is dropping some of the voltage before it even gets to the motors. Or maybe your motors need more current than the motor driver can supply.
BTW why do you sensibly name the motor pins...but then not use those names when you're trying to run the motors?
Steve
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Have you written your code in stages?
Do you have code that just controls ONE motor, forward?
Forget the other motor and the ultrasonic unit.
Thanks.. Tom.. 
my same code works just need to attach one wire from motor driver ground to arduino .
thank you for the advise all the guys