Voltage issue with motor driver

Hey Arduino community!

For a project at university we are working on a line following robot using a L298N
motor control, arduino UNO and 6V DC motor (those common yellow ones) with a
maximum of 500 mA. See layout in image

As stated by a youtube video, powering the L298N with 12V would have enough
voltage to power the arduino as well, eliminating an extra power source. This is
the reason we chose for 12V battery pack. However, voltage is going to be too
high for the motor right?

Does anyone have a suggestion to change this setup to a viable one? Unfortunately,
these components are already ordered and we are close to budget.

What matters to the motor is the current that passes through it. If you keep the PWM value low enough then, even with the 12v supply, there will not be too much current through the motor. Put another way, you may get max power from the motor with analogWrite(130); rather than analogWrite(255); which would probably overload and damage the motor.

But you will need to experiment to find the correct upper limit for your motor.

...R

Robins explanation is spot on and one of the reasons I use PWM in most of my motor projects.

Another reason may be also to reduce motor harmonics on "unknown" motors that operate in the 12 volt range.

You can also use them at different PWM frequency's too (Example here) Lines 49 and 50, 63 to 77, 113-114.