Hi Dear Colleagues, I need your help with a problem in my software, it's very simple for you.
I have a compressor and I'm opening the drain with a solenoid valve after it turn off, but I have just one contact NO to
send me the state if it's ON or OFF.
When it's ON the contact is closed and when it's OFF the contact is open, I did the software below, but it isn't working very
well the solenoid valve is opening in diferent times please show me what I'm doing wrong. I need to turn OFF solenoide
because of the temperature so I'm opening just during five seconds. Thank You.
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int AVISA = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
AVISA = 1; //move 1 para variável
}
else if (buttonState == LOW && AVISA == 1) {
// turn LED off:
digitalWrite(ledPin, LOW);
delay (5000);
digitalWrite(ledPin, HIGH);
delay (5000);
digitalWrite(ledPin, LOW);
AVISA = 0;
}
else (buttonState == LOW); {
digitalWrite(ledPin, LOW);
}
}
