Detect if sensor connected to alalog pin?

Is it possible to detect whether a sensor is connected to an analog pin?

If I have a 10k (pull down) resistor connected, and pull the wire to the pin, then I get an analogRead of 0. However, I want to be able to detect whether the sensor / circuit is connected at all.

Reading the analogRead docs:

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

Which suggests that I cannot definitively determine whether something is connected into a pin.

Can anyone confirm my understanding of this?

mike

The sensor has to be able to develop a voltage on the analog pin for the sensor to be detected.

Which suggests that I cannot definitively determine whether something is connected into a pin.

Can anyone confirm my understanding of this?

No you can't directly. However if you use a pull-down resistor of 10k to ground and then wire your sensor to the analog input pin, then any reading higher then 0 would imply that there is a sensor actively connected and supplying the reading obtained.

That make sense?

Lefty

Thanks. I am using a 10k to ground, so I can detect there.

I was hoping there is a way to detect whether anything is connected (so I can give feedback in the user interface).

Im using a photoresistor.

mike

You should be able to write code to measure the fluctuations on the pin and then if the fluctuations on the pin are very low with the sensor connected then you could measure it that way.

Have you tried enabling the internal pull-ups then you would not have any connections external to the board.

Mowcius

Well, if you have a photoresistor hooked up in the "standard" way, you will get a non-zero voltage. With a 10k pulldown and no photoresistor, you will get zero voltage.

Sounds like it should be easy to determine whether or not the photoresistor is hooked up.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

With a 10k pulldown and no photoresistor, you will get zero voltage.

Sounds like it should be easy to determine whether or not the photoresistor is hooked up.

Thanks. I am using a 10k to ground, so I can detect there.

I was hoping there is a way to detect whether anything is connected (so I can give feedback in the user interface).

No comment.

No comment.

Well, im not sure how you felt that comment contributed to the thread, but perhaps you dont understand the question:

3 Wires

Ground +5V pin

Connected with a pull down 10k resistor.

So:

  1. No wires connected : no way to detect if they are connected
  2. Ground Removed : no way to detect
  3. pin removed : no way to detect
  4. +5v removed : can detect (analogRead returns 0).

mike

I'm not sure by your description what your view of the connections are but here is what I think everyone else is thinking:

With R2 gone, you read 0. With R2 there, you don't.

If you have something different in mind, you'll have to let us know graphically. Your textual description isn't making it clear in my mind.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

@ RuggedCircuits

That is the circuit I have.

My question was if there was a way to determine if the circuit was connected correctly.

i.e. perhaps the entire circuit isnt connected at all. I just wanted to confirm that there was not a way for me to detect that.

thanks for the help, and for posting the schematic.

mike

If you enable the internal pullup and take a reading you'll see near 5V if no circuit is connected, but closer to 0 if at least the pulldown is connected, and somewhere half-way if the photoresistor is there.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Thanks. That is useful.

Ill try that out.

mike

@ RuggedCircuits

That is the circuit I have.

My question was if there was a way to determine if the circuit was connected correctly.

That's why I posted "No comment" to his, it was not applicable for what you had asked. You had said you didn't want to do it that way

If you enable the internal pullup

My post 6 back:

Have you tried enabling the internal pull-ups then you would not have any connections external to the board.

Hmm, I would have thought maybe you might have asked about this if you didn't know what it was or how to use it rather than just waiting for someone to spell it all out to you.

Mowcius