LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Room's Light Simulate

Solved!
Go to solution

Hello everyone

I want to create a VI that simulate the activity of a sensor (motion Sensor). In this case, i want to set up a light that turn on whenever there are people in the room,. The light will keep lighting in the next X (seconds), and then turns off (If there are no more motions sensed by the Sensor). 

 

In the period of X Seconds, if there is any person coming in the room, the led will keep be on until the next period of X seconds passes. And so on.

 

(e.g) When x = 3(s)

Case 1:

{t:= 0, people coming the room, light = on

t:= 1, (no people), light = on

t:= 2, (n.a)

t:= 3, (no people), light = off

}

Case 2:

{t:= 0, people coming the room, light = on

t:= 1, (n.a)

t:= 2, people coming the room, light = on

t:= 3, (no people, light = on)

...

t:= 5 (no people, light = off)

}

 

 

Because i don't have any real material and sensor, i only use a random function to simulate the people entering the room. Smiley Frustrated

 

I have trouble when building the VI. I tried some version but they are all failure.

Any idea? 

Please !

 

I'm using labview 2011 

 

P/S: English is not my mother-tongue, so please ignore all grammatical mistakes that i have done. Smiley Embarassed

 

0 Kudos
Message 1 of 11
(4,507 Views)

Hi John,

 

In the period of X Seconds, if there is any person coming in the room, the led will keep be on until the next period of X seconds passes. And so on.

- You need a signal/flag marking the condition "people are moving": when using a random function you could simplify this to "rnd() >= 0.9"…

- When the condition is met (aka rising edge, detected by PtByPt-BooleanCrossing) you start your timer

- as long as the timer is running you keep the light on

 

I have trouble when building the VI. I tried some version but they are all failure. Any idea?

Attach your VI and we will tell you what went wrong!

(When "no VI from you" THEN "no VI from us"… :D)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(4,501 Views)

@johnnguyen123 wrote:
[...]

I have trouble when building the VI. I tried some version but they are all failure.[...]

 


Sounds like you require at least a state machine... Have you tried that?

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 11
(4,468 Views)

Thank you all of you!

I did not want to share my vi because it didn't work. Anyway, this is my Vi

 

i used labview 2011, if you upload your vi, please save its as labview 2011file. Otherwise my computer can not read.

 

One more time, thank you all !

 

0 Kudos
Message 4 of 11
(4,446 Views)

My new vi:

 

I am pretty sure that this thing is much more better, but it still doesn't work as i expected.

 

0 Kudos
Message 5 of 11
(4,416 Views)

Your outer while loop will only run once because your inner while loop will run forever since you have a false constant wired to the stop terminal.  The only way to stop your program is to abort.

 

Before posting, be sure to run block diagram cleanup so you don't have backwards running wires.

 

Have you sat down and drawn a simple flowchart or some pseudo code to describe how the program is supposed to work?  Right now it looks like just a few functions that should be ones you need to use, thrown down with no logical reason as to why they are there.  The local variables really don't need to be there.

 

You talk about needing two loops, but it seems to me this should be a 1 loop program.  But without some logical plan as to how the program should work, there is no point throwing down code on a block diagram.

0 Kudos
Message 6 of 11
(4,411 Views)

This time, everything work quite well. However, there is a problem.  After the "Human" Boolean = true, the ligh turn on for 5 sec. However, if at the moment when time = 3, the "Human" Boolean = true (second time), the light only be on for the next 2 seconds ( i want the light to be on for the next 5 seconds then turn off)

 

From what i assume, the second while loop keep working until it finishes, so that it couldn't update continuously the data from the "human" Boolean. I want the whole different thing, the time still runs, but the time counter will reset to 0 after the "human" Boolean = true again 

I have wrote many pseudocode, but it's very different when applying to labview >.<

 

 

0 Kudos
Message 7 of 11
(4,400 Views)
Solution
Accepted by topic author johnnguyen123

There is still a problem with the extra while loop and unneeded local variables.

 

Here is how to do it in one loop.

0 Kudos
Message 8 of 11
(4,379 Views)

OMG, you really did that !!!

 

But you did that by using some things that i have no idea what they are 😛

 

Anyway, i believe that i can learn! And it's seem to be the best solution!

 

Thank you so much!

 

 

0 Kudos
Message 9 of 11
(4,373 Views)
Solution
Accepted by topic author johnnguyen123

The only thing that might be unfamiliar to you in this VI is the Boolean Crossing Pt by Pt, which is a pretty cool VI that outputs a True only when the input changes.

 

Actually, I probably should have not used that at all because if you had continuous movement so that "human" was detected on every 1/2 second iteration of the while loop, it would only output a True and reset the timer upon the first True, following a False.  So I'd eliminate that and just wire the =1 output directly to the Reset input of the Express VI.

0 Kudos
Message 10 of 11
(4,369 Views)