Introduction: Multiple Analog Inputs Using One Analoge Pin

Picture of  Multiple Analog Inputs Using One Analoge Pin


In this instructible I will explain how to read values of more than one sensor by using only one analog input pin.

You might wonder why you want to this.

When you are using a Nodemcu board, as illustrated in the picture, only one ADC pin is availible. For a small weather station I would like to read values of multiple analog sensors: a rain sensor and a light intendsity sensor. This is unfortunately not possible with this board.

A solution is to multiplex the sensors. This works as follows: You will turn a sensor A on, read sensor A, then turn sensor A off. After this you will do the same for sensor B.

The idea is based on the instructable of Breagan. As his code was written in LUA I have writen a sketch in C++. This is handy when you are programming your Nodemcu in IDE (the arduino environment). For ease I tested the sketch and wiring on the arduino UNO/duamilanove.

please see also the intructable where I used this technique!

Step 1: Wiring

Picture of Wiring

For this project you need the following:

  • Two 10K ohm potentiometers;
  • Two diodes;
  • One 10K ohm resistor;
  • Arduino;
  • Broadboard;
  • Some wires.


  • Connect one side pin of each potentiometer to ground;
  • Connect the other side pin of potentiometer A to pin 10 of the arduino;
  • Connect the other side pin of potentiometer B to pin 11 of the arduino;
  • Connect the pin in the middle of both potentiometers via a diode to the analog pin 0;
  • Add a pull down resistor (10K ohm) between the ground and the analog pin 0.

The potentiometers do have the same characteristics as analog sensors and are easy to use for testing. The diodes are the key for isolating the sensor circuits. Diodes restrict current to only one direction. Without diodes the sensors still work, however they interact with each other.

Step 2: Coding

Picture of Coding

In order to multiplex, only one sensor can have a complete circuit at a time. By setting the the GPIO pin 10 to HIGH, we are sending 5v to sensor A and completing the circuit. The other pin (GPIO11) is being set to LOW and is therefor sensor B is turned off.

The sketch will read both values and print a value between 0 and 1023 in the serial monitor. You can open the monitor in the IDE software by pressing CNTRL+M.

As one can see in the illustration above the first potentiometer (A) is fully open while the second one is closed. After this potentiometer A is slowly closed until both values approach zero. After this potentiometer B is fully opened.

Have fun trying this out!



Fo2sH828 (author)2017-09-12

you really saved my life !!

but node MCU supply 3v , what if a sensor usess 5v ?

NutellaF (author)Fo2sH8282017-11-25

Edit, the last technic with only the power supply defeats the purpose of this instructables

NutellaF (author)Fo2sH8282017-11-24

You can either have a transistor in a switch configuration to switch higher voltages with only 3.3V (or less) needed to activate, or you take the easier way and buy a 3.3V to 5V step-up converter. What you can also try is just to have an external 5v power supply connected to the sensor and just have the Output wires connected to the nodemcu, but remember to connect ground of the power supply to that of the nodemcu.

A.i'm same ask too. pleasure help me

ReviandiNaufal (author)2017-07-08

if i use other diodes, not the 1A 50V diodes, would it still work?

PatipolT (author)2017-05-14

Please give me the suggestions.
1. Would it work if I connect the pin in the middle of both analog sensors directly to the analog pin 0 without a diode?
2. Would it be possible to use other resistor rather than 10K ohm for the pull down resistor? What will happen?
Thank you.

CraigT60 (author)PatipolT2017-06-13

Or you could just buy a quad ADC and use it for four inputs, no multiplexing needed. After researching this today I picked up a quad ADC from Aliexpress for $2.25. Just search for ADS1115 for 16 bit and ADS1105 for 12 bit. You can read the channels with I2C.

CraigT60 (author)PatipolT2017-06-13

Without the diodes you'd have both sensors in the circuit at the same time, and the one powered down could be shorting the output of the other to ground.

PatipolT (author)CraigT602017-06-13

Thank you for your reply.
Is that means sensor values would be unreliable?

CraigT60 (author)2017-06-13

Yes. The output would be influenced by both sensors.

Since diodes have a drop across them that varies by current, for more accurate readings you'd be better off using a multiplexer chip. You can get 8x1 and dual 4x1 multiplexers for a dollar or less.

Raphango (author)2016-05-26

Great ible!

The only problem in using diodes is that you have a voltage drop, so you have to offset this to get a correct read.

BTW, you could add this idea to your ible: Get multiple button presses in a single analog port, like this video:

All the four buttons are linked to a single ATTiny85 AnalogIn, due to the lack of sufficient DigitalIO to the circuit.

Raphango (author)Raphango2016-05-26

Forgot to mention that the different reads are get through different resistor values attached to the buttons.

Ingenerare (author)Raphango2016-05-26

Hi raphango, yes I did read anything about this drop in voltage but I do not realy understand why it occurs. I will relook to it by this evening. btw, untill now the sensors work perfectly (as you can see on the Thingspeak channel). This is partly because the particular data I ask does not have to be very accurate (day light and rain).

I read before about using multiple buttons using one analog pin. This principle (with different resistor values) scan also be used for reading data of multiple sensors. The only thing you have to know is in which range the sensor throws out his data .

CraigT60 (author)Ingenerare2017-06-13

There's a voltage drop across diodes because diodes have resistance (and capacitance, but that's another story). The drop depends on the current passing through the diode.

Diodes aren't really one-way valves that are totally closed in one direction and totally open in the other, although in most applications we can use them that way, as long as we stay within their specifications.

Raphango (author)Ingenerare2016-06-01

Thats it! =)

Maharaja409 (author)2017-04-25

I need to interface 3 ct sensors to NodeMCU-WiFi-Arduino-IDE-Lua-based-IoT-ESP8266-Development Board. how can I on or off ct sensor.

Cgiff (author)2016-11-04

Ingenerare/ Great innovative post. Adding a little complexity, a 4 to 16 line decoder 74hc154 could also be added to free up other IO, using your suggested technique. Also some 4016 's on the input directly as analog switches could also be used. Thanks for this great instructable.

NeilM113 (author)2016-09-18

Thanks for the instructible! Does this mean that I could essentially have a large number (say >15) analog sensors that I could read sequentially? I would just need 15 diodes, in that case. I guess I'm only limited to the number of digital pins if it works for any number of sensors?

Ingenerare (author)NeilM1132016-09-20

Yes, you are absolutly right. You are limited by the number of I/O pins. You need a diode for each of the I/O pions

jescobar10 (author)2016-06-29

Alguien me puede apoyar ? hacer lectura analogica con el esp8266 e imprimirlo en un servidor web con arduino ide

tstauch (author)2016-06-05

Great post, thank you! We will be using this with kids building smart-things, and adding multiple analog inputs to the ESP8266 is essential.

Well done!

Ingenerare (author)2016-05-25

Please check also my other intstructable where I used this technique!

AmCoder (author)2016-05-16

:-) cool

Ingenerare (author)AmCoder2016-05-21

Thanks all for the great response!

dadlovespi (author)2016-05-12

Thank you very much for making this Arduino ide compatible. You saved me lots of time and effort. I should be able work my battery voltage monitor circuit( currently on A0) in there somewhere. Well done.

Akin Yildiz (author)2016-04-23

you are a life saver :) this is a very important post.. thank you for sharing.!!!

About This Instructable



Bio: The term, engineering originates from the Latin word Ingenerare, which means "to create". My name is Vincent and I am a graduating student in the ... More »
More by Ingenerare:Turn me on, an ATtiny RGB mood lampEasy IoT Weather Station With Multiple Sensors Multiple analog inputs using one analoge pin
Add instructable to: