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);
}
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?
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.
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.