How to select batteries

I am trying to find a grid solving robot where i will use and arduino mega, a line sensor array, two ultrasonic distance sensors, 2-3 servos ranging from 3.4-8.7 volts, and two dc motors ranging 3-6 volts. For dc motors i will be using L298D ic. Any suggestion how to select the proper battery or power source.

The Arduino can run on 3.6 to 6V and both your DC motors and servos can run in that range so I would pick something in that range for your battery. You will have to connect it directly to the "+5V" pin since the "Vin" pin needs at least 7V and neither your servos not your motors can deal with that.

Now that you know the voltage you need:

I would avoid using two batteries! Try going for a 8.4v battery. I would probably get one around 2000mAh depending on how long you want your robot to run.

You can connect the battery right into your servos, then into the voltage regulator on your Arduino, and for your motors you can use a 6v UBEC.

Best of luck!

EDIT: As for how do you pick a power source, I generally find the highest voltage component that i’m using and buy a battery for that. Then I regulate the voltage down for my other components. When It comes to selecting the amperage you need to add up how much power your robot will suck, then find out how long you want your robot to run.

For example say your robot sucks 1 Amp and you need it to run for .5 hour. You would technically need 5000mAh battery, however, its good practice to buy a battery with a little more mAh then you need!