├── README.md └── Esp8266_4051_Multiplexer.ino /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266-4051-Multiplexer-Example 2 | An example showing how to use a 4051 multiplexer with an esp8266 to connect up to 8 analog sensors. 3 | 4 | Buy the Multiplexers here: 5 | - [Aliexpress](http://s.click.aliexpress.com/e/qzNZrRZ) 6 | - [eBay](https://rover.ebay.com/rover/1/5282-53468-19255-0/1?icep_id=114&ipn=icep&toolid=20004&campid=5338037665&mpre=http%3A%2F%2Fwww.ebay.ie%2Fitm%2F10PCS-IC-MUX-DEMUX-8X1-16DIP-SN74HC4051-74HC4051-NEW-%2F311503477945%3Fhash%3Ditem48870ddcb9%3Ag%3AXIgAAOSwnipWbBG4) 7 | 8 | Buy the ESP8266 here: 9 | - [Wemos d1 mini clone](http://s.click.aliexpress.com/e/uzFUnIe) 10 | - [Wemos d1 mini](https://www.aliexpress.com/item/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/32529101036.html) 11 | - [NodeMCU](http://s.click.aliexpress.com/e/AAyvJiA) 12 | 13 | Wiring: Wemos -> 4051 14 | --------------- 15 | D4 -> S0 (A) 16 | 17 | D3 -> S1 (B) 18 | 19 | D2 -> S2 (C) 20 | 21 | A0 -> Common 22 | 23 | 3.3v -> VCC 24 | 25 | G -> GND 26 | 27 | G -> Inhibit 28 | 29 | G -> VEE 30 | -------------------------------------------------------------------------------- /Esp8266_4051_Multiplexer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ESP8266 4051 Multiplexer by Brian Lough 3 | 4 | An example showing how to use a 4051 multiplexer with an esp8266 5 | to connect up to 8 analog sensors. 6 | 7 | Wiring: 8 | Wemos -> 4051 9 | --------------- 10 | D4 -> S0 (A) 11 | D3 -> S1 (B) 12 | D2 -> S2 (C) 13 | A0 -> Common 14 | 3.3v -> VCC 15 | G -> GND 16 | G -> Inhibit 17 | G -> VEE 18 | 19 | 4051 Option pins are then wired to whatever Analog sensors required 20 | 21 | One thing to note: say for example if you only require 2 analog sensors, 22 | You can just wire up S0(A) and connect S1 & S2 to GND and you will be 23 | able to switch between option 1 and option 2 pins. 24 | Same goes for up to 4 pins (just use S0 & S1) 25 | */ 26 | 27 | #define MUX_A D4 28 | #define MUX_B D3 29 | #define MUX_C D2 30 | 31 | #define ANALOG_INPUT A0 32 | 33 | 34 | void setup() { 35 | //Deifne output pins for Mux 36 | pinMode(MUX_A, OUTPUT); 37 | pinMode(MUX_B, OUTPUT); 38 | pinMode(MUX_C, OUTPUT); 39 | } 40 | 41 | void changeMux(int c, int b, int a) { 42 | digitalWrite(MUX_A, a); 43 | digitalWrite(MUX_B, b); 44 | digitalWrite(MUX_C, c); 45 | } 46 | 47 | void loop() { 48 | float value; 49 | 50 | changeMux(LOW, LOW, LOW); 51 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 0 pin of Mux 52 | 53 | changeMux(LOW, LOW, HIGH); 54 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 1 pin of Mux 55 | 56 | changeMux(LOW, HIGH, LOW); 57 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 2 pin of Mux 58 | 59 | changeMux(LOW, HIGH, HIGH); 60 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 3 pin of Mux 61 | 62 | changeMux(HIGH, LOW, LOW); 63 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 4 pin of Mux 64 | 65 | changeMux(HIGH, LOW, HIGH); 66 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 5 pin of Mux 67 | 68 | changeMux(HIGH, HIGH, LOW); 69 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 6 pin of Mux 70 | 71 | changeMux(HIGH, HIGH, HIGH); 72 | value = analogRead(ANALOG_INPUT); //Value of the sensor connected Option 7 pin of Mux 73 | 74 | } 75 | --------------------------------------------------------------------------------