){.nav-menu .menu-item-has-children a{padding-right:20px}.nav-menu .menu-item-has-children a:after{position:absolute;right:7px;top:10}}.vce-ad-container{margin:30px auto;display:block;clear:both;width:728px;position:relative;max-width:100%}.vce-ad-below-header{margin-bottom:0}@media only screen and (max-width:1200px) and (min-width:1024px){.vce-ad-container{width:630px}.vce-ad-below-header{width:728px}}@media only screen and (max-width:1023px){.vce-ad-below-header,.vce-ad-container{width:728px}}@media (max-width:767px){.vce-ad-container{width:375px}}@media (max-width:400px){.vce-ad-container{width:300px}}@media (max-width:320px){.vce-ad-container{width:280px;max-width:100%}}:root .main-navigation ul ul{opacity:1}@media only screen and (min-width:1024px) and (max-width:1200px){.container{max-width:1000px}.vce-main-content{width:700px}.main-navigation ul ul{display:none}.top-header{overflow:hidden}.main-navigation a{padding:15px 9px 15px}.search-header-wrap a{padding:15px}.header-3-wrapper .site-branding{max-width:300px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (min-width:670px) and (max-width:1023px){.header-3-wrapper .site-branding{max-width:300px}.header-3-wrapper .nav-menu>li>a{padding:0 15px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (max-width:1023px){.container{max-width:90%}.vce-main-content{width:100%;padding:15px 0!important}.main-navigation ul ul{display:none}.vce-res-nav{float:left;position:absolute;left:0}.header-3-wrapper{height:50px!important;padding-top:0!important;text-align:center}.header-3-wrapper .site-branding{position:relative;float:none;top:0!important;left:initial!important;text-align:center;max-width:initial;padding:3px 0 7px}.site-branding{padding:4px 0 7px;display:inline-block}.site-branding img{max-width:120px;max-height:28px}.main-header .header-3-wrapper .site-title,.main-header .header-3-wrapper .site-title a.has-logo{line-height:40px!important;font-size:26px!important}.sidebar{margin:0 auto 20px;float:none!important;display:block;clear:both;padding-top:0!important;width:100%;max-width:300px}h1.entry-title{max-width:100%}.vce-responsive-nav{display:block;margin:10px 0 9px}.nav-menu,.top-header{display:none}.main-header .site-title,.main-header .site-title a{line-height:36px!important;font-size:40px!important}li>ul{margin:0}}@media only screen and (min-width:200px) and (max-width:670px){html{margin-top:0!important;overflow-x:visible}html body,button,input,textarea{font-size:14px;line-height:22px}.container{max-width:95%}.vce-main-content{padding:0 0 10px!important}.main-box,.sidebar .widget{margin-bottom:10px}.vce-wrap-right{width:100%;max-width:100%;text-align:center}.vce-single .entry-header{margin:20px 0}.vce-wrap-right{text-align:center}body h1.entry-title{font-size:24px;line-height:30px;padding:0 20px}body p{margin-bottom:20px}body h1{font-size:24px;line-height:34px;margin-bottom:10px}body h4{font-size:18px;line-height:28px;margin-bottom:10px}.sidebar .widget-title{line-height:22px}.vce-wrap-right>ul{float:none;display:inline-block;margin:10px 0 0}}#cookie-notice *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#cookie-notice .cookie-notice-container{display:block}#cookie-notice.cookie-notice-hidden .cookie-notice-container{display:none}.cookie-notice-container{padding:15px 30px;text-align:center;width:100%;z-index:2}.cn-close-icon{position:absolute;right:15px;top:50%;margin-top:-10px;width:15px;height:15px;opacity:.5;padding:10px;outline:none}.cn-close-icon:before,.cn-close-icon:after{position:absolute;content:' ';height:15px;width:2px;top:3px;background-color:#fff}.cn-close-icon:before{transform:rotate(45deg)}.cn-close-icon:after{transform:rotate(-45deg)}#cookie-notice .cn-button{margin:0 0 0 10px}.cn-button.bootstrap{font-family:-apple-system,BlinkMacSystemFont,Arial,Roboto,"Helvetica Neue",sans-serif;font-weight:400;font-size:13px;letter-spacing:.25px;line-height:20px;margin:0;text-align:center;text-transform:none;display:inline-block;touch-action:manipulation;white-space:nowrap;outline:none;box-shadow:none;text-shadow:none;border:none;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;text-decoration:none;padding:8.5px 10px;line-height:1}.cn-button.bootstrap{color:#fff;background:#20C19E}.cn-text-container{margin:0 0 6px 0}.cn-text-container,.cn-buttons-container{display:inline-block}@media all and (max-width:900px){.cookie-notice-container #cn-notice-text{display:block}.cookie-notice-container #cn-notice-buttons{display:block}#cookie-notice .cn-button{margin:0 5px 5px 5px}}@media all and (max-width:480px){.cookie-notice-container{padding:15px 25px}}

Sound Reactive Pixel LEDs

This little post covers the construction details of sound reactive pixels which is pretty enjoyable to build and watch. You can embed it in a lot of things, for example, think about gluing it in your next Christmas tree!

This is what you’ll need:

  • Arduino Uno or Nano
  • WS2812B NeoPixel LED ring/stick/strip
  • Sound Sensor Module with Analog Output (AO)
  • 5V (≥2A) LED SMPS (optional – see notes)

Of course, a couple of the usual prototyping accessories will be required as well.

NeoPixel LEDs are pretty smart minuscule addressable devices, and little effort is needed to set up and run because you need only one I/O of your microcontroller to control them all in a vigorous manner.

Okay, let’s start with this WS2812FX Arduino Example Sketch:

#include <WS2812FX.h> // NeoPixel Library

#define LED_PIN          4  // NeoPixel Control-D4
#define LED_COUNT      8  // NeoPixel Count-8

#define MIN_BRIGHTNESS   1
#define MAX_BRIGHTNESS 128 // Maximum-255
#define THRESHOLD        5

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

uint16_t quietLevel = 0;
uint16_t maxSample = 0;
uint16_t maxSampleEver = 0;
unsigned long timer = 0;

void setup() {

  // Initial audio measurements to establish the quiet level
  for (int i = 0; i < 20; i++) {
    quietLevel += analogRead(A0); // 0-1023
  quietLevel /= 20;
  Serial.print("\nquietLevel is "); Serial.println(quietLevel);


  // Parameters: index, start, stop, mode, color, speed, reverse
  ws2812fx.setSegment(0,  0,  LED_COUNT - 1, FX_MODE_STATIC, GREEN, 8000, NO_OPTIONS);


void loop() {
  // Take an audio sample
  uint16_t audioSample = abs(analogRead(A0) - quietLevel);//Audio Input-A0
  if (audioSample > maxSample) maxSample = audioSample;

  // if the timer has expired, use the sampled audio to recalculate the LED brightness
  if (millis() > timer) {
    if (maxSample > THRESHOLD) { // ensure the audio is above the threshold to reduce LED flickering
      if (maxSample > maxSampleEver) maxSampleEver = maxSample;

      // Calculate a new brightness, properly scaled to the sampled audio
      uint8_t newBrightness = map(maxSample, THRESHOLD, maxSampleEver, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
      //    Serial.print("maxSample:");Serial.print(maxSample); // debug
      //    Serial.print(", maxSampleEver:");Serial.print(maxSampleEver);
      //    Serial.print(", newBrightness:");Serial.println(newBrightness);
    } else {

    maxSample = 0;
    timer = millis() + 100; // Recalculate brightness every 100ms


As you might be observed, the above example code is backed by a dedicated Arduino NeoPixel Library “WS2812FX”. This library offers a variety of lighting effects for the WS281x /NeoPixel LEDs. It is meant to be a drop-in replacement for the Adafruit NeoPixel library with additional features.

You can search for “WS2812FX” in the Arduino Library Manager or download and install the latest version manually through this GitHub link https://github.com/kitesurfer1404/WS2812FX/archive/refs/heads/master.zip

A WS2812-8 addressable RGB LED stick is picked here for the experiments because it’s the only addressable LED module ready to hand at that time. Note that these compact 8-LED addressable sticks can easily be daisy-chained to make more bombastic displays.

The sound sensor module provides an easy way to detect sound and is generally used for detecting sound intensity. It uses an electret condenser microphone (ECM) and an appropriate microphone preamplifier to deliver a sensible audio signal output for further processing by external electronic circuitry. In a simple manner, a sound sensor module detects sound waves and converting them to electrical signals.

This is the schematic of the quite popular “SparkFun Electret Microphone Breakout” which couples an Electret microphone (100Hz–10kHz) with a 60x microphone preamplifier (https://learn.sparkfun.com/tutorials/electret-mic-breakout-board-hookup-guide).

Let’s get back to the project. Below is the Arduino Uno hardware setup diagram. At this point, note that a Grove Sound Sensor module is used as the sound detector, though it is not very critical (feel free to use your trusty one).

As a word of warning, the Arduino Uno features a number of power input options – DC In/USB/Vin/5V. The 5V pin outputs a regulated 5VDC from the voltage regulator on the board. This pin can be supplied with power either from the DC barrel adaptor, the USB connector, or the Vin pin of the board. You can supply regulated 5VDC via the 5V pin too, however, this bypasses the onboard regulator and protection features, and can damage your board!

If you only need to power a single WS2812-8 LED stick, you can actually get away with using only the Arduino. The USB plugged into your computer can provide 500mA of power. I wouldn’t recommend using much more than 400mA but it is enough to neatly power the entire hardware setup described above. To power additional LEDs, you will need a quality external 5VDC power source.

A parting thought!

Honestly, you should spend considerable time studying the WS2812FX library and changing its examples, but it will be worthful. Anyway, here’s another Arduino code (Originally prepared for NeoPixel Rings/Wheels) that can be used for the same Arduino audio-reactive pixel setup. You only need to alter the noise level (# 1 noise level 255) in the code to match your specific sound sensor module, that’s all.

#include <Adafruit_NeoPixel.h>

#define MIC A0 // Audio In = A0
#define LED_PIN 4 // NeoPixel DI = D4
#define N_PIXELS 8 // Total Pixels = 8
#define N 100 // Total Samples
#define fadeDelay 10 // Fade Amount
#define noiseLevel 255 // See Note!

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);

int samples[N];
int periodFactor = 0;
int t1 = -1;
int T;
int slope;
byte periodChanged = 0;

void setup() {

void loop() {

void Samples() {
  for (int i = 0; i < N; i++) {
    samples[i] = analogRead(0);
    if (i > 0) {
      slope = samples[i] - samples[i - 1];
    else {
      slope = samples[i] - samples[N - 1];

    if (abs(slope) > noiseLevel) {
      if (slope < 0) {
        if (periodChanged == 1) {
    else {
    periodFactor += 1;

void calculatePeriod(int i) {
  if (t1 == -1) {

    t1 = i;
  else {

    int period = periodFactor * (i - t1);
    periodChanged = T == period ? 0 : 1;
    T = period;
    t1 = i;
    periodFactor = 0;

uint32_t getColor(int period) {
  if (period == -1)
    return Wheel(0);
  else if (period > 400)
    return Wheel(5);
    return Wheel(map(-1 * period, -400, -1, 50, 255));

void fadeOut()
  for (int i = 0; i < 5; i++) {
    strip.setBrightness(110 - i * 20);
    strip.show(); // Update strip
    periodFactor += fadeDelay;

void fadeIn() {

  for (int i = 0; i < 5; i++) {
    //strip.setBrightness(20*i + 30);
    periodFactor += fadeDelay;

void ledsOff() {
  for (int i = 0; i < N_PIXELS; i++) {
    strip.setPixelColor(i, 0, 0, 0);

void displayColor(uint32_t color) {
  for (int i = 0; i < N_PIXELS; i++) {
    strip.setPixelColor(i, color);

uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {

    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  else if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);

Finally, While this project didn’t gain as much beauty as I thought it might have, I found it worthwhile all the same. Okay, now improve your prototype by adding new features and functionalities to the hardware and software. And get festive with some sound reactive pixels!

Leave a Comment X