Ultrasonic sensor controlling dc motor code?

I am making some code for a robot i am trying to make (just a simple obstacle detection robot) and i couldent find anything for my specifacations, if you have seen any recources please tell me or give me a link to them!

specifacations...

9v battery (plugged into the +5 v source of the l298)

protrinket 5v usb

dc motors max 6v (i need these to just be 2 pwm pins)

motor driver l298 (4 output pins)

hc-sro4 ultrasonic sensor

if you cant find any code online for 2 motors just tell me if you find code for one motor and then from their i can modafiy the code!

i also just wanna add that littearly all i need is something detected about 5 inches from the sensor will trigger one or 2 motors.

anyways thanks for helping!

Hi, What model motor driver do you have? Or do you just have a L928 IC?

You will need more than a 9V transistor battery for the motor power, 4 AA batteries in series will be better.

Tom... :)

I am just using the l298 motor driver

But you are saying that putting the 9v in the 5v spot is damaging the board? Becuase I can put it in the 12v spot but I think that would damage the motors...

Motor driver.....

https://www.amazon.com/Qunqi-Controller-Module-Stepper-Arduino/dp/B014KMHSW6/ref=sr_1_3?ie=UTF8&qid=1512833143&sr=8-3&keywords=Motor+driver

And I saw online that if I put the 9v battery into the 12v slot it could damage my 6v motor but I don't know if the 9v battery is damaging the l298 by putting it in the 5v slot.

I am making a obstacle detection robot and need some help, I am wondering if I can plug in a 9v battery to the +5v slot of the l298 module and have it run 2 dc motors (the dc motors minimum power is 4v and the maximum is 6v)

I am also wondering if I plug in the 9v into the 12v slot will it ruin the l298 or the motors which are maximum 6v? And if I can't use a 9v battery what is something similar size or smaller that I can use.

Not one of the 9V PP3 block batteries. They are intended for smoke alarms and are hopeless for motors.

@TORTLE_TECH, please do not cross-post. Threads merged.