I've a exhaust fan that runs when the humidity is high. When the exhaust fan is on it should work for 3 minutes and should wait another 5 minutes to on. I am a beginner to this struggling for almost 2 days now. with this code the led just blink and off
int ledPin = 2; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis2 = 0;
unsigned long previousMillis = 0;
long interval = 10000; // in
long OnTime = 1000; // milliseconds of on-time
long OffTime = 2000; // milliseconds of off-time
void setup()
{
Serial.begin(9600);
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
unsigned long currentMillis2 = millis();
if (currentMillis2 - previousMillis2 > interval) {
// save the last time you blinked the LED
// check to see if it's time to change the state of the LED
Serial.print("hellohh ");
unsigned long currentMillis = millis();
if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
Serial.print("hellohh2 ");
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
Serial.print("hellohh 3");
ledState = HIGH; // turn it on
previousMillis = currentMillis;
previousMillis2 = 0; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
}
}
if (currentMillis2 - previousMillis2 > interval) {
is for a longer interval than 1000/2000 so I expect weird behaviour. You haven't said what is actually happening. Saying a "checking is working" is a bit non-specific. What is being printed? Does the LED light?