I'm using a 4051 to mux the only analog pin on a Wemos D1 Mini to read various sensors.
I've hooked up the 4051 Gnd pins directly to Gnd, the control pins to some digital pins and all the 4051 select pins to either an analog sensor or nothing (circuit open). Vcc is connected to the Wemos 3.3 powered by 3 1.2v AAA batteries.
Each minute I read from only 2 of the 4051 inputs (and then go into deep sleep) :
Battery level by connecting the muxed pin to Gnd with a 100K resistor : OK
Ldr sensor with it's resistor : ok-ish
The other pins are open but not parsed in code.
My issue is the ldr output has not the same result as if directly connected to an analog pin. The results are a little bit to high.
I map the output 0-1023 to 0-100% as float.
The mapped result Delta is higher as the value is higher.
Ie: 22%-23%, 85%-100%, (direct analog vs muxed)
Do I need to connect the unused terminals to Gnd even if their not used/called?
Do I need a capacitor somewhere?
I'll provide a fritz diagram this evening if required.
Thank you.
Pandadoudou:
Ldr sensor with it's resistor : ok-ish
Problem is that the WeMos D1 mini has an absolute/voltage A/D, and is not really suitable to measure ratiometric sensors like an LDR. Fluctuating battery power is going to make this (instability) worse.
What are you measuring.
Leo..
Vcc is connected to the Wemos 3.3 powered by 3 1.2v AAA batteries.
That's a confusing thing to say. Are the batteries connected to the 3V3 pin or the 5V pin on the Wemos ?
I think the best way would be to connect the batteries to the 5V pin. The Wemos' regulator would then provide a stable 3.3V, until the battery voltage drops to around 3.5V. Even below that, the Wemos will continue to operate for some time. But during that time the ldr reading will be affected.
You could use a third input on the multiplexor to measure VCC. Then you can compensate for any voltage at VCC, in effect making your sensor ratiometric in software.
I'll provide a fritz diagram this evening if required.
Fritz diagram not required. Schematic diagram is required. You can use Fritzing to make a schematic: just switch to the schematic view and make that look neat & tidy.
I hooked up 3 1.2V NiMh batteries to the 3.3v pin of the Wemos.
I read this method is wasting less energy than using the 5V pin (while allowing to use the batteries to a lower voltage too)
On my first prototype, I had no 4051 so I plugged the LDR directly to the analog pin and using the same powering method.
About the diagrams, I tried the schematics view but I have a hard time making it readable. The cables seems connected whenever they cross (no bridge)
You'll find attached the fritzing file, sorry. (just remove the .txt extension)
Always a good idea to have the sensor - the LDR - going to ground and the pull-up - you have chosen 100k but in this case for a pull-up you should probably use more like 22k - to your 3.3 V supply.
If you want to read your battery voltage, you will want to connect your second 100k to your battery, not ground.
You do not really need to connect the other multiplexer inputs to ground for two reasons. One is that you will not be switching the multiplexer to those inputs anyway. The other is that the voltage divider in the WeMOS is already pulling the analog input to ground.
The risk in connecting three 1.2 V NiMH batteries to the 3.3 V pin is that when charged they will provide not 3.6 V but 4.2 V and exceed the ESP8266 rating.
The risk in connecting three 1.2 V NiMH batteries to the Vin pin is that the regulator will sag when the input is 3.6 V.
You do not really need to connect the other multiplexer inputs to ground for two reasons.
I have found that you do need to connect unused inputs to ground with some makes of multiplexers. This is because of the interference picked up with the floating inputs can cause these pins to oscillate and the cross talk between channels will bleed into the channels you are using. Look up the cross talk figure on the data sheet of the manufacturer you are using. Those can be different and can be inadequate when leaving an input floating.
To be on the safe side I always ground unused multiplexer pins.
The battery mesurment was indeed an error whild retranscripting it in schematics.
I fixed it in attachment.
I don't have much experience with battery powered devices, but I was expecting that using 3x1.2V batteries would give me 3.6V.
I mesured 4.2V with my voltmeter but still tried to power the wemos (since I had a few laying around)
How to limit the voltage to a max of 3.6V ? Something like a Zener diode ? (my electonics knowledge fades a little bit on this side)
The main point of my understanding is that using a 4051 VS not using one is not giving me the same readouts, when powered by the same power source.
I may have to setup another protoboard with the 2 in parallel to ensure the captor is not badly behaving.
That shouldn't have happened. Fritzing checks that your schematic view and you breadboard view are consistent and highlights any connections that don't match between the two diagrams.
PaulRB:
That shouldn't have happened. Fritzing checks that your schematic view and you breadboard view are consistent and highlights any connections that don't match between the two diagrams.
No I mean I misconnected it to GND instead of VCC by memory
Any new idea ?
I managed to find the value is 20% higher than the other prototype.
I updated the method to query the multiplexed to switch pin, wait, then get the value.
It seems to reduce any noise versus switching the pin and polling directly.
I tried to add a 0.1uF capacitor as close as the 4051 between the VCC and GND pin without success.
I tried to add a 4.7uF capacitor between the 3.3V and GND pin without success.
For now I'm only applying a correcting factor of 20% on my data but this is not ideal.
I'll have to buy soon some potentiometer to validate the readouts manually.