#define pinPersianaAbierta 8
#define pinSensorPresion 9
#define pinRele57 2
#define pinRele34 3
#define pinRele28 4
#define pinError 5
int remoto;
int persianaAbierta;
int sensorPresion;
unsigned long timer;
enum {
PASO1,
PASO2,
PASO3,
PASO4,
PASO5,
PASO6,
ERROR
};
int paso = PASO1;
int pasoanterior = -1;
void setup() {
Serial.begin(9600);
pinMode(pinRemoto, INPUT_PULLUP);
pinMode(pinPersianaAbierta, INPUT_PULLUP);
pinMode(pinSensorPresion, INPUT_PULLUP);
pinMode(pinRele57, OUTPUT); digitalWrite(pinRele57, LOW);
pinMode(pinRele34, OUTPUT); digitalWrite(pinRele34, LOW);
pinMode(pinRele28, OUTPUT); digitalWrite(pinRele28, LOW);
pinMode(pinError, OUTPUT); digitalWrite(pinError, LOW);
}
void loop() {
remoto = digitalRead(pinRemoto) == LOW;
persianaAbierta = digitalRead(pinPersianaAbierta) == LOW;
sensorPresion = digitalRead(pinSensorPresion) == LOW;
if ( pasoanterior != paso ) {
Serial.println(paso + 1);
pasoanterior = paso;
}
switch ( paso ) {
case PASO1:
if ( remoto == HIGH ) {
digitalWrite(pinRele57, HIGH);
timer = millis();
paso = PASO2;
}
break;
case PASO2:
if ( persianaAbierta == HIGH ) {
digitalWrite(pinRele34, HIGH);
timer = millis();
paso = PASO3;
}
if ( millis() - timer >= 30000UL ) {
digitalWrite(pinRele57, LOW);
paso = ERROR;
}
break;
case PASO3:
if ( sensorPresion == HIGH ) {
digitalWrite(pinRele28, HIGH);
}
if ( persianaAbierta == LOW) {
digitalWrite(pinRele34, LOW);
digitalWrite(pinRele28, LOW);
}
if ( sensorPresion == LOW) {
digitalWrite(pinRele34, LOW);
digitalWrite(pinRele28, LOW);
paso = PASO4;
}
if ( millis() - timer >= 30000UL ) {
digitalWrite(pinRele57, LOW);
digitalWrite(pinRele34, LOW);
digitalWrite(pinRele28, LOW);
paso = ERROR;
}
break;
case PASO4:
if ( remoto == LOW ) {
digitalWrite(pinRele28, LOW);
timer = millis();
paso = PASO5;
}
break;
case PASO5:
if ( millis() - timer >= 20000UL ) {
digitalWrite(pinRele34, LOW);
paso = PASO6;
}
break;
case PASO6:
if ( sensorPresion == LOW ) {
digitalWrite(pinRele57, LOW);
paso = PASO1;
}
break;
case ERROR:
digitalWrite(pinError, HIGH);
break;
}
}
Hola esta versión ya apaga los reles, cuando no hay señal de sensores, ahora esta independiente, Persiana Abierta apaga RE34, Sensor Presión apaga RE28, lo malo es que envía a error pasado un tiempo.
Nota: El hilo ya supero las trescientas visitas nunca he abierto un hilo que sea tan popular