Motor for Steering Problem

I got a problem about my Motor steering. it rotate 360 degree.

Normally, when a car want to rotate left or right, the motor steering will only rotate 45 degree on either side and stop.

But,when i give command for my car to turn left or right, the motor steering rotated 360 degree and make the holder loose.

What should i add to my coding to make it rotate 45 degree only?

Here’s the attachment of my coding and my car photo.

NodeMCU_Car.ino (4.42 KB)

What should i add to my coding to make it rotate 45 degree only?

You need to tell us what type of motor that is, and how it is normally controlled.

Image from Original Post so we don’t have to download it. See this Simple Image Guide

IMG-20180414-WA0000.jpg

…R

The thing in your photo looks like a servo, but I can't be sure. If it is a servo and if it used to steer properly I suspect, based on your description, that it is now broken.

...R

There would have been end stop feedback from a contact plate inside that servo. I have seen quite a few in rc toys. It uses a regular brushed motor but normally there is a little round contactor that rotates against a pcb inside that gives some feedback when the motor hits it's end limits. What are you doing with the green and yellow wires? I would investigate what happens to those wires when it rotates. You may find it easier to replace the whole thing with a regular servo.