In this article, we connect an KY-034 7 color flashing LED to a Raspberry Pi 4
The KY-034 7 color flashing LED module can emit a color sequence from the LED when power is supplied to it. The LED has 7 different colors and thus also all resulting mixed colors.
We will use Python for these examples
Working voltage | 3V — 5V DC |
LED model | YB-3120B4PnYG-PM |
LED type | 5mm round head |
The sensor looks like this
Parts Required
You can connect to the module using dupont style jumper wire. There is no reason this device will not work with any Raspberry Pi hardware that you have – in this example a Raspberry Pi 4 but you can use a Zero if you want a lower cost solution
Name | Link | |
Raspberry Pi 4 | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
Pico | SENSOR |
---|---|
Pin 18 | S |
GND | – |
Code Examples
Basic example in thonny, running on the Raspberry Pi
import RPi. GPIO as GPIO import time GPIO.setmode (GPIO.BCM) # The input pin LED_PIN = 24 GPIO.setup(LED_PIN, GPIO.OUT, initial= GPIO.LOW) print ("Flashing 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 for 4 seconds print("LED 2 seconds off") GPIO.output (LED_PIN,GPIO.LOW) # LED is switched off time.sleep (2) # LED is switched off # Tidying up after the program is finished except KeyboardInterrupt: GPIO.cleanup ()
REPL Output
N/A
Links
https://github.com/getelectronics/PIBits/tree/master/Sensor%20Kit/KY-034%207%20COLOR%20LED