Go Down

Topic: Help coding two sensors triggering LEDS (Read 4906 times) previous topic - next topic

UKHeliBob

Quote
when I leave my hands for longer period in front of the sensors the LEDs switch on suddenly again
If you look back at reply #1 you will see that I suggested actions should be taken when a sensor goes HIGH, ie changes from LOW to HIGH.  Your current code takes actions when a sensor is HIGH so if you leave your hand in place it will see the HIGH signal again and take the actions again. 

What you need to do when a sensor is seen to be HIGH is to check that its previous state was LOW.  To do this you need to remember the state of the sensor the last time you read it.  This process is known as state change detection and there is an example of it in the IDE.

Nothing to do with this problem, but you can drastically reduce the complexity of your ON/OFF functions by using an array and passing parameters to a single function.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Docedison

#16
Feb 09, 2014, 11:56 pm Last Edit: Feb 10, 2014, 12:26 am by Docedison Reason: 1
what happens when two people going in opposite directions use the stairs at the same time...
Reminds me of that song from Fiddler on the Roof... If I were a Rich Man.... I'd have 3 staircases, one going up, one going down and one not going anywhere at all... Biddy, biddy.. Better I think to have one sensor diagonally placed so as to sense when the corridor formed by the stairs is occupied... No fancy logic involved...
Obviously not tested P-Code...
void setup()
set the pins for sensor and led here
void loop()
{
if (sensor )
{
occupied = 1; // Delay flag, Stairs are in use
led =1 ;            // so turn on the light's
}
if  (occupied and ! sensor)   // If the stairs were in the past period (5 seconds) occupied
wait 5 seconds; // blink W/O delay for the next person up or down
occupied = 0;  //  reset the delay flag:
led = 0;     // turn off the Led

Not nearly complete but a fair outline of a simpler method?

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

ARDURINO


Quote
when I leave my hands for longer period in front of the sensors the LEDs switch on suddenly again
If you look back at reply #1 you will see that I suggested actions should be taken when a sensor goes HIGH, ie changes from LOW to HIGH.  Your current code takes actions when a sensor is HIGH so if you leave your hand in place it will see the HIGH signal again and take the actions again. 

How to write the code for this statement  ......( when sensor goes from LOW to HIGH ), just learning here.

Quote

What you need to do when a sensor is seen to be HIGH is to check that its previous state was LOW.  To do this you need to remember the state of the sensor the last time you read it.  This process is known as state change detection and there is an example of it in the IDE.

This one is new for me.
I didn't know about this function , I'll search for it.


ARDURINO


what happens when two people going in opposite directions use the stairs at the same time...
Reminds me of that song from Fiddler on the Roof... If I were a Rich Man.... I'd have 3 staircases, one going up, one going down and one not going anywhere at all... Biddy, biddy.. Better I think to have one sensor diagonally placed so as to sense when the corridor formed by the stairs is occupied... No fancy logic involved...
Obviously not tested P-Code...
void setup()
set the pins for sensor and led here
void loop()
{
if (sensor )
{
occupied = 1; // Delay flag, Stairs are in use
led =1 ;            // so turn on the light's
}
if  (occupied and ! sensor)   // If the stairs were in the past period (5 seconds) occupied
wait 5 seconds; // blink W/O delay for the next person up or down
occupied = 0;  //  reset the delay flag:
led = 0;     // turn off the Led

Not nearly complete but a fair outline of a simpler method?

Doc

Hi Doce ,
I know this could happen , but I started to KISS ( KEEP IT Super Simple) here, then I'll improve system STEP by STEP.
Anyway thank you so much for your suggestion.

Go Up