hi all,
im working with 8 channels mux with arduino, the 8 channels are supposed to connect to 8 sensors.
my question is, i want a trick such that when only one sensor is connected i read and display one sensor data.
i dont want to display somthing like:
when 4 i read and display the 4 sensors ( without reading the unconnected channels) and when i connect 8 sensors i read and display the 8.
is there any trick to do this?
i thought about sometrick to detect eather the sensor is connected or not using a pulldown/up resistor but in my case this is not a solution because 0v could be a reading value not just and empty value. also i could not compare to "0" because of the same reason.
any help please? thanks in advance.
I can think of one, but not sure if would work. Might only work if your sensors are, for example, LDR or thermistors, with a known fixed resistor to form a voltage divider. Where the sensor is missing, the fixed resistor should still need to be present, pulling the mux input to Vcc (not ground). The technique would be to take two readings on each channel. One with the internal pull-up enabled and one without. Reading made with the internal pull-up would not be very accurate, since the internal pull-ups vary from chip to chip, with temperature, supply voltage etc. So you would record the value made without the pull-up enabled. But if the sensor is present, the two readings would be different. If the sensor is missing, the two readings would be the same, or both very close to Vcc.
in my case this is not a solution because 0v could be a reading value
For many analog sensors, such as LDR and thermistors, 0V will not be a reading. This type of sensor never has zero or infinite resistance. If we suppose an LDR has 10R resistance in bright sunlight and 10M resistance in complete darkness, and we use a fixed 10K resistor to make a voltage divider, then the output voltage would be 10/(10000+10)*5=0.005V in bright light and 10000000/(10000000+10000)*5=4.995V in darkness. The ADC readings would never be below 5 or above 1020, unless the sensor was not connected. So that might work.
For any type of sensor where the resistance could be exactly zero, you could place a low value resistor in series with the sensor so that zero can never be a reading unless the sensor is removed.
But why do you need a mux with esp32? Does not not have 8 analog inputs?
@PaulRB thanks for the idea, i need mux because the other pins are busy thats all. @TomGeorge im suppling the 4051 with 3.3v ( the on resistance will be higher compared to 5v)
PaulRB:
But why do you need a mux with esp32? Does not not have 8 analog inputs?
I think it depends on the board you purchase as to how many ADC pins you have.
Basically an ESP32 has available.
Analog to Digital Converter (ADC)
The ESP32 has 18 x 12 bits ADC input channels (while the ESP8266 only has 1x 10 bits ADC). These are the GPIOs that can be used as ADC and respective channels:
yes mr@TomGeorge
i said that the other pins are used. i need a mux this is a must.
my qst is how to read a value only when a sensor is connected.
thanks
one more question Mr @TomGeorge
if i supply the 4051 with external 5v to minimize to Ron, and i connect the grounds together.
this wont cause a problem right ?
also i need external 5 because some sensors operate at 5v. of course ill divide their output.
@PaulRB@TomGeorge
what if my sensor is just a voltage divider. for example a PV panel voltage. somtimes its really 0 (at night).
(this img is just an example not mine)