If Statements not responding when receiving an input

Hello, I'm currently running into an issue where even though I've verified that my Arduino is receiving a propper 5v signal from the propper input pin, the code is still skipping right over the if statement which the said signal should activate. theirs no issue with the wiring as I'm doing a direct jumper w a 5v signal to simulate for the program.

Blockquote
#include <Stepper.h>
int StartMotor = 3;
int reverseMotor = 4;
const int stopmotor = 22;
int RMotorStep = 50;
int RMotorDir = 52;
int LMotorStep = 51;
int LMotorDir = 53;
int DOctrl = 30;

void setup() {
Serial.begin(9600);
pinMode(stopmotor, INPUT);
pinMode(reverseMotor, INPUT);
pinMode(StartMotor, INPUT);
pinMode(DOctrl, INPUT);
pinMode(RMotorStep, OUTPUT);
pinMode(RMotorDir, OUTPUT);
pinMode(LMotorStep, OUTPUT);
pinMode(LMotorDir, OUTPUT);
}

void loop()
{
START:
//reviewing inputs and outputs
Serial.print("time to work"); //looping text before sub actions start
delay(2000);
digitalRead(StartMotor);
digitalRead(reverseMotor);
digitalRead(stopmotor);
if (StartMotor == HIGH)
{
digitalWrite(RMotorStep, HIGH);
digitalWrite(RMotorDir, HIGH);
digitalWrite(LMotorStep, HIGH);
digitalWrite(LMotorDir, HIGH);
Serial.print(" Motors goin Forward ");
delayMicroseconds (100);
goto START;
}
else if (reverseMotor == HIGH)
{
digitalWrite(RMotorStep, HIGH);
digitalWrite(RMotorDir, LOW);
digitalWrite(LMotorStep, HIGH);
digitalWrite(LMotorDir, LOW);
Serial.print(" Motors reverse ");
delayMicroseconds (100);
goto START;
}
else if (stopmotor == HIGH)
{
Serial.print(" Motors stopopopop ");
delayMicroseconds (100);
goto START;
} else
{
Serial.print("gotta reset");
delay(1500);
goto START;
}
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

if (StartMotor == HIGH)

StartMotor is a pin number, not the state of that pin. Did you mean

if (digitalRead(StartMotor) == HIGH)
1 Like

Thank you, yup that's what I meant.

It helps considerably if you give move descriptive names to variables such as

const byte startMotorPin = 3;

In passing, note the use of a byte rather than an int to save memory and the fact that, as the value will not change the variable has been declared as a constant value

1 Like

And please, get rid of the gotos.

1 Like