motor connection

i am a beginner. i am making an obstacle avoiding robot using arduino uno along with motor shield. i have already connected two driving motors. i want to connect a third one such that it turns on when the robot is moving straight ahead and should turn off when the robot makes a turn. but with my current code vice versa is happening. what should be done? (the motor shield can connect upto 4 motors)

obst.ino (2.72 KB)

Hi,
I see you seem to be using one of those L298 driver boards that need their own library! I only tried it once and I put it in the bin!! (Strange labeling, strange code). L298/293 are not very good drivers as you lose power in the output transistors. Go get yourself a tiny DRV 8833 module, much better and you have full control of the motors, etc using you own code.

See my bots here: www.melsaunders.co.uk under electronics of course, We can help, but lets see your schematic or wire drawing, etc. What power are you using??

The code to use the U/S sensor is simple you don’t need a library? I can’t see your third motor in your code or have I missed it? What does it do?

Put your code between code brackets, as top left </> is easier to read and take less space.

Hope it helps, regards.

Mel.

No idea without knowing the motor shield. It looks like you are sending a hard coded number in each of the functions. The numbers being sent must be wrong, but without a datasheet or other documentation it is impossible to tell.