Gentle siren

Billy Kwok
3 min readSep 5, 2021

How to overcomplicate your Arduino LED starter assignment and what I learned from it…

Billy Kwok. Professor Kimiko Ryokai. NWMEDIA C262, Fall 2021

Since I already have previous experience in Arduino and embedded system programming, I modified the assignment to make it as difficult for me as for the new learners. It still fulfills all the requirements listed in the instructions. However, I challenge myself to make a flashing police light using Pulse-width modulation (PWM) and the Arduino TaskScheduler library.

Description

Police light is probably not the most favorable object in the world. But its association with danger and crime does make it an effective visual indicator for warnings and alerts. I personally find this quite interesting and decided to build one to study its visual effect and potential usage.

Flashing Pattern

A police light typically consists of a blue and a red light. The lights blink in various patterns depending on the type of warning and regional convention. In my setup, I implemented the commonly used alternating flashing pattern.

Nevertheless, I found that on-and-off blinking is too distracting and uncomfortable. To improve and soften the pattern, I instead made the lights fade in and out quickly using two antiphase sine waves.

Electronic

The two LEDs are connected to the Arduino board pin 12 and 13 respectively. They have their own 220ohm resistor and are grounded to the same pin.

Circuit design

Implementation

Since LED takes only digital input, switching it on and off faster than human eyes can recognize is the only way to adjust its brightness.

Brightness can be adjusted by changing the portion of time when the voltage is applied
Brightness can be adjusted by changing the duty cycle

The higher the portion of time when the voltage is applied (duty cycle), the higher power output is resulted, thus the brighter the LED is. This is commonly known as pulse-width modulation (PWM).

I initially used the delayMicroseconds() function to implement the PWM. However, this would not work for the second LED, which flashes in a different schedule. This is because the built-in delay function pauses all the processing of the Arduino CPU, blocking the computation for the other LED light. Essentially, what we want is to make the delays for the two LEDs completely independent of each other. This requires some kind of concurrent or parallel processing. Unfortunately, Arduino, as an embedded system, supports neither threading nor scheduling natively. Instead of making my own time-sharing algorithm, I pulled in the neatly written Arduino TaskScheduler library. With its task scheduling feature, I managed to schedule the flashes of the LEDs without any blocking!

Basic demo of the flashing pattern

In addition, the flashing can be instantly stopped or resumed by sending the “STOP” or “START” command over the serial port. I also made the commands recognition case-insensitive and space-insensitive to make the system more tolerant to unexpected input.

Toggle flashing using command

Reflection

This modified version of the assignment is indeed challenging enough and gave me the opportunity to refresh my knowledge in PWM and scheduling. In terms of the flashing pattern, I found that alternating flashing is more comfortable for the users compared to simtaneous flashing because showing blue and red, which are contrasting colors, triggers a very high level of visual alertness.

Last but not least, this tiny project could be further developed into bigger ideas. Here are a few that I could think of.

  • Build a location-based racial violence alert using real-time crime monitoring API, which reminds and notifies people about the safety and racial justice of their neighborhood.
  • Develop it into a home security system that not only flashes when some people break into the house but also rings the siren.
  • Include it into STEM toy kits to teach kids about electronics.

What do you think about this? Please let me know in the comment section and share your thoughts!

Components Used

1x Arduino UNO R3

1x Breadboard

2x 220 Ω Resistors

2x LED (Blue and red)

Some Jumper wires

Code

--

--

Billy Kwok

Master of Design student at UC Berkeley, solving problems at the intersection of design, technology, and business. Check out billykwok.me / billykwok.medium.com