How to Use Multiple Analog Sensors on Your ESP8266





Introduction: How to Use Multiple Analog Sensors on Your ESP8266

Hello Everyone!

In this instructable I'm going to show you how to how to use multiple analog sensors with your ESP8266 using a 4051 multiplexer.

Check out the video (2 mins) for a quick run down of what I'll be covering here. I also have an example sketch on how to use the multiplexer on my github.

Step 1: The Problem

As mentioned in the introduction, the ESP8266 only has one analog pin, which can prove to be a problem for some applications.

I've included an image of an analog stick component that is quite common in Arduino sensor packs. The analog stick requires one analog input to measure the movement on the X-axis and a second analog input to measure the movement on the Y-axis. On it's own the ESP8266 can not be used with this sensor.

But fear not, all is not lost....

Step 2: A Solution

There is a couple of different ways to solve problem, and the one I'll be covering here is the 4051 multiplexer, which can be picked up for less than $2 for a pack of 10 on Ebay.

With the 4051 you can connect up to 8 analog devices to the single analog pin on your ESP8266 (It also uses 3 digital pins, which I'll cover in a moment).

Step 3: How It Works

So, how does it work?

It has:

  • 3 select pins, labeled A B and C (These are digital pins)
  • A Common pin
  • 8 option pins (labeled X0 - X7)

Based on the inputs provided to the select pins, a different option pin is connected to the Common pin.

In the first example, I set the option pins to 0 0 0 , which connects Common to X0

In the second example, I set the option pins to 1 1 0, which connects Common to X3

One thing to note is that you don't need to connect up all the select pins if you don't need that many option pins. For example, if I wanted to connect the Analog Stick Component from the first step to the ESP8266, I would only need to move between two of the option pins, which means I only need to connect up one of the select pins (and tie the other select pins to ground).

Step 4: Wiring

Now let's take a look at how to wire the Multiplexer to the ESP8266

Wemos -> 4051

D4 -> S0 (A)

D3 -> S1 (B)

D2 -> S2 (C)

A0 -> Common

3.3v -> VCC

G -> GND

G -> Inhibit

G -> VEE

Then connect whatever Analog sensors are required to the option pins (X0 - X7)

You should now be able run the example from this github page.

Hopefully you find this useful! If you have any questions please let me know.




  • Remote Control Contest 2017

    Remote Control Contest 2017
  • Arduino Contest 2017

    Arduino Contest 2017
  • LED Contest 2017

    LED Contest 2017

We have a be nice policy.
Please be positive and constructive.


Questions & Answers


Have you tested what the current draw is when taking a reading and when nothing is being used on the analog multiplexer? I'm interested to grab one of these for my project but it is battery powered so don't want it to use a lot of power as my esp8266 will be in deep sleep for most of the time

I haven't tested it, as it's ic chip I'm sure it has some current draw but what you could do is use a transistor as a switch to control powering the multiplexer at all, so you could only turn it on when needed. I think that makes the most sense for a project with deep sleep.

Cool instructable. Btw, the 74HCT4067 is a 16 channel version for anyone needing more