Motor Direction reverse using Proximity Sensors

Hello!
I am Running a Dc motor with L298 Controller. I want to reverse the direction as soon the Proximity sensor is triggered and continue the reverse direction till the second Prox sensor is triggered. It should continue the reverse and forward in a loop without stopping. The problem I am facing is I am not able to program it right since I use coding occasionally. I have tried switch condition, if else conditions , while if condition but nothing works, I am attaching the code in comments.

While you're at it, also post a schematic and details of the sensor.

Just to add a thought, when reversing direction, let the motors stop before you throw them into reverse…
You’ll thank me in 12 months time.

Have you read the instructions? :face_with_raised_eyebrow:

Thanks. really appreciated. I have changed the code and it worked.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.