Skip to content

KY-022 Infrared Receiver #1194

@nojvspine

Description

@nojvspine

Device name: Infrared Receiver
Protocol: GPIO
URL of example product: https://arduinomodules.info/ky-022-infrared-receiver-module/
Further information e.g. data sheet:

With gpiod we use this receiver in pair with infrared LED so that it blinks and receiver gets the signal.

import gpiod
from threading import Thread
from gpiod.line import Direction, Value
from time import sleep
from time import time

SENSOR = 27
LED = 5

chip_name = '/dev/gpiochip4'

def send_signal():
    with gpiod.request_lines(
                chip_name,
                consumer='led-test',
                config={
                        LED: gpiod.LineSettings(
                                direction=Direction.OUTPUT, output_value=Value.ACTIVE
                            ),
                    }
                ) as request:
        while True:
            request.set_value(LED, Value.ACTIVE)
            sleep(0.025)
            request.set_value(LED, Value.INACTIVE)
            sleep(0.025)
            
def get_signal():
    with gpiod.request_lines(
                chip_name,
                consumer='sensor-test',
                config={
                        SENSOR: gpiod.LineSettings(
                                direction=Direction.INPUT
                            ),
                    }
                ) as request:
        while True:
            request.
            print(f'Got {request.get_value(SENSOR)} from sensor')

def main():
    send = Thread(target=send_signal)
    get = Thread(target=get_signal)
    get.run()
    send.run()

if __name__ == '__main__':
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions