I am currently working on a project where I need to be able to attach multie sensors to my board (Arduino Unu), that part is very simple. But in order to get thearduino board to read the sensor input I need to hard code the analog pin and how it reads the pin. I want to have multie sensors and be able to plug then into any analog slot I want and then have the arduino figure out if there is a sensor and what kind of sensor.
Is there ANY way to do this? Any help is appreciated.
I think you only hope of such a capability is if the analog sensors each have readings which separate into different parts of the 0 - 5v. analog input range. Then the Arduino could distinguish them by taking a first reading and distinguishing its range.
If these are all meant to work in the 5 v. range, perhaps you could build a little transistor (or opamp) amplifier front end for each which crunches their ranges to distinct parts of the full range. But then of course, you are losing some of the resolution of each sensor.
Its not completely needed. But for what I would like to do I would like a very modular system, so in one you could put 3 temperature sensors into the first 3 slots and the 2 humitity sesnsors in the last 2. But if you changed your mind and wanted to replace one of the temperature sensors with say a moisture sensor, I would like if I could do that without changing the code. I have everything figured out but the part of scanning the analog ports and finding out if there is a sensor and what kind.
Technically speaking I could hook the sensor up to another board and have that board send specialized data to the sensor. But that is not very practical and more inportantly, not very cost effective.
I can't think of a way to use the analog inputs in such a way. But that comes back to I2C. Each slave has its own address, so you can plug it anywhere along the network, and it will be recognized.
As far as I know, you can't do that with multiple analog inputs.
Analogue sensors need calibrating (code) to be accurate.
Therefore you can't just swap e.g one 10k NTC for another 10k NTC.
Not if you want accurate temp measurements.
If there is a sensor connected, that's the easy part. Enable the internal pull-up resistor, or use an external high value resistor to VCC or ground.
Any unused pin will read 1023 or 0.
Which sensor is connected...?
You could use port expanders to add as many analogue ports as you want.
Leo..
I assume your sensors are all analogue and to be powered from your Arduino's power supply; so you will require three pins: ground, Vcc and analogue signal.
Use a connector with more pins such as a 5-pin DIN connector. Use the extra two pins to indicate which type of sensor is plugged in. Connect the two extra pins from each socket to Arduino digital inputs with pull-up resistors enabled in software (if you have insufficient digital inputs use multiplexing). For a temperature sensor leave both extra pins disconnected but for a humidity sensor connect one pin to earth (this can be done within the plug). For a pressure sensor (say) connect the other extra pin to earth and for a light sensor (say) connect both pins to earth.
If you have more than four types of sensors, or wish to identify individual sensors for calibration reasons, use connectors with more pins such as a 9-pin D-type.