Go Down

Topic: bitRead() on multiplexer 74HC4051 giving double value? (Read 62 times) previous topic - next topic

murkertrer


So, I'm very new to all of this, and I'm trying to get the 4HC4051 working. It's kind of happening, but the problem is that it is reading the pin twice in each round.

I'm only conecting a single pin to a photoresistor and it is reading it twice>

614,0,0,0,614,0,0,0

Instead of

614,0,0,0,0,0,0,0

I figure that the problem must be the way that the code of the bitRead is set up.

Perhaps, someone with experience can help me out adress this mistery?

Code: [Select]



int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)

int s0 = 2;
int s1 = 3;
int s2 = 4;
int count = 0;   //which y pin we are selecting

int inPin = A7;

void setup(){ 
 
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  Serial.begin(9600);
}


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

    r0 = bitRead(count,0);    // use this with arduino 0013 (and newer versions)     
    r1 = bitRead(count,1);    // use this with arduino 0013 (and newer versions)     
    r2 = bitRead(count,2);    // use this with arduino 0013 (and newer versions)
     
    digitalWrite(s0, r0);
    digitalWrite(s1, r1);
    digitalWrite(s2, r2);

    int red;
    red = analogRead(inPin);

    if(count == 7) {
      Serial.println(red);
    } else {
      Serial.print(red);
      Serial.print(",");
    }
  } 
}


Grumpy_Mike

#1
Nov 14, 2017, 09:22 am Last Edit: Nov 14, 2017, 09:23 am by Grumpy_Mike
Quote
I figure that the problem must be the way that the code of the bitRead is set up.
No.

Looks like pin 4 is not connected correctly to the chip.
post your schematic and a photo of the wiring.

Go Up