Rotary switch pot only outputting 0

I did not touch the knob and it changed full scale. We are talking about a rotary switch potentiometer, so i'm not sure what brought up LEDs. I expected single values corresponding to the resistance of the position of the switch. Is this assumption wrong? Am I supposed to use a different component to get the same effect?

That sounds like:

If you hook 0 & +5 to the CCW and CW terminals, you should be able to read a constant voltage at the W terminal. If you feed a constant voltage into A2, then analogRead(A2) should get you a fairly constant value in the analogRead(pin) range.

I'd check all the voltages on the resistors and terminals and see if they are as expected.

The rotary switch pot should work like a big voltage divider, so it should be easy to calculate the expected voltages.

Edit: Wildly wandering values could be normal for 'analogRead(pin)'-ing reading of an unconnected analog pin.

I misunderstood. Good catch, @DaveX . It's not supposed to change without your input to the pot.

That assumption is correct. You should be able to get roughly the same values for each pot position that you can use to output to something else on another pin.

I brought up the LEDs because changing the resolution of something like your pot and outputting that to something that requires PWM (analogWrite )or some other 8-bit value (which is very common in electronics) to try to bring clarity to you as to how you're going to ultimately use this pot to interface with your game.

1 Like

I think you mean you got a reading of 10 with the DMM set on 20K range.
So resistors are 10K.

Possibly brown, black, ORANGE, grey. 10K.

When you measure from CWW to CW, what range did you have your DMM set to.
Try setting to 200K range.

Can you post us an image of your DMM?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

@TomGeorge
yes thats right, it was reading 10 with the DMM set to 20k ohms range, so yes that confirms the resistors are 10k. HUZZAH! Also the color bands confirm it.
I had the DMM set to 2k. Sure here is an image of the DMM.
When I set it to 200k, I get reading between 90 to 170 between CCW and CW. It doesn't stay consistently on a specific number.

Sounds like a dodgey solder joint or short between solder pads.
What about between CW and W, for each switch position.

Nice meter for your application. :+1:

Tom.. :smiley: :+1: :coffee: :australia:
PS.I'm at work at the moment, having smoko (Aussie term), will check at lunchtime.

2 Likes

position 1: readings between 0 and 158
position 2: readings between 10 and 139
position 3: readings between 20 and 100
position 4: readings between 30 and 130
position 5: readings between 40 and 69
position 6: readings between 50 and 90
position 7: readings between 60 and 110
position 8: readings between 70 and 120
position 9: readings between 80 and 130
position 10: readings between 90 and 140

Did your Nano come with the headers pre-soldered?
Are the wires between your Sparkfun board and the Nano mechanically fastened or soldered?
I'm running out of things to suggest to check, but will say that I agree with some of the other helpers here who wonder if there's a soldering issue on that Sparkfun board.

Really look closely, like with a camera zoom or magnifying glass. Sometimes the issue (if there is one) is really obvious under magnification.

Those readings look pretty uncertain. The low-range numbes look dead on to the expected values from a ladder of 10K resistors, but the high values are awful. Is something loose connecting to CW and W? Normally I'd expect readings to be stable within 1% and most certainly within 10%. Your DMM looks like it has 2000count/3.5digit resolution, so in 200K mode should measure to +/-0.1kOhm.

I think I'd try hooking both meter probes up to CW and see if the variation is due to the meter/probes or not. If it isn't the meter/connections, I'd try remelting the solder on the CW,W,CCW pins and the others on the board to fix:

@icefreezer7
As others already ask you - please show a clear photo of the pot's pcb rear side.
Also show an image of your Nano

1 Like

Hi all.
@hallowed31 my nano came with headers pre-soldered. The wires i'm using are dupont jumper wires, I placed myself. I also suspect the issue to be the solder. Even with a magnifying glass, I can't see any obvious issues.
@DaveX Yes, the values are uncertain. I did try hooking both leads to CW yesterday but I don't remember what reading it was giving. I will try to remelt the solder on the header pins and run a test afterwards.
@b707 which pcb rear side? I've already posted photos of the rear side. But here's some more if they were too blurry.





so I resoldered CCW,W,and CW and a few of the other pins that clearly needed a bit more solder. Here is the results from the A2 pin on the nano on each position of the switch.
Position 1: 0 to 0
Position 2: 112 to 114
Position 3: 225 to 227
Position 4: 340 to 342
Position 5: 454 to 455
Position 6: 569 to 570
Position 7: 683 to 685
Position 8: 797 to 799
Position 9: 911 to 913
Position 10: 1023 to 1023

Its looking much more stable now. Guess the entire problem was the solder. Thank you everyone who helped me with this.

2 Likes

that was suggested in post #3 :slight_smile: — it's a usual suspect

glad you solved it - have fun !

1 Like

The CW pin solder in post #51:

...looks like a cold solder joint.

This has some good pics and advice:

As I mentioned in post #38

and alluded to again in post #43, I have no idea where you're going with this project from here but the thread made me think of what I might do with such a potentiometer for such a game so I wrote some code because it amuses me.

Check it out if you like, or don't if you don't feel like it. I code stuff like this for love of the game.

/************* MARS Industries Welcome Series Presents: ********************
   **********   Cobra Rattler Armaments Package [C.R.A.P]    ************
      **********        (tenModeSelectorPotgame)           ************
 ***************************************************************************

   Rough Calibration based on preliminary sketch supplied by icefreezer7
   in this thread of the Arduino Forum
   https://forum.arduino.cc/t/rotary-switch-pot-only-outputting-0/1290810/55

    Position 1: 0 to 0
    Position 2: 112 to 114
    Position 3: 225 to 227
    Position 4: 340 to 342
    Position 5: 454 to 455
    Position 6: 569 to 570
    Position 7: 683 to 685
    Position 8: 797 to 799
    Position 9: 911 to 913
    Position 10: 1023 to 1023

    circuit: potentiometer A2, GND and +5V
             LED to pin 9
             Use Serial Monitor at 115200 baud

  by Hallowed31
   2024-08-13

  Free software as in gratis. No guarantees. Use at your own risk.
  Redistribute if you want to. Party on.

*/
int weaponsVal;
int lastWeaponsVal;
int weaponsPin = A2;
byte weaponMode; // to drive the state machine
byte lastWeaponMode; // to wrangle certain behavior like endlessly Serial printing
boolean newInfo;
int statusLed = 9;
unsigned long statusTimer = 0;
unsigned long statusTime = 0;
int timeToReadMessageDelay = 3500; // default 3500
unsigned long previousMillis = 0;
const long interval = 1000; // for countdown timer, default 1000
int timer = 30; // also for countdown timer

void setup() {
  pinMode(weaponsPin, INPUT);
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, LOW);
  Serial.begin(115200);
  shortLineSpacing();
  Serial.println(F("      MARS Industries Welcome Series Presents:\n"));
  Serial.println(F("      Cobra Rattler Armaments Package [C.R.A.P]\n"));
  delay(timeToReadMessageDelay);
  longLineSpacing();
  weaponsVal = 0;
  lastWeaponsVal = -1;
  weaponMode = 0;
  lastWeaponMode = -1;
  newInfo = false;
}

void loop() {
  weaponsVal = analogRead(weaponsPin);
  if (weaponsVal != lastWeaponsVal) {
    // Serial.println(weaponsVal);
    newInfo = true;
    switch (weaponsVal) {
      case 0 ... 90:
        weaponMode = 0; // disarmed
        statusTimer = 0;
        break;
      case 100 ... 190:
        weaponMode = 1; // chaff
        statusTimer = 100;
        break;
      case 200 ... 290:
        weaponMode = 2;  // GAU-8
        statusTimer = 200;
        break;
      case 300 ... 390:
        weaponMode = 3; // lasers
        statusTimer = 300;
        break;
      case 400 ... 490:
        weaponMode = 4; // flares
        statusTimer = 400;
        break;
      case 500 ... 600:
        weaponMode = 5; // sidewinder
        statusTimer = 500;
        break;
      case 650 ... 740:
        weaponMode = 6; // hellfire
        statusTimer = 600;
        break;
      case 750 ... 825:
        weaponMode = 7; // willy pete
        statusTimer = 700;
        break;
      case 875 ... 975:
        weaponMode = 8; // propaganda
        statusTimer = 800;
        break;
      case 1000 ... 1023:
        weaponMode = 9; // <classified>
        statusTimer = 1000;
        break;
    }
    lastWeaponsVal = weaponsVal;
  }
  informStatusAndArmWeapons();
  blinkStatus();
}

void informStatusAndArmWeapons() {
  if (newInfo == true) {
    if (weaponMode != lastWeaponMode) {
      switch (weaponMode) {
        // newInfo = false;
        case 0:
          Serial.println(F("      Weapons Disarmed\n"));
          wStage0();
          break;
        case 1:
          Serial.println(F("      Chaff Deployed\n"));
          wStage1();
          break;
        case 2:
          Serial.println(F("  GAU-8/A Avenger Armed: BRRRRRRRRAAAP!\n"));
          wStage2();
          break;
        case 3:
          Serial.println(F("      Lasers Armed\n"));
          wStage3();
          break;
        case 4:
          Serial.println(F("      Flares Armed\n"));
          wStage4();
          break;
        case 5:
          Serial.println(F("      Sidewinder Missiles Armed\n"));
          wStage5();
          break;
        case 6:
          Serial.println(F("      Hellfire Rockets Armed\n"));
          wStage6();
          break;
        case 7:
          Serial.println(F("      Willy Pete Armed\n"));
          wStage7();
          break;
        case 8:
          Serial.println(F("    Propaganda Flyers Dropped\n"));
          wStage8();
          break;
        case 9:
          Serial.println(F("   <CLASSIFIED> Package Deployed\n"));
          wStage9();
          timer = 30; // restart countdown timer every time
          break;
      }
      lastWeaponMode = weaponMode;
      newInfo = false;
    }
  }
}

void wStage0() {
  // all weapons idle
}
void wStage1() {
  // maybe code for stopping chaff firing sequence
}
void wStage2() {
  // maybe button code to light 'em up with the ma'CHEEN gun
}
void wStage3() {
  // maybe button code to light 'em up with the lasers
}
void wStage4() {
  // maybe button code to deploy flares
}
void wStage5() {
  // maybe button code to deploy missiles
}
void wStage6() {
  // maybe button code to deploy rockets
}
void wStage7() {
  // maybe button code to deploy white phosphorus
}
void wStage8() {
  Serial.println(F("Brainwashing Material Distributed courtesy of Cold Slither\n"));
  delay(timeToReadMessageDelay);
}
void wStage9() {
  // maybe decending tone BEEEEEEUUUUUuuuu
}

void blinkStatus() {
  if (millis() - statusTime >= statusTimer) {
    statusTime = millis();
    digitalWrite(statusLed, !digitalRead(statusLed));
  }
  if (weaponMode == 9) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      Serial.print(F("You now have T- "));
      Serial.print(timer);
      Serial.println(F(" seconds to reach minimum safe distance\n"));
      timer--;
      if (timer == -1) {
        Serial.println(F("<CLASSIFIED> device detonated\n"));
        timer = 30;
      }
    }
  }
}

void shortLineSpacing() {
  for (int i = 0; i < 15; i++) {
    Serial.println();
  }
}
void longLineSpacing() {
  for (int i = 0; i < 25; i++) {
    Serial.println();
  }
}

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