Siren effect on a single LED?

Do you know if it’s possible to use a single LED that alternates from blue to red, to create a siren effect like police, fire trucks, and similar?

Thanks in advance.

Something I haven’t mentioned is whether I can do it using Bambulab LEDs.

WS2812 RGB LED with IDC0.8 4PIN (2PCS) | Tienda Bambu Lab EU

If it’s an addressable LED, like a WS2812, then yes you can make it switch between colors.

3 Likes

hello
you can find some 2 colors LED

like (for some reason the link point to green/blue, but the same applies )

but you’ll need to provide 2 signals in sync to light up each color while stopping the other

2 Likes

Two great options and you can also just do it yourself with two LEDs.

The best way is probably set by the microcontroller you are using it with to drive the LED. If you are just into using I/O pins to drive the LEDs, the bicolor LED or two discrete LEDs might be the better choice.

The LEDs with the WS2812 functionality (aka RGB LEDs or neopixels) have 3 or 4 LEDs in them - RGB and sometimes white. To drive those you connect + and - supplies and one I/O line that sends out a serial pulse train that sets the brightness of the LEDs in the module.

That’s the big difference - do you need brightness control and are you up to coding that pulse train needed for neopixels. If you want to just set and clear I/O pins to blink the LEDs, it’s discrete LEDs or bicolor LEDs.

Depending on the microcontroller you are using there can be libraries ready to go to drive neopixels so it may not be difficult at all to get working. Neopixels also daisy chain so you can use a single I/O pin to drive many neopixels. The caveat is time - the longer the daisy chain the longer it takes to update the LED brightness and color and that can get so long you can spot flicker. But there’s also ways around that if needed.

Added - you can PWM discrete LEDs too in order to get brightness control.

1 Like

The MicroPython interpreter on the CyberBrick has library support for WS2812 LEDs. The “NeoPixel” library. There are tons of examples on the web showing how to drive these LEDs with this library. One of the few things AI is actually pretty good for, just ask your favorite LLM to show you example MicroPython code that controls WS2812s. It is almost trivially simple.

No actual work beyond some cut and paste would be necessary, aside from the wiring itself… :slight_smile:

The advantage of using WS2812s is that you can control intensity. Instead of just blinking on/off instantly, you could make it ramp up/down quickly, so it’s more like an incandescent bulb.

3 Likes

Huge advantage! I’ve used brightness to simulate fireflies, flame flickers, and incandescent bulbs. It works great!

I’d just as soon use neopixels now where I would otherwise use an LED.

I prefer to use 2812s. You can do so much more with them. They need an MCU, but I don’t need to calculate and connect a current limiting resistor to make them work. V+/Gnd/Data and some code. Easier to hook up. And the code to drive them is easy to write (cut/paste).

2 Likes

But are we talking about the LEDs sold by Bambulab with its Cyberbrick ecosystem? WS2812 RGB LED with IDC0.8 4PIN (2PCS) | Bambu Lab US Store

Thanks, Something I haven’t mentioned is whether I can do it using Bambulab LEDs.

The only difference between the Bambu LED and a generic WS2812 is packaging. Electrically, they are all the same thing. You could take the wiring harness and snip it off the Bambu LED, and connected it to a WS2812 LED strip you bought off Amazon.

1 Like

I understand, but how do I configure that color alternation in the cyberbrick ecosystem? I’ve even been looking into using micro python.

Well… you have to know how to program. Although, since Bambu sells a WS2812 LED for the Cyberbrick, I have to think they’ve got some sample code showing how to make the LED work…

I don’t own a Cyberbrick. But I have been programming WS2812 LED controllers on ESP32s and Arduinos for quite a few years…

You can drive an entire string of WS2812 LEDs from a single output. Like these lighted gates for indoor micro drone racing… They’re using about 80 LEDs all strung together in each one, with a single Arduino powering and driving the color patterns and animations (I’d have posted a YT video so you could actually see them changing, but every time I tried the forum’s editor box showed a broken link).

3 Likes

my bad : I didn’t pay enough attention to the sub forum (ie Cyberbrick)

you should find some code you can adapt in simlar projects , like

https://makerworld.com/fr/models/1043348-f1-sign-led-with-color-sequences#profileId-1028623

I didn’t specify my intention in the text. Thank you, buddy.

Maybe this Shippet does what you expect?

Police Light - LED 0 and 1 (Red/Blue Alternating):

# Shippet effect police

from leds import LEDController
from machine import Timer

led_front = LEDController(“LED1”)

# Stop effects
led_front.repeat_count = 0

try:
police_timer
except:
police_timer = Timer(0)

police_timer.deinit()

def police_blink(t):
# Alternate: LED 0 Red/LED 1 Blue → LED 0 Blue/LED 1 Red
if led_front.np[0] == (255, 0, 0):
led_front.np[0] = (0, 0, 255) # LED 0 Blue
led_front.np[1] = (255, 0, 0) # LED 1 Red
else:
led_front.np[0] = (255, 0, 0) # LED 0 Red
led_front.np[1] = (0, 0, 255) # LED 1 Blue

led_front.np.write()

# Fast switching every 150ms
police_timer.init(period=150, mode=Timer.PERIODIC, callback=police_blink)

Police Light - Single LED (Red/Blue Toggle):

from leds import LEDController
from machine import Timer

led_front = LEDController(“LED1”)

# Stop effects
led_front.repeat_count = 0

try:
police_timer
except:
police_timer = Timer(0)

police_timer.deinit()

# Start with red
led_front.np[0] = (255, 0, 0)
led_front.np.write()

def police_toggle(t):
# Toggle between Red and Blue
if led_front.np[0] == (255, 0, 0):
led_front.np[0] = (0, 0, 255) # Switch to Blue
else:
led_front.np[0] = (255, 0, 0) # Switch to Red

led_front.np.write()

# Switch every 200ms
police_timer.init(period=200, mode=Timer.PERIODIC, callback=police_toggle)

Connect the code Shippet (receiver) with an ‘event’ button /switch (controler)

1 Like

We are talking about 2 leds, one of them for blue and the other one for red, is that right?

No… these are RGB LED! They can ‘change’ colors! So the LED can light up in red or blue (or any other Color).

Here the LED used in the Shippet Code.

So the LED can change from blue to red.

Start with red

led_front.np[0] = (255, 0, 0)
led_front.np.write()

Start with blue

led_front.np[0] = (0, 0, 255)
led_front.np.write()

Start with white

led_front.np[0] = (255, 255, 255)
led_front.np.write()

You also can change the ‘brightness’

Start with white (50%)

led_front.np[0] = (127, 127, 127)
led_front.np.write()

So you also can program effects (fade in /out) on the LED
So the Shippet in the previous post shows the changing of blue and red with one LED and an alternating change (blue/red) between LED 0 and LED1….

1 Like

Understood, I think I can continue with that information. Thank you for your help.

2 Likes