If this module is powered, a sequence of color changes is automatically emitted from the LED, which includes 7 different colors as well as all mixed colors of the 7 different colors included.

Technical data

Voltage range 3.3V to 5V

Pin assignment

Code example Arduino

Connection assignment Arduino

Arduino Sensor
Pin 13 Signal
- -
Mass GND

This code example shows how an LED can be switched on for four seconds and then switched off for two seconds by means of a definable output spin.

int Led  =  13;
 
void setup  ( )
{
  pinMode (Led, OUTPUT)  ;  // Initialization  Output spin for the LED
}
 
void loop  ( )  //Main program loop
{
  digitalWrite   (Led, HIGH)  ;  // LED  is switched on
  delay (4000)  ;  // Wait mode for 4 seconds
  digitalWrite  (Led, LOW) ;  // LED  is switched off
  delay (2000)  ;  // Wait mode for another two seconds in which the LED is switched off
}

Sample program download

KY034-Arduino-ON-OFF.zip

Code example Raspberry Pi

Connection assignment Raspberry Pi

Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
- -
Mass [ Pin 6 ] GND

This is a similar example program with the difference that here no LED is brought to light but something is output in the console when a signal is detected.

#  Required modules are imported and set up
import RPi. GPIO  as  GPIO
import time
  
GPIO.setmode (GPIO.BCM) 
  
# The input pin to which the sensor is connected is declared here.  In addition the PullUP resistor at the input is activated
LED_PIN = 24
GPIO.setup(LED_PIN, GPIO.OUT, initial= GPIO.LOW)
  
print ("LED test [press CTRL+C to end the test]")
 
# Main program loop
try:
        while True:
                print("LED 4 seconds on")
                GPIO.output(LED_PIN,GPIO.HIGH) # LED is switched on
                time.sleep(4)  # Wait mode for 4 seconds
                print("LED 2 seconds off") 
                GPIO.output (LED_PIN,GPIO.LOW) # LED is switched off
                time.sleep (2)   # Standby mode for another two seconds when the LED is switched off
 
# Tidying up after the program is finished
except KeyboardInterrupt:
        GPIO.cleanup ()

Sample program download

KY034-RPi-ON-OFF.zip

To start with the command:

sudo python3  KY034.py

Code example Micro:Bit

Connection assignment Micro:Bit:

Micro:Bit Sensor
Pin 1 Signal
- +V
Mass GND

This is a MakeCode example for Micro: Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.

Sample program download

microbit-KY-034.zip