Hi, Fantastic community here.
I am new to Arduino and electronic, I don't have a great knowledge of coding however the Arduino reference has helped a lot and advice I have found on the forum.
I'm a little confused as to what is occurring when I try to use the multiplexer.
I want to read 8 18650 batteries using the CD4051 rather then use multiple Analog pins.
When I power the CD4051 directly off 5v, an with my multimeter (Fluke 1587) Connected to Com-Out everything works, when I test reading 1 battery on each PIN of the multiplexer the reported values to Serial are correct with some small noise.
example:
874,26,28,26,20,17,11,7,0
869,5,10,20,26,20,18,27,27
873,0,0,0,01,10,24,28
However, If I remove my multimeter from the circuit or switch it off, the reported results in the Serial are no longer correct, battery voltage is correct for the pin its connected, all other results are similar to the batteries reading as if it was connected to all pins.
I found code on the forum from user CrossRoads in regards to reading from 2 multiplexer chips and made adaptions to his code, however I'm failing to see the mistakes I may be making, I would like to read 3 multiplexers in my finished product but I'm struggling to start with 1.
Maybe I'm biting off more then I can chew here, but I thought it may be possible to power the CD4051 from a digital pin so I can turn it on and off when required however this gave me really bad results with 1.8-3.3v coming out the com-out with no battery connected to any gate of the multiplexer, I found when 1 controlPin is HIGH voltage out was 1.8v, then with 2 HIGH 2.8v, when all 3 HIGH 3.3v, this doesn't happen if I power off 5v rail.
//#define mux0 2
#define mux_A 22
#define mux_B 23
#define mux_C 24
byte controlPins[8] = { // PORTA Pins 28-22 AD7-AD0 | 000, 001, 010, 011, 100, 101, 110, 111
B00000111, B00000001, B00000010, B00000011, B00000100, B00000101, B00000110, B00000000};
int muxArray[8];
byte x;
void setup() {
//pinMode (mux0, OUTPUT);
pinMode (mux_A, OUTPUT);
pinMode (mux_B, OUTPUT);
pinMode (mux_C, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (x = 0; x < 8; x = x + 1) {
PORTA = controlPins[x];
//digitalWrite (mux0, HIGH);
delay(100);
muxArray[x] = analogRead(A0);
muxArray[x] = analogRead(A0); // 2 reads to ensure voltage has time to settle thru analog mux
//digitalWrite (mux0, LOW);
}
Serial.println ("values 0 to 7: ");
for (x = 0; x < 8; x = x + 1) {
Serial.println (muxArray[x]);
}
delay(2000); // dumb pause to keep from bombarding the PC too quick
}
Code commented out is what I was trying to use to power multiplexer from digital pin.
I hope someone can give me some tips and points in the right directions.
Thanks, all the best.