using Array

hello everyone, in this project i'm using 5 different soil sensors and i'm using two different arrays. one for sensors pins and the other for sensor level.The output of the program is random number of 0 and 1.
need help.

const int sensors[5]={0,1,2,3,4};
int sensorvalue[5];
int i,j;
void setup() {
 Serial.begin (9600);
for(i=0;i<5;i++){
 pinMode(sensors[i],INPUT);
}
}

void loop() {
  for (i=0;i<5;i++,j++){
   sensorvalue[j]=digitalRead(sensors[i]);
   Serial.println(sensorvalue[j]);
   delay(500);
    }
  }

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (the italics in your code, for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:

[code]

[color=blue]// your code is here[/color]

[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please explain exactly what you need help with.

You have to use the twoo arrays in the same way, or better you have to call every element like arrayname [elementnumber] one is used well, but not the other

Is your code really in italics or did you not read this before posting a programming question ?

 for(i=0;i<6;i++){
  pinMode(sensors[i],INPUT);
 }

How many sensors do you have and what are the index numbers of them in the array ?

UKHeliBob:
Is your code really in italics or did you not read this before posting a programming question ?

 for(i=0;i<6;i++){

pinMode(sensors[i],INPUT);
}




How many sensors do you have and what are the index numbers of them in the array ?

5 sesnors and index

...and now the original has been edited, and the later comments make no sense.

AWOL:
...and now the original has been edited, and the later comments make no sense.

So it has.

I'm out

If you really want to study OP's program you need to collect from 5 threads across 4 forums beginning in May.

AWOL:
...and now the original has been edited, and the later comments make no sense.

the output still the same which is random zeros and ones.

Hello everyone, in this project i'm using 5 different soil sensors and i'm using two different arrays. one for sensors pins and the other for sensor level.The output of the program is random number of 0 and 1.
need help.

const int sensors[]={0,1,2,3,4};
int sensorvalue[5];
 int i,j;
void setup() {
  Serial.begin (9600);
 for(i=0;i<5;i++){
  pinMode(sensors[i],INPUT);
 }
}
 
void loop() {
   for (i=0;i<5;i++){
    sensorvalue[i]=digitalRead(sensors[i]);
    Serial.println(sensorvalue[i]);
    delay(500);
     }
   }

https://forum.arduino.cc/index.php?topic=563532.0

/*
The code can't compile, I se a i insteed a j.
*/
And if you have 5 sensors you have to use numbers from 0 to 5, not to 4.
How can you know that the output isn't correct? Test property the corrent/tension, decause the digitalRead is the right function (if the sensors are digital and not analogical)

Silente:
And if you have 5 sensors you have to use numbers from 0 to 5, not to 4.

0 to 5 would be six numbers. That would be one too many for 5 sensors.

Your original example used analogRead. analogRead will output a number from 0 to 1023. Your current code appears to use digitalRead. digitalRead outputs a 0 or a 1.

I'd suggest you read up here on the difference between analog and digital.