Help to understand channels in a multiplexer

Hi guys, I'm new in this arduino world, so tehre are many basic things that I still don't understand... and multiplexers are one of this. So, if you can help me whith this problem I'll really aprecciate it!

The thing is, I'm trying to select every channel from an 8-channel multiplexer (74HC4051), and show the values of the potentiometers connected in the serial monitor. I have 8 pots connected in every channel. I'm using the library Mux.h

Everything is fine until channel 3... from channel 4 to 7 the serial monitor repeats the same values than channels 0 to 3, and if a move, for example the pot connected in channel 6, nothing happens.
In other case, if I move the pot connected in channel 0 the monitor shows the same value in channel 0 and 4.

I'm doing this just to understand how I can select the channels of a multiplexer

Any, idea about what is happening? I think is the code, because when I use another code all the pots works fine

my code:

#include <Mux.h>

using namespace admux;




Mux mux(Pin(A0, INPUT, PinType::Analog), Pinset(8, 9, 10));

void setup() {
   Serial.begin(9600);
}

void loop() {
  int ch0 = mux.read(0);
  Serial.print("Canal 0 esta en "); Serial.println(ch0); 
  int ch1 = mux.read(1);
  Serial.print("Canal 1 esta en "); Serial.println(ch1); 
  int ch2 = mux.read(2);
  Serial.print("Canal 2 esta en "); Serial.println(ch2); 
  int ch3 = mux.read(3);
  Serial.print("Canal 3 esta en "); Serial.println(ch3); 
  int ch4 = mux.read(4);
  Serial.print("Canal 4 esta en "); Serial.println(ch4); 
  int ch5 = mux.read(5);
  Serial.print("Canal 5 esta en "); Serial.println(ch5); 
  int ch6 = mux.read(6);
  Serial.print("Canal 6 esta en "); Serial.println(ch6); 
  int ch7 = mux.read(7);
  Serial.print("Canal 7 esta en "); Serial.println(ch7); 
  Serial.println();
  delay(1500);
}

Thanks!

What is different between the code that works and your code?
Paul

1. Try the following circuit (Fig-1) first before using the Mux.h Library in order to be sure that the hardware is operational.

4051x.png


Figure-1:

2. Sample Code

void setup()
{
    Serial.begin(9600);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    ananlogReference(DEFAULT);
}

void loop()

{
     digitalWrite(8, LOW);
     digitalWrite(9, LOW);
     digitalWrite(10, LOW);  //select Ch0 of 4051
     //--------------------------------------------------
     unsigned int y = ananlogRead(A0);    
     Serial.println(y, DEC);                        //0 to 1023
     delay(2000);                                     //2-sec delay between samples
}

3. Upload the Sketch of Step-2.
4. Set the pot at the middle approx.
5. Select Ch0 with a jumper.
6. Check that Serial Monitor shows about 512.
7. Test all the remaining 7 channels by putting appropriate values on DPin-8, 9, 10.
8. Now, test the channels varying the wiper of the pot. Check that Serial Monitor shows: 0 to 1023.

4051x.png

Something seems to be wrong with the third address pin. The one controlled by Arduino Pin 10. Check the connection.

Hi!, I think some pins of the multiplexer were not doing a good conection. I re-solded and it works fine. Thanks for your help!!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.