KY-010 Light barrier-module

From SensorKit X40 Wiki

Jump to: navigation, search

Picture

ky-010.jpg

Technical data / Short description

The connection between both input pins will be interrupted if the optical barrier is beeing interrupted.

Pinout

3 S V G.png

Code example Arduino

In this program, a LED will flash up, if a signal was detected at the sensor. You can also use the modules KY-011, KY-016 or KY-029 as LEDs. 

int Led = 13 ;// Declaration of the LED-output pin
int Sensor = 10; // Declaration of the Sensor-input pin
int val; // Temporary variable
 
void setup ()
{
  pinMode (Led, OUTPUT) ; // Initialization output pin
  pinMode (Sensor, INPUT) ; // Initialization sensorpin
}
 
void loop ()
{
  val = digitalRead (Sensor) ; // The current signal at the sensor will be read.
 
  if (val == HIGH) //The led will flash up, if a signal was detected.
  {
    digitalWrite (Led, HIGH);
  }
  else
  {
    digitalWrite (Led, LOW);
  }
}

Connections Arduino:

LED + = [Pin 13]
LED - = [Pin GND]
Sensor Signal = [Pin 10]
Sensor +V = [Pin 5V]
Sensor - = [Pin GND]

Example program download

SensorTest_Arduino_inverted

Code example Raspberry Pi

# Needed modules will be imported and configured 
import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
 
# The input pin which is connected with the sensor.<br /># Additional to that the pull up resistor of the input will be activated.
GPIO_PIN = 24
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
 
print "Sensor-Test [press ctrl+c to end the test]"
 
# This outputFunction will be started at signal detection
def outputFunction(null):
        print("Signal detected")
 
# The outputFunction will be started at the moment of a signal detection (raising edge).
GPIO.add_event_detect(GPIO_PIN, GPIO.RISING, callback=outputFunction, bouncetime=100) 
 
# Main program loop
try:
        while True:
                time.sleep(1)
 
# Scavenging work after the end of the program
except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

Signal = GPIO24 [Pin 18]
+V = 3,3V [Pin 1]
GND = GND [Pin 6]

Example program download

SensorTest_RPi_inverted

To start, enter the command:

sudo python SensorTest_RPi_inverted.py