Arduino DUE

please, i need any help
i has four analog inputs
when i program them ,my data is not correct
but when i program two analog input ,data is correct

arduino is DUE
please any help
MY CODE
/* simple analog in – multiple inputs

  • —————-
    *this takes multiple analog signals and returns their values

*/

int analog0 = A0; // select the input pin for the potentiometer
int analog1 = A1; // select the input pin for the potentiometer
int analog2 = A2; // select the input pin for the potentiometer
int analog3 = A3; // select the input pin for the potentiometer
int analogVal0 = 0; // variable to store the value coming from the sensor
int analogVal1 = 0; // variable to store the value coming from the sensor
int analogVal2 = 0; // variable to store the value coming from the sensor
int analogVal3 = 0; // variable to store the value coming from the sensor

float v1;
float v2;
float v3;
float v4;
//
//float v1_f;
//float v2_f;
//float v3_f;
//float v4_f;
//
//float v1_old;
//float v2_old;
//float v3_old;
//float v4_old;
//float a=0.015;

void setup() {
Serial.begin(9600); // use the serial port to send the values back to the computer
}

void loop() {
analogVal0 = analogRead(analog0); // read the value from the sensor
analogVal1 = analogRead(analog1); // read the value from the sensor
analogVal2 = analogRead(analog2); // read the value from the sensor
analogVal3 = analogRead(analog3); // read the value from the sensor

v1=(3.3analogVal0)/1023;
v2=(3.3
analogVal1)/1023;
v3=(3.3analogVal2)/1023;
v4=(3.3
analogVal3)/1023;

Serial.print(" "); // print the value to the serial port
Serial.print(v1); // print the value to the serial port
Serial.print(" "); // print the value to the serial port
Serial.print(v2); // print the value to the serial port
Serial.print(" "); // print the value to the serial port
Serial.print(" "); // print the value to the serial port
Serial.print(v3); // print the value to the serial port
Serial.print(" "); // print the value to the serial port
Serial.println(v4); // print the value to the serial port
}

That looks pretty simple; no obvious problems.

What else are you doing? How do you know the values are not correct? Can you post a copy of the program which does work?

this is program which is not working or give me wrong data
i measure DATA from 4 LDR

How do you know it's wrong? The LDRs will have some tolerance (some difference) so 4 of them side-by-side won't give exactly the same numbers. If you shade each one individually with your finger, does the corresponding analog value change?

i know from testing LDR BY shadow ,the some values of LDR are not changed

OK, I have read on this forum and in the datasheet that when switching analog channels, you can get a reading from the previous channel instead of the one you think you switched to. The solution is to use two analogRead() in a row and only use the value from the second one.

It shouldn't be necessary as the code inside analogRead() is supposed to do this for you. Give it a try.

analogRead(analog0);
analogVal0 = analogRead(analog0);
analogRead(analog1);
analogVal1 = analogRead(analog1); 
analogRead(analog2); 
analogVal2 = analogRead(analog2); 
analogRead(analog3); 
analogVal3 = analogRead(analog3);

The only other problem might be your wiring. Double-check the value of the pullup resistors, make sure no wires are touching, make sure they're pushed fully into the breadboard.

If your LDR's are in a high impedance state you will get significant error - add a capacitor of about
10nF to 100nF between each analog pin and ground and you'll see correct behaviour.