Hello! This is my first time in the forum. I would like to know if there is some way for detecting the high impedance state by arduino software. I mean, when we use digitalRead() in unconnected pin we get HIGH or LOW randomly, I do not know if it exists some flag in the Atmega328P or whatever that let me to know that. I am looking for it because I am interested in the detection of unconnected pins. Thanks
davidpinol: I am looking for it because I am interested in the detection of unconnected pins.
Why do you need to detect unconnected pins?
If you write the code and otherwise design the system won't you know without testing anything?
You could use INPUT_PULLUP on all unused pins to ensure a stable value from digitalRead().
Basically there is not a flag or anything else that will tell you if an input is floating. It reads just like a solid input but can flap about.
You can do fancy tricks like turning the pins either side of the target pin into outputs and driving them up and down and seeing if the target pin changes but it is not very reliable.
If you need to detect unconnected pins you will have to go about it another way like using a jack plug with a switchin it.
This is called the “XY problem”.
Whilst we can pontificate and discuss all sorts of ways to determine whether the pin is connected to anything, we know this is not the real problem.
It is almost certain that you know what it is that might or might not be connected to this pin, so if you “fess up” and tell us what it is, we can give you much more sensible advice on how to manage it.
Sorry, I can see that I have not explained very well my problem, the X problem. I just want to know how to detect if someone cut the cables of the sensor conected to the nano arduino board by software or hardware. I men, I have a sensor hall conected, three pins: 5v, ground and signal conected to the board, and someone cut some of these three cables or all of them and i want to active an alarm. I hope you understand me now. Thanks anyway for your answers.
That is not actually telling us what sensor you have, what signal it normally puts out nor why you think some one will cut a wire. Is this a burglar alarm? As I said before there is nothing directly that you can do.
It is a A3144 sensor hall, and is for a burglar alarm. I see that there is nothing I can do. I have not found anything in the Datasheet of Atmega328P about it.
So a hall effect sensor.
Sure, there are things you can do. Connect another pin through something like a 1M ohm resistor. Toggle that pin up and down. If the hall effect sensor is still in circuit, there should be no effect.
But if the wire has been cut, the pin connected to the sensor will toggle up and down along with the other pin.
Connect a weak-ish pull-up/down resistor on the pin. If the reading moves outside the normal operating range, someone is tampering with the circuit or sensor.
This may help.
The best way is to have some intelligence at the sensor. The master sends out a request for status, with a seed. The sensor replies with data that is scrambled with the seed. No sensor, no reply. How secure are you talking about? Dwight