Example Code for UNIHIKER-LED Control
Control the LED light using the photo interrupter. The LED light will turn on when the photo sensor is blocked; otherwise, it will turn off.
Hardware Preparation
- 1 x UNIHIKER
- 1 x photo interrupter
- 1 x Two-end PH2.0-3P White Silicone Twisted Wire
Software Preparation
- MindPlus
Wiring Diagram
Connect the photo interrupter to pin P23 on the UNIHIKER, and connect the LED light to pin P24.

Other Preparation Work
Sample Code
from pinpong.extension.unihiker import *
from pinpong.board import Board, Pin
# Initialize the board
Board().begin()
# Set up the input pin for the photo interrupter
p_p23_in = Pin(Pin.P23, Pin.IN)
# Main loop
while True:
# Check if the photo interrupter is blocked
if p_p23_in.read_digital():
# If blocked, turn on the LED
p_p24_out = Pin(Pin.P24, Pin.OUT)
p_p24_out.write_digital(1) # Turn on the LED
else:
# If not blocked, turn off the LED
p_p24_out = Pin(Pin.P24, Pin.OUT)
p_p24_out.write_digital(0) # Turn off the LED
Result
After the program runs successfully, cover the photo interrupter with an object, and the LED light will turn on. When the object is removed, the LED light will turn off.

Additional Information
Note: You can refer to the MindPlus Code Programming Tutorial for a better understanding of how to use Python code mode in MindPlus.
Was this article helpful?
