The problem I'm facing here is that though I have tried inserting another PID function to control the other pin for the H-Bridge to turn the motor otherwise ,Still the code behaves in a erratic way the motor goes on rotating by itself like that only random turns sometimes speeds up and sometimes goes down and/or runs on one way by itself and then stops like that only.