motor sensor controlled car

Hi everybody i have a small question . I tried to modify/hack a cheep RC chinese car .I wanted to make autonomous car which avoid objects and executes other small functions. The basic is that i have removed the chip RX_2B and i use the arduino board instead.I use 4 pins( 2 for the controlling of forward and reverse mouvement , and 2 for going right or left . I am using also a ping ultrasonic sensor for avoiding objects ( here i use 4 pins - one to +5 V , one to GND , one who called Trigger and one who called ECHO ). Also i use a combination of photo resistor and a pair of leds for make the leds light when its dark in the room ( here i use one pin for the led , because they are 2 in a row ). I also use 2 leds to light when i make reverse mouvement.(another 2 pins ) The main idea of this car is this : When i dont have an object in front of my car than , the car must just go ahead - using the forward command ( the code this must be executed when the distance is greater than 12.50 ) .And if there is an object which is closer to the car than 12.50 , the car must stop , go reverse at same time turning on the leds , than after a small period stops and after that going forward and making a right turn for another small period .That’s the basics . I am using 4 x 1.5 V , i have an limiting diod and a 2200 uF capacitator with the purpose tto make the voltage about 5.4 V , because of the operating voltage of arduino board . The main problem is that when i turn on the car without the connection cable (usb )on my board (i mean when i use just the batteries) , than instead of going streight ahead(because there is no object in front of the ping sensor ) the car goes reverse for a small period , go forward and after a small period , go right . Ang this cycle is repeated twice , before starting executing the main program ( or just going ahead ) .BUT when i use the usb cable connection to the pc + the 5.4 volts of the batteries, than there is not such problem, and everything is alright . I want to ask is this some problem with the processor , i mean am i supposed to say something on the first lines of the program , to indicate some adresses or there is another problem. Thanks . This is the code :

int forward = 11;
int reverse = 10;
int left = 9;
int right = 8;

#define ECHOPIN 3
#define TRIGPIN 2

int ledBL = 5; // back led 1
int ledBR = 6; // back led 2

int ledBlue1 = 7; // front led
int lightPin = A5; // photoresistor

void setup() {


pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);


pinMode(ledBR, OUTPUT);
pinMode(ledBL, OUTPUT);

pinMode(ledBlue1, OUTPUT);


void loop() {


digitalWrite(TRIGPIN, LOW);
digitalWrite(TRIGPIN, HIGH);
digitalWrite(TRIGPIN, LOW);
// Compute distance
float distance = pulseIn(ECHOPIN, HIGH);
distance= distance/58;


if ( distance < 12.50) {





if ( distance > 12.50) {





Get rid of the diode and capacitor. The Arduino will happily run on 6V What it will not do is provide much current from its pins. Are your motors wired directly to the Arduino ?

I am using the board of the rc car . This is the h-bridge.There are some resistors and transistors . ( 3 transistors for each pin )

Good news about the H-bridge

Still get rid of the diode and capacitor though.

In fact i use them because i connect the motors + the photo resistor + the ping sensor to the +5 V pin of the arduino board . If i cut the capacitator and the diod,isnt there risk for this pin to burn because of the higher voltage ( about 6 volts ) ?

Where are you feeding your battery voltage in? Are you putting it into the power jack, or the +5V header pin?

I am using the +5 volts of the board arduino , thats why i use the combination of capacitator and the diod , to limite the voltage .

It had occurred to me to do the same but I did not like the sound of it so I did it the right way. Power into the Arduino through the power jack and directly to the motors

Ok than, i will try this.I jsut was wondering what is the problem , what and why is causing it to happen ? But thanks anyway for the suggestion.