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.
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.
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.
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.
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.
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.