Hello to everyone!
I am using ARRAY for three soil moisture sensors ( A0,A1,A2) with arduino Uno. Ι open the Arduino uno every 12 hours manually. My problem is that at the time that Uno working the data from AO,A1,A2 i need to put a delay time between them 3 minutes in my code. That means when AO sent the data to uno has to stop ,After 3 minutes must open A1 and read the data and then stop. After 3 minutes open A2 read the data and then stop. Is there any way to put a delay time between them when I use arrays ?
#include <SoftwareSerial.h>
const byte sensorPins[] = {A0, A1, A2};
int sensorValue;
void doSoilSensor(byte sensorNo)
{
int sensorValue = analogRead(sensorPins[sensorNo]);
Serial.print("sensor = " );
Serial.println(sensorValue);
delay(20000);
}
void setup() {
Serial.begin(9600);
}
void loop() {
for (uint8_t cnt = 0; cnt < sizeof(sensorPins); cnt++)
{
doSoilSensor(cnt);
}
}
Is there any way to put a delay time between them when I use arrays ?
You already have a 20 second delay between readings, why not make it longer ?
Some time the mind gets stuck.!!!
Thank a lot my friend!
At the above code how can delay the first readings from AO ? I mean when i give power to Arduino Uno i do not want strait away starting reading the data from AO . I need to have a delay time before the hole project start sending data ?
I need to have a delay time before the hole project start sending data ?
Put the delay() in setup()
not with a delay function.
I am using ARRAY for three soil moisture sensors ( A0,A1,A2) with arduino Uno. Ι open the Arduino uno every 12 hours manually. My problem is that at the time that Uno working the data from AO,A1,A2 i need to put a delay time between them 3 minutes in my code. That means when AO sent the data to uno has to stop ,After 3 minutes must open A1 and read the data and then stop. After 3 minutes open A2 read the data and then stop. Is there any way to put a delay time between them when I use arrays ?
I'm assuming you mean that you power-cycle the arduino when it's time to do another reading.
enum State {
START,
READ,
DONE
} state = START;
void setup() {
}
int readingN;
const byte readingPin[] = {A0, A1, A2};
int readings[3];
uint32_t readingMs;
const uint32_t readingDelayMs = 1000L * 60L * 3L; // 3 minutes
void loop() {
switch (state) {
case START:
readingN = 0;
state = READ;
// trick the 'reading' state into performing the first read immediately
readingMs = millis() - readingDelay;
break;
case READ:
if (millis() - readingMs < readingDelayMs) break;
readings[readingN] = analogRead(readingPin[readingN]);
readingN ++;
if (readingN >= 3) {
readingsAreComplete_doStuff();
state = DONE;
}
else {
readingMs += readingDelayMs;
}
break;
case DONE:
// done. do nothing.
break;
}
}
void readingsAreComplete_doStuff() {
}
Exacly !
That was my problem !! I thank you very much for your help and also the rest friends that had answer me.
!!
Having said that, power-cycling the arduino is for chumps. Add a button to trigger a read, and think about what the whole sketch should do, not just the little bit you are interested in.