4051 with paired y-pins

Hi Everyone

I’m trying to get familiar with multiplexing, and I’ve been following this tutorial by Götz Müller-Dürholt (it’s in German, so I might have missed a few points).

http://goetzmd.de/hardware/mehr-analoge-inputs-fuer-arduino-ic-4051-tutorial-midi-controller-selber-bauen-teil-10

I’ve copied his circuit and code, though I’ve renamed some variables and added some more info to the serial print for the sake of comparing HIGH and LOW select pins with Y-pins and returned values.

But it’s not working quite as it should.

The values returned are stable, but I’m getting duplicate readings on pin (=count) 0 and 1, on pin 2 and 3 and on pin 4 and 5 (if I connect one pot to Y3, I’m getting a duplicate reading on pin 6 and 7). Teoretically I should just get three different reading on pin 0, 1 and 2 and pin 3, 4, 5, 6 and 7 should return “0”, since nothing is connected to them.

If I turn my pots fast, the serial monitor shows that the values on the “paired” y-pins is infact individual and not just “mirrored”, because the values changes in steps, but its pretty clear that the second pin in the pair gets it’s value from the same pot as the first pin in the pair. I hope this makes sense, if not, please see the attachement with some read outs boxed in.

There’s more :slight_smile: If I connect any pot to Y4, Y5, Y6 or Y7, it doesn’t affect the read outs at all. It’s like Y4 - 7 doesn’t excist.

I’m using Arduino Uno and the multiplexer is a CD4051BE, so it should be pretty straight forward, but I’m lost. Any help would be appreciated :slight_smile:

int Val = 0;
int count = 0;

int bit1 = 0;
int bit2 = 0;
int bit3 = 0;

void setup() {
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 Serial.begin(9600);
}

void loop () {
 for ( count = 0 ; count <= 7; count++ ) {

  bit1 = bitRead(count, 0);
  bit2 = bitRead(count, 1);
  bit3 = bitRead(count, 2);

  digitalWrite(2, bit1);
  digitalWrite(3, bit2);
  digitalWrite(4, bit3);

Val = analogRead(A0);
 
  Serial.print(bit1);
  Serial.print(bit2);
  Serial.print(bit3);
  Serial.print(" ");
  Serial.print("=");
  Serial.print(" ");
  Serial.print("Y");
  Serial.print(count);
  Serial.print(": ");
  Serial.print(Val);
  Serial.print("\t");
 } 
 Serial.println("");

}

13b1668aa14281c48d5b8e8dffc84e86fa35e394.jpg
e5ddaa9ca8dabbbdb26837e2b985bae9be02a408.jpg

Hello Anders,

This sounds like wiring problems. Did you ground all the unused inputs? Because of the “pairing” of inputs, you should check carefully the connection from pin 2 to the 4051.

Paul

and pin 3, 4, 5, 6 and 7 should return "0", since nothing is connected to them.

No. When nothing is connected to a pin the value is not 0 but a floating value which can be anything. It sounds like you are picking up signals from the other channels. In digital electronics you should never leave inputs unconnected.

Thank you both for your responses.

Grumpy_Mike: No. When nothing is connected to a pin the value is not 0 but a floating value which can be anything. It sounds like you are picking up signals from the other channels. In digital electronics you should never leave inputs unconnected.

Please escuse my poor choice of words :) What I meant was, that these pin have no sensors (pots) connected to them. They're all tied to ground. The tutorial I followed suggests to connect them through a 10K resistor, both that and directly to ground produce the same result.

I'll try to rebuild the entire circuit step by step. Maybe I did connect something wrong, that I can't pin point with everything is connected.

Thanks again :)

If you still have problems you need to post the schematic and a photo clearly showing your wiring. Don't bother posting a physical layout diagram.

Hi Again :)

The rebuild helped. It turned out that I had my "select pins" wired wrong. Instead of having them on digital pin 2,3 and 4 they were on 3, 4 and 5, so even when the code was sending out:

000, 100, 010, 110, 001, 101, 011 and 111

on pins 2, 3 and 4, the 4051 only recieved:

000, 000, 010, 010, 001, 001, 011 and 011.

Makes sense! :)

Thanks for the help.