Resistance Detection?

I'm wondering if someone can help me - I'm having brain freeze figuring out how to achieve this....

So here's the rough setup - I have an Arduino (nano at the moment) that has 4 digital inputs. The "Inputs" are simply 1/4" (6.35mm) Female Guitar Jacks. One pin connected to the GND, and the other, to my INPUT. I am using INPUT_PULLUP, and the male 1/4" jack simply has all pins connected - so basically, when inserting a male jack, it completes the circuit and turns on an LED (So the jack / socket is simply working as a simple switch).

There is a total of 4 Jacks (each with their own LED... I'm using 4 individual Neo Pixels (5050), chained together since they can be controlled from a single pin)

I'd now like to expand on this, where by I will have a small OLED display, probably just a simple 0.96" I2C - but I want to make it display different things, depending on which Male Jack is plugged in at the given time.

I figured the "easiest" way to do this would be to use a different resistor in each of the 4 Jacks, and then try and read the resistance value? Does that sound feasible? Is it possible to do this using INPUT_PULLUP on analog pins? (I imagine I'll need to use the analog input to get a proper reading?)

Failing that, can anyone suggest perhaps a better way to achieve this?

The end result would be that there are 4 female sockets hooked up to the arduino, and that, regardless of which socket a jack is plugged into, it would know what that jack was? (Obv pre-programmed)

I've got everything else down so to speak, just need to figure out how I would go about identifying the different jacks the easiest.

Many thanks in advance

Yes, you must use analog inputs. INPUT_PULLUP is not a good idea because the resistance of the internal pullups varies with temperature, supply voltage and is not consistent between pins or Arduinos. So use fixed external pull-ups, e.g. 10K.

On your jacks, one of them can have the pins connected (effectively a zero resistance), another can have 10K, another 4K7 and the final jack 22K, for example.

Bear in mind that you cannot guarantee an exact reading from analogRead(), so in your code, don't check for a specific value, always check for a value within a range of perhaps 10 either side of the expected value.

I wasn't clear about something from your question. Do you need to know which socket a jack is inserted into, or does that not matter, only which jack is inserted? If so, with careful choice of resistor values, all 4 sockets could be connected to a single analog input.

Hi PaulRB,

Thanks for your response… no, it doesn’t matter what socket a jack is connected to, only need to “detect” the different jack plugs. I say that, but currently, it will change the colour of neo pixel. So there’s 4 sockets, and 4 neopixels… default colour is red, when a jack plug is connected, that relevant LED changes to blue. There’s nothing complex there, although that’s neither here nor there, I can do all that, I was just having some brain freeze thinking about the best way to do it :slight_smile:

So I figure I’ll tie each (x4) Analog input down to GND with a 100k resistor (resulting in a default 0 reading), and then each jack would have a different resistance, such as 1k, 2k, 3k, 10k or what ever.

Yeah, I figured the value wouldn’t be exact, I guess something like

if (reading>=1010 && reading<=1015){ do this } else if … kinda thing should do

Thanks for your help :slight_smile:

jtanner:
no, it doesn't matter what socket a jack is connected to, only need to "detect" the different jack plugs. I say that, but currently, it will change the colour of neo pixel. So there's 4 sockets, and 4 neopixels... default colour is red, when a jack plug is connected, that relevant LED changes to blue.

So you do in fact need to detect which jack is in which socket. My single analog input idea won't work.

So I figure I'll tie each (x4) Analog input down to GND with a 100k resistor

No, don't do that, it's not as safe as what I suggested. Your plan would mean 5V being directly exposed in the sockets. That means a danger of short-circuits. Instead, as I suggested, have the fixed resistor between 5V and the socket and the other connection to the socket is ground.

Also, try to keep the resistors in the ~5K to ~50K range, if using an Arduino like Uno/Nano/Mega. Higher resistances will cause more unstable readings. If you are using an Arduino based on a more modern chip, like samd21 or esp8266, then resistors in the ~50K to ~500K range would be ok.

I know it has been said that consistency is the hobgoblins of small minds but this thread makes me crazy.

I see the terms socket and jack used together to describe a device pair. Makes no sense.

You have plugs (male) and jacks (female).

Or you have you have plugs (male) and sockets (female).

PaulRB:
So you do in fact need to detect which jack is in which socket. My single analog input idea won't work.

Well, only for the LEDs so to speak, but I'm happy enough using individual analog pins - it's a simple enough circuit so there's enough pins.

PaulRB:
No, don't do that, it's not as safe as what I suggested. Your plan would mean 5V being directly exposed in the sockets. That means a danger of short-circuits. Instead, as I suggested, have the fixed resistor between 5V and the socket and the other connection to the socket is ground.

Also, try to keep the resistors in the ~5K to ~50K range, if using an Arduino like Uno/Nano/Mega. Higher resistances will cause more unstable readings. If you are using an Arduino based on a more modern chip, like samd21 or esp8266, then resistors in the ~50K to ~500K range would be ok.

So acting as a pull up so to speak? With the jack then pulling it down via different resistors. My resistor values were purely for example sake, I hadn't thought about best R to use, but will take note of what you've said.

Because it's super simple, I've no need for a SAMD or ESP8266, when a perfectly cheap £3 nano clone will do the job perfectly well :slight_smile:

WattsThat:
I know it has been said that consistency is the hobgoblins of small minds but this thread makes me crazy.

I see the terms socket and jack used together to describe a device pair. Makes no sense.

You have plugs (male) and jacks (female).

Or you have you have plugs (male) and sockets (female).

I know, I know, but I've no idea on the prominent localisation of this forum etc etc, so was using numerous known terms so that all would be able to follow, especially since the plugs are commonly sold as "Jacks" or "Jack plugs" etc ... My apologies :slight_smile:

I still prefer to type "analogue" over "analog" but was chastised elsewhere over that too!
You can't please all of the people, all of the time.

Hi,
To clarify, you have;

  • 4 panel mounted sockets
  • 4 or more line plugs
  • each plug will have a different resistor in it to make it unique.
  • you want to be able to identify any plug used in any socket?

You will be best to use 4 analog inputs, each input having an external pullup resistor, to measure the volt drop across the socket terminals, which will be proportional to the plug resistor value.

For example;
ph_socket.jpgph_plug.jpg
Tom... :slight_smile:

ph_plug.jpg

ph_socket.jpg

TomGeorge:
Hi,
To clarify, you have;

  • 4 panel mounted sockets
  • 4 or more line plugs
  • each plug will have a different resistor in it to make it unique.
  • you want to be able to identify any plug used in any socket?

You will be best to use 4 analog inputs, each input having an external pullup resistor, to measure the volt drop across the socket terminals, which will be proportional to the plug resistor value.

For example;
ph_socket.jpgph_plug.jpg
Tom... :slight_smile:

Yes, exactly that. Yes, my plan was to use 4 of the Analog inputs, all attached to 5v via a high value resistance, and then attach the ground to the one pin on the socket, and the other connects to an Analog input.

Each plug will have a different resistor value

For all intents and purposes, I guess it'll simply be a voltage divider on each of the 4 analog inputs tied up to 5v and grounded through the plug (Edit: Actually, working as an ohmmeter)