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.


Cool instructable. Btw, the 74HCT4067 is a 16 channel version for anyone needing more
Excellent idea.
Thanks a lot!

About This Instructable




Bio: 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 ... More »
More by witnessmenow:Social Stats Counter Managing Configurations on Your ESP8266 Using WiFiManager Avoid Hard-Coding WiFi Credentials on Your ESP8266 Using the WiFiManager Library 
Add instructable to: