Go Down

Topic: 4051 Multiplexer example code? (Read 17209 times) previous topic - next topic


I will try the things you mentioned, and I'll let you know how it goes.

Thanks very much for all your help!


Apr 14, 2009, 03:38 pm Last Edit: Apr 14, 2009, 03:46 pm by tep Reason: 1
I'm interested, because I want to use this mux, but the sample code doesn't seem very complete... can you tell me how it works now and your current code?



Just in case anyone reading this needs more analog inputs, I thought I'd pass on a hint that I gleaned from the BeatBearing project in Make (Volume 17):


That device uses a HEF4067B analog multiplexer with 16 inputs.  It's a Philips (now NXP) part:


Has anyone used this chip in a similar circuit to the 4051 setup?


Yes : http://fluidforms.eu/de/CassiusHow.php


I don't get any of this...
I want to read 25 LDR's but first I can't get it to read anything.

Here is how it is wired:

Code: [Select]

5V - LDR -|y0   s0|-  D5
         |y1   s1|-  D6
         |y2   s2|-  D7
         |y3     |
         |y4     |
         |y5     |
         |y6     |
         |y7    z|-  analogInPin

What am I doing wrong? And what is the correct code to read the inputs?


Jan 08, 2010, 10:08 pm Last Edit: Jan 08, 2010, 10:10 pm by evolutionxbox Reason: 1
My previous post was completely wrong... following the arduino page I got this wiring:

with my own code:

Code: [Select]
int led = 11;    //just a led
int analogIn = 0;
float analogValue;

void setup() {
 pinMode(2, OUTPUT);    // s0
 pinMode(3, OUTPUT);    // s1
 pinMode(4, OUTPUT);    // s2

void loop () {
 digitalWrite(2, LOW);
 digitalWrite(3, HIGH);
 digitalWrite(4, HIGH);
 analogValue = analogRead(analogIn);
 analogValue = map(analogValue, 0, 1023, 255, 0);
 analogWrite(led, analogValue);

It works!
(If you are not sure about what pins are where it is the same way up as the playground image.)


Hey guys, I'm using a couple of 4051's. Just wanted to be sure . . the 4051 GND,Vss,Vee and INH goes to the analog ground and so do the 5V pin of Arduino. Right? does it matter if I connect it to the digital ground of Arduino? Thanks ..


Check this:


Pins 6, 7 and 8 to ground

Connecting Arduinos 5V pin to ground sounds like a seriously poor idea.


i have a question about the 4051....

if i have 8 pots and run them thru the mux they go into the arduino via a single analog input pin ..... i got that much clear...

but what if i need each one of those pots to feed into 8 separate variables?

currently im doing something like this (not using a mux yet)

int pot1pin=1;
analogRead (pot1pin);

so how would this type of thing work with a mux?.... is it even possible to assign individual vars to each of the 8 pots?

thanks for the help



First you tell the 4051 which of it's inputs should be connected to it's output, then you use analogread. repeat 8 times. with 8 different variables.


Jul 08, 2010, 02:03 pm Last Edit: Jul 08, 2010, 02:03 pm by Grumpy_Mike Reason: 1
repeat 8 times. with 8 different variables.

Or the same variable as an array and just increment the array index.

like here:-

Go Up