Automatically detecting the sensor connected to the arduino

My problem is kinda hard to put into words but I'll try my best to explain. So basically I have a number of sensors which connect to an arduino. I want to be able to automatically detect which sensor has been connected and run the code for the corresponding sensor (using a switch case). It is difficult to identify these sensors uniquely because some of them are plain analog and digital sensors (such as slide potentiometer, proximity sensors, push buttons etc)

My initial idea considering I do not have a lot of available pins on the board is to some how interface all the sensors to the I2C lines. I could use a light color detector connected to the I2C lines and different colored LED on each sensor. Thus, when the sensor is connected and led is lit up I would get a unique reading on the I2C channel

Could anyone suggest a more elegant (and preferable cheaper) solution?

Thanks

Automatically detect just what? And how to do that without burning something up?

If I want self-ID sensors, I’d give each one a controller with the pins and code to run it.

Cheaper and more elegant? Wire the sensors myself, each one to match the app it is for.

If I want self-ID sensors, I'd give each one a controller with the pins and code to run it.

Could you please elaborate? I have four slots wherein i can "fit sensors" (just like a lego block) I have a multitude of sensors and I want to uniquely identify

I have sensors too and not one of them self-identifies nor is there a single circuit that I would hook them all up to because I don't want to burn up my sensors or controllers.

So I would have to put a controller chip with every sensor. And that chip would run the sensor properly and connect and report the data in a standard way, like through I2C or faster.

It would be more expensive and mostly ever unnecessary.

You only have 4 slots? In what?

To do something like that you need to include the code to read every… sensor you have in your sketch.

Next, you’ll need to identify every sensor. You could… equip every sensor with a 1-wire component, since they use unique codes.

Depending on the number of different sensors it can use a lot of programming space though.

Assuming have windows running on your arduino simply create a text file in the root directory of your sensor as follows

[autorun]
open=yourExecutableCodeHere
icon= someicon.ico

Actually, for technical reasons that doesn't work.

anath2: Could you please elaborate? I have four slots wherein i can "fit sensors" (just like a lego block) I have a multitude of sensors and I want to uniquely identify

Perhaps you can elaborate also. What do you mean by "sensor"

In my mind it could be as simple as an LDR or an LM335 temeperature sensor and It is hard to see how they could be swapable and detectable.

On the other hand if your "sensor" is a whole circiuit board it would be easy to have some ID code on it - perhaps set by an 8-way DIP switch.

...R

In my mind it could be as simple as an LDR or an LM335 temeperature sensor and It is hard to see how they could be swapable and detectable.

That is precisely the problem. In fact, I even have a push buttons and potentiometer among the components I want to detect. My idea is to add another IC on my component chips which would notify the arduino with a unique number when I've plug in the component. (I am not sure how to do that or even if it can be done)

To do something like that you need to include the code to read every..... sensor you have in your sketch.Next, you'll need to identify every sensor. You could...... equip every sensor with a 1-wire component, since they use unique codes.

Thanks that's exactly what I plan to do. What kind of 1-wire component should I be looking for?

I think it is easier to make use of a can-bus system. There is a shield for it or you can try make it your own.

Canbus works with two wires and a controller. One wire is high the other is low

Each sensor conected is actually a node on the system it doesnt matter if you just connect 1 sensor or connecting 10 sensors.

Take a look at it

I would do it the way that GoPro identifies the different "backpacks" that can be attached to a GoPro camera. Depending on if it's the LCD screen or the 2nd battery, the GoPro does different things.

It uses an I2C interface to talk to a EEPROM chip inside each backpack. It looks at one specific memory location on that chip to read out an identifier.

Look at a 24LC256 chip. They are very cheap. You will only need two I2C wires (plus ground) to talk to the memory chip and read the ID for your sensor block. You can also program that with your Arduino when you build each sensor block.

anath2: That is precisely the problem. In fact, I even have a push buttons and potentiometer among the components I want to detect. My idea is to add another IC on my component chips which would notify the arduino with a unique number when I've plug in the component. (I am not sure how to do that or even if it can be done)

You would need a controller component that can completely run the sensor it is connected to and communicate on a bus. Then as long as the project did not require any quick couplings and/or tight timings it could have a plug and pray chance of working.

Otherwise you have sensors with different numbers of differently arranged pins that need to be used in different ways, plus whatever it takes to somehow tell the controller what it is (at least 1 more pin) and then whatever pins you do you connect to have to be capable of what is needed which totals into having to waste pins for every sensor to have what's necessary for every sensor.

The way I do it, I am the sensor identifying unit. Also the wiring up unit and a code writing unit. If I need to use 16 buttons I don't need 16 button modules and 80 or more pins because I multiplex the lot on 1 chip. That's 1 controller for at least 16 sensors and having room for more.

I use pins as I see fit and arrange by need and if I need more I may add controllers or shift registers or other means to add resources for my project. I don't need to add another $1 or so to make a 5 cent light detector work.

If you want cheaper by a magnitude or more and more elegant then become a sensor identifier yourself.

anath2: Thanks that's exactly what I plan to do. What kind of 1-wire component should I be looking for?

It doesn't really matter which 1-wire component you use, since all have an unique number.

You could use a DS2401, its only purpose is giving you its unique ID, but you could use an DS18B20 as well, giving you both an unique ID plus temperature sensor.

What you wanted to do is to create an IO 'standard' for all the sensors that you wanted to use. Since every other sensors out there has different requirements (i.e. digitial, analog, specifc bootup, etc, etc), what you need to do is to determine all the sensors that you wanted to ever use, then create a standardizations - which in almost all cases, probably will require several digital addressing bits/pins, some analog (input as well as output) pins, a fixed number of ID pin(s) [# depends on # of different types of sensors you wanted to use], at least 1 or 2 handshake pins, etc.

If you wanted to minimize the number of pins used, you'll then need to make each sensor 'smart' by coupling some sort of controller to it and maybe some additional local circuitry to perform powerup routine, etc.

Won't be easy but if you can get all these done, you basically now have created your own universal plug and play HW components library. If you can then provide the corresponding SW library components, then you can probably start selling these as universal plug and play components.

Good luck though this isn't a simple process to go through.