(first post, be gentle =P)
**My problem: **
I have an ATMega2560 where I have attached DHT11 sensor(s). I want my software to detect if the sensor is attached to one of the "approved" digital pins (approved = the pins I've specified in my code, in this case either d-pins 51-54, for a max of 4 possible DHT11 sensors). For my project, it doesn't matter if zero or all four sensors are plugged in, it's dynamic. I do not need to detect what type of sensor - I don't really care only because I assume that there isn't a good way to detect a DHT11 from something else. If there is a way to detect the type of sensor that's a game changer for me, but my research says it's not possible.
I'm using this sensor-detection to drive my TFT screen for displaying a "UI Widget" that shows the sensors values. If 4 sensors are plugged in, I'm going to show 4 widgets. If 1 sensor, then only show 1 widget.
**What I've tried: **
My thoughts were to use digitalRead()
. It seems to work in that the simple detection of a "0" (for when no sensor is plugged in) and "1" (for when a sensor is plugged in) is enough for my purposes. I'm just nervous about moving forward with this as I don't know the consequences, risks, or 'gotchas'.
My question:
If not what I'm currently (planning on) doing, what's a good way to detect if "something/anything" is plugged in and using the digital pins? Is what I'm doing 'approved'/safe/a good idea?
What I've read/researched so far:
-
Detect if sensor connected to alalog pin? - Interfacing - Arduino Forum - but this has to do with analog pins and pull down resistors. I'm thinking I don't need that based on my digitalRead() proposal.
-
arduino nano - How can I detect a disconnected pin? - Arduino Stack Exchange - but this was honestly a bit over my head/experience so my eyes glazed over.
Thank you in advance and glad to join the forum/community.