raiil
May 9, 2022, 7:35pm
1
I'm trying to turn a water pump ON for 30 seconds and then OFF for 30 minutes. PLEASE HELP
here is what I have so far:
#include <DHT.h>;
#define DHTPIN 7
#define DHTTYPE DHT22
#define IRR_ON 30000
#define IRR_OFF 18000000
DHT dht (DHTPIN, DHTTYPE);
const int FAN = A5;
const int PUMP = A0;
const int DEHUM = A4;
int chk;
float hum;
float temp;
void setup(){
Serial.begin(9600);
dht.begin();
pinMode(FAN, OUTPUT);
pinMode(DEHUM, OUTPUT);
pinMode(PUMP, OUTPUT);
digitalWrite(FAN, HIGH);
digitalWrite(DEHUM, HIGH);
}
void loop(){
hum = dht.readHumidity();
delay(250);
temp = dht.readTemperature();
if (hum < 50){
digitalWrite(DEHUM, HIGH);
}
else{
digitalWrite(DEHUM, LOW);
}
delay(15000);
if (temp <= 23.8889){
digitalWrite(FAN, HIGH);
}
else{
digitalWrite(FAN, LOW);
}
if (millis() < IRR_OFF){
digitalWrite(PUMP, HIGH);
}
if(millis() < IRR_ON){
digitalWrite (PUMP, LOW);
}
delay(2000);
{
Serial.print("Hum: ");
Serial.print(hum);
Serial.print(" %");
Serial.println();
Serial.print("Temp: ");
Serial.print((int)round(1.8*temp+32));
Serial.print(" Degrees");
Serial.println();
delay(250);
}
}
raiil:
if (millis() < IRR_OFF){
Think about how millis counts after reset.
I mean "what do you think millis() does?"
raiil
May 9, 2022, 7:45pm
5
i think its a timer that can be used to execute specific commands without interrupting the rest of the program
No.
It's a simple incrementing value, counting milliseconds since the last reset.
raiil:
PLEASE HELP
Help with what?
What's the trouble?
Why do helpers need to spend time helping You to post a question they can take on?
Read and follow this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum
raiil
May 9, 2022, 7:52pm
8
...so how am i able to change a specific pin to Low after 30 seconds using millis but not able to turn in to High after a specific time?
Probably because you're not understanding how time works.
raiil
May 9, 2022, 8:00pm
10
so are you going to tell me "how time works". there has to be a way to turn it back on using millis if i can turn it off using millis correct?
raiil
May 9, 2022, 8:02pm
11
sorry, your response is useless.
Time moves on.
Always.
At least it does where I am
raiil
May 9, 2022, 8:04pm
13
can your sketch an example of how it should look?
raiil:
if (millis() < IRR_OFF){
millis() will be less than IRR_OFF until it reaches IRR_OFF . It will NEVER be less again until you reset the Arduino OR the millis() counter rolls over after 49 days.
First understand "blink without delay"
https://www.baldengineer.com/blink-without-delay-explained.html
Then modify it for unequal intervals on and off.
When the on period has elapsed and you turn the pump off, you reset the interval to the off interval. When the off interval has elapsed, you reset the interval to the on interval.
raiil
May 9, 2022, 8:14pm
17
exactly what im looking for thanks you!!
Useless questions, useless answers...