Two analogue readings off the one analogue pin

I'm trying to read a wind vane voltage and battery voltage using an ESP8266 (functionally the same as the arduino except there is only 1 analogue pin).
I have the wind vane connected to a digital pin that writes HIGH and LOW to power the windvane resistor. And I have the battery connected with 2 10k resistors and the same analogue pin connected between.

My thought being that I'll be able to do some calibrating and calculating to work out the states of the two systems by the difference between the HIGH and LOW digital pin. Attached is a schematic.

Is this possible?
Without the battery connected to the system it works as planned. An analogue reading based on the windvane resistance on HIGH, a consistent analogue reading of 3-4 when the digitial pin is LOW.

However when the battery is connected I get similar readings when HIGH, but my analogue readings when the digital pin is LOW now change between 70 and 300 depending on the windvane resistance.

EDIT:
I realised when the digital pin is low I am grounding through the windvane instead of through the second battery resistor. I put a 10k resistor between the windvane and D2 which has reduced the variation when D2 is LOW but not eliminated it

Can you update your diagram to include that extra resistor you added, mark all resistors with their values, and give a link to the spec of the wind vane?

Did you know that the analog input on the esp has a fixed 1V reference? This is unlike a regular Arduino analog input's default setting which is to use Vcc as the reference?

The windvane the same as the one featured here (but bought off ebay) Weather Meter Kit - SEN-15901 - SparkFun Electronics

No I wasn't aware that the A0 had a 1V reference. That could explain some of the other funny readings I've had with the A0 pin.

New schematic attached

What is the voltage of this battery.
Is there a regulator between battery and ESP8266.
Is this a "bare" ESP, or one on a board with supporting parts.

I see that this vane switches between 688ohm and 33k.
You could measure that with a ~15k resistor from A0 to ground, and the vane resistor between A0 and VCC.
You maybe could turn the vane on/off by making an IO pin HIGH or INPUT (not LOW).
Don't see yet how you are planning to turn that battery circuit on/off.
Leo..

It's a Node MCU 1.0 ESP8266 powered off the USB uart cable. The battery is an unregulated 18650 battery (and will eventually run the ESP8366, however it isn't in this case). As the battery voltage is more or less constant between readings I thought it would be a matter of finding the battery voltage and then subtracting that from the voltage when the windvane voltage.

Making the digital pin INPUT instead of LOW has made the analogue value constant! I'll have to play around with the values to see if it works but that's a great start thanks!

Not sure if I have understood correctly what you are trying to accomplish.

But... if you require two inputs to share the same single input pin, maybe consider physically switching the input of that pin using a relay, so that when the relay is in state1 it is physically connected to sensor1 and when the relay is in state2 it is physically connected to sensor2.

Maybe that would work? I am not sure of the sample frequency you require, but if it is for weather variables, then this shouldn't have a detrimental effect on the quality of the measured inputs.

Just a thought!

A relay would definitely solve this, but I'm just trying to avoid using a relay as it makes the physical build bigger and a bit more complex and clunky. All variables known I'm hoping that I can calibrate it to work with just a software solution and some resistors

The ESP can measure it's own VCC when the A/D pin is "floating".
Maybe you could disconnect that 15k resistor to ground with a second IO pin.
Leo..

I get what you are trying to do. I would have to build a spreadsheet to help me figure out how to interpret the readings to measure the wind direction and the battery voltage.

My weather station project uses many of the same components and performs the same tasks. Have a look at the link below to see how I built it.

PaulRB:

I get what you are trying to do. I would have to build a spreadsheet to help me figure out how to interpret the readings to measure the wind direction and the battery voltage.

My weather station project uses many of the same components and performs the same tasks. Have a look at the link below to see how I built it.

GitHub - PaulRB/Wemos-Weather-Station: Outdoor Weather Station with Wind Speed, direction &Rainfall sensors

Paul - I read through your GITHub page yesterday, it's awesome... and I am sure to be learning loads from you in the coming days/weeks! My ESP8266's arrive tomorrow.

I've just had success in xCode (1) creating my own totally useless OSx app and (2) creating my own totally useless iOS app.

#NASANext :slight_smile:

Hi Paul, thanks for the link. I can't work out how you got both the readings on the A0 pin though.

Wawa I tried what you suggested, sending the battery GND resistor to an IO pin instead, I think this helped spread out my results on the wind vane pin more.

For anyone playing along. I've done testing at different battery voltages and their is a fairly linear relationship between the battery voltage and the wind vane reading. Attached is a chart with four different readings at each of the 16 directions on the wind vane. I've worked out the equation for each line and can programatically work out the windvane direction once I know the battery voltage. This takes a bit of calculating each time though.

However I'm not convinced the analogue reading is consistent enough. I get an occasional variance with analogue readings and I think I'd need to this to be fairly accurate (especially as the lines draw closer together at high battery voltage and between some of the cardinal points that don't have a big spread between resistance). I should probably do some testing for a while before throwing the idea out, however im less keen on the idea now! Especially because I'll probably have to redo all this calibrating and generation of equations if I change any of the resistors or rebuild the device.

The analog input of the esp in my weather station only measures the battery voltage. The weather vane is connected to an analog input on the tiny85. This is so that the tiny 85 can take the average of many readings over a 15 min period. Meanwhile the esp is in deep sleep. The esp would draw at least 20mA if it were not in deep sleep, which would flatten the battery in a few days. But because it only wakes from deep sleep for 5~10 secs every 15 mins, and the tiny85 consumes only around 0.5mA, the 18650 battery lasts around 12 weeks.