toggle between 2 sensors i want to read from

Hello,

Let’s say I want to connect a potentiometer and a LDR to 1 analog pin, and choose which of them I want to read with a toggle switch. Is this the way it should be done?

Thanks!

Edit: the pot is supposed to be a 10k of course, not 100k.

Yes, that should work - have you run out of analog inputs then?

Thanks. I want to build a MIDI controller and connect lots of inputs and switch between them in a live situation…

One option for that is an anlog multiplexer chip - a 16 to 1 analog multiplexor takes 1 analog pin and 4 digital pins to provide access to 16 signals...

Interesting. I might need these digital pins for something else but I’ll keep that in mind. :slight_smile:

Instead of 5V you could connect the LDR and the potmeter to a digital pin. If the pin is set HIGH the appropiate device gets 5V. With an inverter you need only 1 pin.

robtillaart: Instead of 5V you could connect the LDR and the potmeter to a digital pin. If the pin is set HIGH the appropiate device gets 5V. With an inverter you need only 1 pin.

What's the problem with using the 5V?

yan_g:

robtillaart: Instead of 5V you could connect the LDR and the potmeter to a digital pin. If the pin is set HIGH the appropiate device gets 5V. With an inverter you need only 1 pin.

What's the problem with using the 5V?

I think what he's trying to say is rather than using a switch to flip between the two sources, you power one or the other using a digital pin (each resistance would have its own digital pin). Alternatively, you could use a single digital pin hooked to one of the sensors, and use an inverter IC to connect to the other from the same pin - so when you brought the pin HIGH, only one of the devices would be selected, bring it LOW, and the other would be selected).

That's what I understood, but as a noob I can deal with switches more easily than with ICs :) It's nice to know though, makes me think of new ideas, thanks. For instance, I could use a tact switch to toggle between the two, and power an LED in front of the LDR in the same time.