Attached you can see the code and the setup of my arduino and 16 channel analog multiplexer.
Currently, I am attaching only 4 LDRs, but my goal is to have 12 LDRs and receive their values on the serial monitor of arduino(so only have them as inputs). Then these values will be taken to MAX MSP to have audio as output.
I am having a problem getting the right values on serial monitor. Can anyone help me to spot the mistake?
Thank you for your time. Any help is much appreciated!! Been reading many forums and tutorials but feeling very stuck.
Best,
Ilayda
//16 channels analog multiplexer
//Pinout
// S0 -> Arduino Digital 8
// S1 -> Arduino Digital 9
// S2 -> Arduino Digital 10
// S3 -> Arduino Digital 11
// E -> Ardunio Digital GND
// Z -> Arduino Analog A0
// VEE/ GND -> Arduino GND
// VCC -> Arduino + 5V
// Y0 to Y15 -> Analog Extended Pins
//#define S0 D8
//#define S1 D9
//#define S2 D10
//#define S3 D11
//#define Z A0
int valY0; // Assign the name sensorPinA0 as analog output value from channel Y0
int valY1;
int valY2;
int valY3;
int sensePin = A0;
//Variables
int value; //store value from photoresistor (0-1023)
void setup() {
DDRB = 255;
Serial.begin(9600);
pinMode(valY0, INPUT); // set sensorPinA0- as in input
pinMode(valY1, INPUT); //set sensorPinA1 - as an input
pinMode(valY2, INPUT); //set sensorPinA1 - as an input
pinMode(valY3, INPUT); //set sensorPinA1 - as an input
}
void loop() {
PORTB = B00000000;
valY0 = analogRead(sensePin);
PORTB = B00000001;
valY1 = analogRead(sensePin);
PORTB = B00000010;
valY2 = analogRead(sensePin);
PORTB = B00000011;
valY3 = analogRead(sensePin);
Serial.print("Channel0 = ");
Serial.println(valY0);
Serial.print("Channel1 = ");
Serial.println(valY1);
Serial.print("Channel2 = ");
Serial.println(valY2);
Serial.print("Channel3 = ");
Serial.println(valY3);
Serial.println(" ");
delay(500); //delay
pinMode(valY0, INPUT); // set sensorPinA0- as in input
pinMode(valY1, INPUT); //set sensorPinA1 - as an input
pinMode(valY2, INPUT); //set sensorPinA1 - as an input
pinMode(valY3, INPUT); //set sensorPinA1 - as an input
Each one of those sets pin zero to be an INPUT.
I don't know why you are doing that
Uncompiled, untested
//16 channels analog multiplexer
//Pinout
// S0 -> Arduino Digital 8
// S1 -> Arduino Digital 9
// S2 -> Arduino Digital 10
// S3 -> Arduino Digital 11
// E -> Ardunio GND
// Z -> Arduino Analog A0
// VEE/ GND -> Arduino GND
// VCC -> Arduino + 5V
// Y0 to Y15 -> Analog Extended Pins
const byte sensePin = A0;
void setup()
{
DDRB = 255;
Serial.begin(9600);
}
void loop()
{
int valY [4];
for (byte i = 0; i < 4; i++) {
PORTB = i;
(void)analogRead(sensePin); // discard the first reading
valY [i] = analogRead(sensePin);
}
for (byte i = 0; i < 4; i++) {
Serial.print(F("Channel"));
Serial.print (i);
Serial.print(F(" = "));
Serial.println(valY [i]);
}
Serial.println();
delay(500);
}
The code is compiled but still getting random values. I was trying to get channel values from A0 pin that's why... But I am sure that it was a wrongful thinking.
//Oh yes okay, let me solder and try it again with this new code.
//and thanks again- just connected it!!