I'm working on a project that finding out the soil moisture affect the voltage output vs the distance. And I want to turn on my sensor with c4 combination to investigate distance effect. For instance, for the first 20s, turn on sensor1 and read 100 numbers and next turn on sensor2 and read 100 numbers then continue 12,13,14,23,24,34,123,124,234,134,1234 combination.
The sensor is soil moisture sensor with three connections, one for power supply, which is 5V, one ground, one a serial output which is connected to A1, A2, A3, A4 to read out the outputs from four sensors.
Right now I find out I wrote a fake c4 code that, read outputs as required but actually all 4 sensors are turned on. Cause all four sensors are connected to the 5V power supply of the Arduino board.
Can anyone give me some idea how to power them by code?
void setup() {
Serial.begin(9600); // open serial port, set the baud rate as 9600 bps
while (!Serial) {} //wait for serial
}
void loop() {
int s1=0,s2=0,s3=0,s4=0;
delay(10000);
SerialUSB.println("s1 =============================");
for(int i=0; i<100; i++){
s1 = analogRead(1); //connect sensor to Analog 1
SerialUSB.println(s1); //print the value to serial port
delay(200);
}
SerialUSB.println("s2 =============================");
for(int i=0; i<100; i++){
s2 = analogRead(2); //connect sensor to Analog 2
SerialUSB.println(s2); //print the value to serial port
delay(200);
}
SerialUSB.println("s3 =============================");
for(int i=0; i<100; i++){
s3 = analogRead(3); //connect sensor to Analog 3
SerialUSB.println(s3); //print the value to serial port
delay(200);
}
SerialUSB.println("s4 =============================");
for(int i=0; i<100; i++){
s4 = analogRead(4); //connect sensor to Analog 4
SerialUSB.println(s4); //print the value to serial port
delay(200);
}
//c(4,2)=6
SerialUSB.println("s1 s2 =============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s2 = analogRead(2);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.println(s2);
delay(200);
}
SerialUSB.println("s1 s3 =============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s3 = analogRead(3);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.println(s3);
delay(200);
}
SerialUSB.println("s1 s4 =============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s4 = analogRead(4);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
SerialUSB.println("s2 s3 =============================");
for(int i=0; i<100; i++){
s2 = analogRead(2);
s3 = analogRead(3);
SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.println(s3);
delay(200);
}
SerialUSB.println("s2 s4 =============================");
for(int i=0; i<100; i++){
s2 = analogRead(2);
s4 = analogRead(4);
SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
SerialUSB.println("s3 s4 =============================");
for(int i=0; i<100; i++){
s3 = analogRead(3);
s4 = analogRead(4);
SerialUSB.print(s3); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
//c(4,3)=4
SerialUSB.println("s1 s2 s3=============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s2 = analogRead(2);
s3 = analogRead(3);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.println(s3);
delay(200);
}
SerialUSB.println("s1 s3 s4=============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s3 = analogRead(3);
s4 = analogRead(4);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.print(s3); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
SerialUSB.println("s1 s2 s4=============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s2 = analogRead(2);
s4 = analogRead(4);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
SerialUSB.println("s2 s3 s4=============================");
for(int i=0; i<100; i++){
s4 = analogRead(4);
s2 = analogRead(2);
s3 = analogRead(3);
SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.print(s3); SerialUSB.print("\t");SerialUSB.println(s4);
delay(200);
}
//c(4,4)=1
SerialUSB.println("s1 s2 s3 s4=============================");
for(int i=0; i<100; i++){
s1 = analogRead(1);
s2 = analogRead(2);
s3 = analogRead(3);
s4 = analogRead(4);
SerialUSB.print(s1); SerialUSB.print("\t");SerialUSB.print(s2); SerialUSB.print("\t");SerialUSB.print(s3); SerialUSB.print("\t"); SerialUSB.println(s4);
delay(200);
}
while(1){};
}