So, according to this video which I had followed, my motors should be constantly running as per the program and should stop running after the program is executed. Instead, when I first ran the script, the motors did run, as per the directions and stopped. But, later, on the second try, one of my wires connecting the motor, disconnected. I immediately reattached it back after stopping the program. But, the motor kept constantly running and was running regardless of the program(I mean that it did not change the directions or stop as per the time). I restarted my Pi and it worked fine for 2 tries and then slowly, the speed of the motors decreased and then at one point stopped. I thought that my batteries were dead as the motors might have consumed a lot of power(PS I am just a newbie in this), but using a voltmeter I found out that it still was nearly full. Then, I tried running it again, and this time, it did not even run. So, just to try out, I restarted my Pi, and it worked again and slowly decreased the speed as the previous incident. So, if there is any solution to this problem, it would be very much appreciated.
This is the circuit layout: https://ibb.co/dk49rVV (Stack Exchange wouldn't let me add a picture due to its size)
P.S. I had made a code error on the first try, which I had later realised when the motors spun only in 1 direction. For the forward function, I had accidentally copy-pasted the same line that is, the
gpio.output(17, True) instead of assigning the values for different GPIOS.
import RPi.GPIO as gpio import time def init(): gpio.setmode(gpio.BCM) gpio.setup(17, gpio.OUT) gpio.setup(22, gpio.OUT) gpio.setup(23, gpio.OUT) gpio.setup(24, gpio.OUT) def forward(steps): init() gpio.output(17, False) gpio.output(22, True) gpio.output(23, False) gpio.output(24, True) time.sleep(steps) gpio.cleanup() def reverse(steps): init() gpio.output(17, True) gpio.output(22, False) gpio.output(23, True) gpio.output(24, False) time.sleep(steps) gpio.cleanup() print("GOING FORWARD") foward(4) print("GOING BACKWARD") reverse(2) Also, just to your notice, I'm very new to this. So, if you feel I'm too dumb or silly, sorry. Thank you.