DC MOTOR FORWARD REVERSE USING 2 CHANNEL RELAY MODULE

Hello everyone,i’m running a dc motor in forward and reverse condition using 5V 2 channel relay module. When i push the forward push button, dc motor will run forward until touch the limit switch;it will stop forwarding. I want to make the dc motor not running forward even i press the forward push button after it stop forwarding.This is my code.

bounce2_change_codingaiman.ino (2.01 KB)

Create a flag variable, say, boolean limited = false;. When the motor activates the limit switch, set the flag to true. Where you read and act on the forward button, check the value of the flag. If it is true don't allow the motor to run. You will need a method to clear (make false) the flag before you can move forward again.