I want to add a delay to the sensor reading so it only reads the moisture onse every 10-20 minutes. i am not sure where to put it. it is like no matter where i put it it delays the buttons aswell, and i can´t use the menus.
Colin.ino (8.96 KB)
I want to add a delay to the sensor reading so it only reads the moisture onse every 10-20 minutes. i am not sure where to put it. it is like no matter where i put it it delays the buttons aswell, and i can´t use the menus.
Colin.ino (8.96 KB)
This bit of code you already have:
//used to reset screen and kick out of edit after 30 seconds
if ((screen != 0) || (edit_mode != 0)) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
screen = 0;
edit_mode = 0;
previousMillis = currentMillis;
}
}
Do something similar for your moisture readings. Your interval will be 20 minutes (20 * 60 * 1000). When hit, it should read and map your moisture variables.
Also, forgot to ask, - Is this some sort of automated watering system for plants? And if so are you using the two nail technique?
If so, the DC going through can cause rapid corrosion and throw off your readings, if you're willing to use another pin, you can alternate the current and slow that process.
The periodic reading like you asked for is another way to slow it down.
Arduino: 1.6.0 (Windows 7), Board: "Arduino Uno"
Sketch uses 1,068 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 11 bytes (0%) of dynamic memory, leaving 2,037 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x01
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x01
Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Yes tammytam it is a watering system and i am using the two nail system, thats why i want to use the delay. i am pretty new to this programming, so i am not quite sure what you mean sorry
//used to reset screen and kick out of edit after 30 seconds
if ((screen != 0) || (edit_mode != 0)) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
screen = 0;
edit_mode = 0;
previousMillis = currentMillis;
}
}
could you maybe show me inatead?
I can show you, but you've literally got the code already there for another system, so unless you copied it you should understand it
unsigned long currentMillis = millis();
static unsigned long previous_humid_reading_millis = 0;
if( currentMillis - previousMillis > (20 * 60 * 1000) ) // 20 minutes
{
// This code gets hit every 20 minutes ! Raise a flag to do all your readings and watering...
previous_humid_reading_millis = currentMillis;
}
I had help :smil lol: ,so i really don´t undestand it all yet
I am not really sure where to put it in the code