I'm currently using a circuit with 2 separate transistors that can be switched on or off to measure 2 separate voltage inputs.

The reason for this is because I'm using an esp8266 which has only one ADC input at pin A0 and I need to measure light intensity from an LDR as well as voltage from a solar panel.

The LDR is wired with a voltage divider. The voltage input from the solar panel is 0 - 5v, so I have that wired with a voltage divider to output a max of 3.3v (pin A0 is 0 - 3.3v). The problem is that in complete darkness, the ADC is still reading the LDR with a value of around 260 (should be close to zero) and with bright light reading around 850 (should be close to 1023). Also, the voltage measured from the solar panel (divided to 3.3v) is returning anywhere from 600 (0v) to around 840 (3.3v).

I've tried these input measurements separately with expected results. It's having the option to switch inputs is what is tripping me up.

So, is my approach correct or is there another way to do this?

Note: I would have included a circuit diagram if I knew anything about circuits and making diagrams.

  • you can measure resistance quite accurately with a digital pin and some passive components using RC timing. I have a reisistor finder sketch that uses this, as it works better than a voltage divider for identifying unknown values on a large range of ohms, not just ones that work well as voltage dividers when close to the known resistor.... you can also use a plain old relay to switch between two analog inputs. – dandavis Mar 13 '17 at 22:32
  • Could use a multiplexer to switch analog input. You connect one pin to youe esp, and then you can connect 4-16 inputs/output depending on the chip. Use 2-4 control pins to select the pin you want to read/write on. – rpmerf Mar 16 '17 at 11:33
  • Can anyone explain what's up with the down vote? Was my question too detailed? – TheFreddyKilo Mar 16 '17 at 17:36
  • For what it's worth, I solved the problem by simply condensing the range of values with the light and voltage readings in my script along with adding a higher ohm resistor to the base of both transistors. The resolution isn't as high, but still very accurate. – TheFreddyKilo Mar 16 '17 at 17:40

There's two basic solutions, both of which require the addition of an external chip:

  1. Use an analog multiplexer to select the different devices to connect to the ADC input
  2. Use an external (I2C or SPI) ADC chip. These can give you higher resolutions than the internal ADC and many more inputs (depending on the chip you choose).

My recommended solution would be to get an external ADC chip.

  • 1
    Thank you, I'll look into those solutions. So, why wont simple transistors work in this scenario? Isn't a transistor just a switch? – TheFreddyKilo Mar 13 '17 at 20:05
  • 1
    I can be done with transistors but you have to select the right kind of transistors and wire them in the right way. A transistor is not just a switch - certainly a BJT isn't just a switch. – Majenko Mar 13 '17 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.