Ky-008 Laser and Laser sensor.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Light/Laser detector.

Smoke Genie Warning

Install the laser prism detector as shown below with the lump facing back towards the chip. If you install it backwards, the sensor will burn out.

Press down the prism wires firmly and make sure the wires go all the way into the plugs.

The right way to install the prism.

Laser Receiver Wiring Diagram

VCC: 5V, Pin 1

Out: Pin 40 (GPIO 21)

GND: Ground, Pin 6.

KY-008 Laser Wiring Diagram

VCC: Pin 4. 5V

S: Pin 38 (GPIO 20)

GND (-) : Pin 39. Ground

Python3 Code.

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# Light sensor pin
pin = 21

# Laser pin
ledpin = 20

# Setup pin in and out directions
GPIO.setup(pin, GPIO.IN)
GPIO.setup(ledpin, GPIO.OUT)

def laser_detector(pin):
    #Turn on the laser
    GPIO.output(ledpin, GPIO.HIGH)

    # Delay for laser to activate
    time.sleep(0.1)

    # Read the light sensor value and print it to terminal
    print('Light sensor value: ',GPIO.input(pin))

    # Read light sensor and display status
    if GPIO.input(pin) == 1:
        print('Laser detected.')
    else:
        print('Laser not detected.')

    # Add time delay
    time.sleep(0.2)

# Start the program loop to activate the laser and read the light sensor.
try:
    while True:
        laser_detector(pin)
except KeyboardInterrupt:
    pass
finally:
    GPIO.cleanup()
Python3 Code.

Run the Python3 code from Linux.

python3 lasertripbeam.py

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.