I have this code below. When smoke sensor detects smoke, the ventilating fan turns on and when the moisture sensor detects water the window closes. However, i used a led as an indication for the window. My question is, when smoke and water is detected, the arduino executes the task that takes place first and then the next task. I know i have to use interrupts. But i don't know how to start. Any small hints will be helpful. Thank you.
Err. Sorry i'm kinda stuck. How do i write the program so that it closes the window and turn the ventilating fan on when smoke and water are detected at the same time?
How do i write the program so that it closes the window and turn the ventilating fan on when smoke and water are detected at the same time?
Get started. Right away. Without delay().
Nothing happens "at the same time". You check the value of a sensor then tells whether there is smoke. Then you check the value of a sensor to see if there is water. You did not do both checks "at the same time".
State machines and the blink without delay examples are the way to go. You have some states - everything's fine, the house is on fire and its not raining, the house is on fire and it is raining, etc. What you do at any given time depends on the state you are in.
Although, really, if the house is on fire why you are worried about closing the window because it is raining escapes me.