Switching from 9v to 6v

I am currently doing a project which uses 2 dc motors(6v) controlled by a motor driver(l293d),a servo, a rain sensor and a ultrasonic sensor.I am planning two use 6xAA batteries to power the whole thing(including an arduino).My problem is that is i do not know how to change the 9v to 6v which is needed by the motors.

A DCDC buck converter can be used for that. Which one depends on the current need of the motors.

Other way would be to change to 4xAA and use a LDO for the Arduino. Although you would miss a bit of capacity that way.

One simple way would be to just use four more AA batteries. You would need a separate battery holder for the second set of batteries.
But a buck converter would be efficient as already mentioned.

Why do you need 9 volts? To power the Arduino? If so, just supply 6volts instead. The regulator will not regulate well, but it will still drop the 6 volts to five volts. It might be a bit under five volts, but it will run just fine at 4.5 volts. Sometimes you can even run it at 3.3volts, but it is recommended to drop to 8MZ crystal instead of 16.

Try running the Arduino on six volts. Feed it in the same way you were 9V. I'm sure it will be reliable, and not use much power either.

But bear in mind that an L293D is likely to drop around 2V so if you really want to see 6V at the motors then running the driver at 9V is about right.

Steve

Include about 4 or 5 diodes and get a drop around 3 V. Sorry for my English.

I have seen other posts to the effect that any attempt to use an L293 off 6V will not end well.
You need to supply it with at least 9V. If , after measuring the voltage across the motors it turns out that it is supplying too much voltage to the motors then you will just have to insert power resistors in series with
the motors to drop the voltage :

RDropping =(VIN-VLOAD)/ILOAD

9V is fine. 2V drop over the L293D (that's simply lost as heat) leaves about 7V for the motors. Likely not a problem. Especially as those AA batteries will quickly drop to 1.2-1.3V output.

If still too much just keep your PWM levels down a bit. An analogWrite() value of 220 will reduce the average current of a 7V supply to that of a 6V supply.