Hello, i'm having troubles thinking of an algoritm to match what i want to do.
I'm making a small scale fire suppresion sistem with 3 rooms /3 fire sensors/3 solenoids valves .
Making them open when the sensor detects something is easy but i want to have them work independently like so:
If 1 sensor detects something(state of sensor should be low for 1 sec to proc it) it starts this algorithm:
-flash a 12v led for 3sec(this will be connected to a realay as well)
-open the valve after and keep it until the sensor doesnt detect anything but no less than 5 sec
But i dont want to use delays because if another sensor detects something i want the above steps to start in that specific room as well.
I saw that i can use the "millies" function but im kinda lost how, especially because i'm also trying to flicker the led for each detection.
Thought of using variables to store time by incrementing them and calculating 1 cycle of code(wich is maybe easyer with a small delay)
I would apreciate if you would give me some tips of what algorithm should i implement in the code
This is the simple code for detection and action:
Also something wierd is that the sensors do is normally on high and goes low when it detects something, same with the relay.
int s1 = 51 ;
int s2 = 52 ;
int s3 = 53 ;
int r1 = 31 ;
int r2 = 32 ;
int r3 = 33 ;
int flame_detected1 ;
int flame_detected2 ;
int flame_detected3 ;
pinMode(s1, INPUT) ;
pinMode(s2, INPUT) ;
pinMode(s3, INPUT) ;
flame_detected1 = digitalRead(s1);
flame_detected2 = digitalRead(s2);
flame_detected3 = digitalRead(s3);
if (flame_detected1 == 0)
Serial.println("111Flame detected...! take action immediately.");
else if (flame_detected2 == 0)
Serial.println("222Flame detected...! take action immediately.");
else if (flame_detected3 == 0)
Serial.println("333Flame detected...! take action immediately.");
Serial.println("No flame detected. stay cool");