Control the barrier to go up and down with light sensors and one button

Control the barriers

Program one barrier to go up and down using one button, the two light sensors and one motor. Before your start programming. Make a flow chart.

The flow chart is what programmers use to communicate and think about what the program needs to do. For this example it seems to be too easy, but its best to understand it first in easy coding before going to complex examples. Need help with making and good flow chart go to the library.

For this program is best to use Sequential Function Chart (SFC). It looks almost like an flow chart. Its a graphical programming language what lets you see which state the program is in.

In this lessons we use 3 states:

  • State 1: Idle state. Waiting until the button is high
    • Condition to move the state 2: Button is pressed.
  • State 2: Barrier up. Turns the motor on the go up.
    • Condition to move the state 3. Sensor barrier is up.
  • State 3: Barrier down. Turns the motor on to go down.
    • Condition to move the state 1. Sensor barrier is down.

Test the program and check the states.

Translate »
Scroll to Top