Problem detecting a HIGH level signal using an analog channel in Arduino UNO

Hello.

I appreciate in advance your support on the following:

I am building a custom sound system where it contains a couple of stepper motors that are driven by a the following motor shield (using one fro each stepper motor): http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?search_type=jamecoall&catalogId=10001&freeText=2187690&langId=-1&productId=2187690&storeId=10001&ddkey=http:StoreCatalogDrillDownView

Now, these stepper motors are going to control a set of doors that are going to “hide” the system (http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?search_type=jamecoall&catalogId=10001&freeText=155460&langId=-1&productId=155460&storeId=10001&ddkey=http:StoreCatalogDrillDownView), my idea is use a couple of roller switches (2 for each motor shield) to indicate the stepper motor when to stop.

My plan is to connect those 2 roller switches: one to A0 (indicating when the door is closed) and the other to A2 (indicating when the door is open)

My problem is that for some reason the stepper motor is not stopping then I activate the switch using the code copied to this message, I don’t know if I’m missing configuring the voltage reference or something else. I have tried using the 5V power source coming from the USB and also an external power (9V to be exact).

This code is for one side of the stepper movement, hopefully it can be useful to use as guidance to provide me with your support.

Attached is a block diagram on how I am connecting the switches to the Arduino board.

Thank you.

#include <Stepper.h>

/Configuration pins for the subs/
int pwm_sub_a = 3; //PWM control for motor outputs 1 and 2
int pwm_sub_b = 9; //PWM control for motor outputs 3 and 4
int dir_sub_a = 2; //direction control for motor outputs 1 and 2
int dir_sub_b = 8; //direction control for motor outputs 3 and 4

/Configuration pins for the amps/
int pwm_amp_a = 5; //PWM control for motor outputs 1 and 2
int pwm_amp_b = 10; //PWM control for motor outputs 3 and 4
int dir_amp_a = 4; //direction control for motor outputs 1 and 2
int dir_amp_b = 12; //direction control for motor outputs 3 and 4

/General variables and stepper function variables/
int dclosesub = A0;//bit to see if the door is close on the subs
int dopensub= A2;//bit to see if the door is open on the subs
int SubPos = 0;
const int STEPS = 200; //number of steps
Stepper myStepper(STEPS, dir_sub_a, dir_sub_b);
Stepper myStepper2(STEPS, dir_amp_a, dir_amp_b);

void setup() 
{
  // put your setup code here, to run once:
   pinMode(pwm_sub_a, OUTPUT);  //Set control pins to be outputs for subs
  digitalWrite(pwm_sub_a, LOW);
  pinMode(pwm_sub_b, OUTPUT);
  digitalWrite(pwm_sub_b, LOW);
  myStepper.setSpeed(40);//era 30
  
  pinMode(pwm_amp_a, OUTPUT);  //Set control pins to be outputs for amps
  digitalWrite(pwm_amp_a, LOW);
  pinMode(pwm_amp_b, OUTPUT);
  digitalWrite(pwm_amp_b, LOW);
  myStepper2.setSpeed(40);//era 30

  pinMode(dclosesub, INPUT);
  pinMode(dopensub, INPUT);
}  

void loop() 
{
  do
  {
     pinMode(pwm_sub_a, OUTPUT);  //Set control pins to be outputs
     digitalWrite(pwm_sub_a, HIGH);
     pinMode(pwm_sub_b, OUTPUT);
     digitalWrite(pwm_sub_b, HIGH);
     myStepper.step(-STEPS);
     pinMode(pwm_sub_a, LOW);  //Set control pins to be outputs
     pinMode(pwm_sub_b, LOW);
     //delay (100);
     SubPos = digitalRead(dopensub);  
  }
  while(SubPos == LOW);
}

block diagram switches.JPG

Please read and follow directions in the "How to use this forum" post -- edit your post and add code tags.

Please. Show a schematic and picture of your wiring.

And a part number for the motor.

"I am using the 5V pin from the board as my voltage source, I measure the voltage going to A3" I think many steppers need more than the maybe 500mA (with 7.5V, 1A supply at the barrel jack) that is available at that pin. Certainly under 500mA if powering from USB.

CrossRoads: And a part number for the motor.

"I am using the 5V pin from the board as my voltage source, I measure the voltage going to A3" I think many steppers need more than the maybe 500mA (with 7.5V, 1A supply at the barrel jack) that is available at that pin. Certainly under 500mA if powering from USB.

I have updated the message with more information and added a block diagram.

Thank you for the help.

The first problem I see is that the switches are wired incorrectly. Both switch between nothing and +5v. This is not really a change of state as the A0 and A3 lines are floating "Google floating input". You need to tie them low so that when the switch goes on they go high. Try putting a 10k resistor from each input to ground then see what the program does.

The diagram was good for the swiching but to check the whole program you need to show us the whole electrical setup.

int dopensub= A2;//bit to see if the door is open on the subs

Does not match the block diagram where the pin is connected to A3

aston1595: I have updated the message with more information and added a block diagram.

Almost got the "code" box right.

Daz1712: The first problem I see is that the switches are wired incorrectly. Both switch between nothing and +5v. This is not really a change of state as the A0 and A3 lines are floating "Google floating input". You need to tie them low so that when the switch goes on they go high. Try putting a 10k resistor from each input to ground then see what the program does.

The diagram was good for the swiching but to check the whole program you need to show us the whole electrical setup.

Thank you for the request, I have connected the 10K resistors to GND and I still can't stop the stepper when I have a 5V signal going to pin A2. I can try to draw the whole electrical setup, hopefully wit the attached pic can help out.

pinMode(pwm_sub_b, LOW);

Usually pinMode is used with INPUT, INPUT_PULLUP, or OUTPUT. It's not normal to use HIGH or LOW. I'm not sure right off hand which mode that would set you to.

when I have a 5V signal going to pin A2.

The switch diagram shows that there is NO connection to A2.