How to Use Multiple Analog Sensors on Your ESP8266

Introduction: How to Use Multiple Analog Sensors on Your ESP8266

About: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into Arduino development after discovering the esp8266 chip, a WiFi enab...

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.


Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    7 Discussions


    Question 9 months ago on Step 4

    Can we connect 8 IR sensors to it and get real time data from all simultaneously?


    Question 1 year ago on Step 4

    Hello, I am running out of available digital pins on the esp8266 to use, so how do I interface an LCD and an rfid reader to the esp8266 using multiplexer


    2 years ago

    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


    Reply 2 years ago

    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.


    3 years ago

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


    3 years ago

    Excellent idea.


    Reply 3 years ago

    Thanks a lot!