Arduino if Statemennts Limiting my Functions

I have been programming with Arduino for just over 6 months and I have never run into this issue until not. I am doing a simple if statement, if (vVal > 3.00) {..., but whenever I do this,when reading the value from a potentiometer for example, I can't read anything above that value. It's like the if statement is constraining everything and this only started recently. Does anyone have any clues as to why?

int STEPS = 32;
int IN1 = 8;
int IN2 = 9;
int IN3 = 10;
int IN4 = 11; 


Stepper stepper(STEPS, IN1, IN3, IN2, IN4);
int joyX = A0;

int xVal;

float vVal;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
stepper.setSpeed(10);
}

void loop() {
  // put your main code here, to run repeatedly:
xVal = analogRead(joyX);

vVal = (5./1023.)*xVal;

if (vVal > 3.00) {
  stepper.step(STEPS);
}

if (vVal < 2.00) {
  stepper.step(-STEPS);
}

Serial.println(vVal);
}

Add more print statements inside the if blocks.

What is being printed now? That is, do you see values all across the range? And the only way you ”know” what is happening is because of the response to the stepper calls?

a7

I attempted to add additional print statements inside the if block but the only thing being read from my joystick is 2.57. When I push it either way to go over 3 or under 2, the serial monitor stops entirely, but the stepper also doesn't respond to anything.

OK, not code.

Post as much as you can along the lines of not-code.

Schematic, hardware, power supply &c. &c.

a7

i see values up to 5 when testing the code without stepper

Alright, I'm using an Arduino UNO with a joystick module connected to pin AO measuring its X-Value. The joystick is currently powered by the 5 volt ppin of the Arduino with the same ground. I am using a 28BYJ-48 stepper motor, being controlled with a ULN2003 stepper motor drive, powered with a DC power supply module connected to a 9 volt battery. The signal for the motor is indicated by pins 8, 9, 10, and 11.

Also thank you so much for helping me out.

THX.

Time to learn how, if you need to, and hand draw a schematic.

It’s the best way to communicate, your prose leaves too many questions.

Comment out all the stepper lines of code and see your program work perfectly, me and @gcjr will put money on that, if

you have the potentiometer wired correctly, and a few other dets that will best be presented visually.

No need in fact it would probably be prefer to not go find some CAD program.

google

schematic diagram

pick images and then do your best with paper and pencil, show everything, take a celly and post it here.

TIA

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.