Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Sunny Zhao
Published © GPL3+

5 Minutes to Create a Sound Volume Reminder

Create a sound volume reminder with Grove Beginner Kit & Grove - WS2813 RGB LED Strip

BeginnerFull instructions provided1 hour159
5 Minutes to Create a Sound Volume Reminder

Things used in this project

Story

Read more

Schematics

Sound Volume Reminder_Schematic

Code

Arduino_Sound Volume Reminder

Arduino
// test code for Grove - Sound Sensor
// loovee @ 2016-8-30
#include "Adafruit_NeoPixel.h"
#ifdef __AVR__
  #include <avr/power.h>
#endif  
#define PIN    6  
#define NUMPIXELS 30
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
 
const int pinAdc = A2;
 
void setup()
{
  Serial.begin(115200);
    //Serial.println("Grove - Sound Sensor Test...");
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code
  pixels.setBrightness(255);
  pixels.begin(); // This initializes the NeoPixel library.
}
 
void loop()
{
    long sum = 0;
    long f_sum = 0;
    for(int m=0; m<100; m++)
    {
        for(int i=0; i<32; i++)
        {
        sum += analogRead(pinAdc);
        }
      sum >>= 5;
      f_sum += sum;
      
      }
     sum = (f_sum/100);
    
     if ((sum < 110)) {
        for(int i=0;i<NUMPIXELS;i++){
 
        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(0,255,0)); // Moderately bright green color.
        pixels.show(); // This sends the updated pixel color to the hardware.

 
      }
  }    

if ((((sum < 200)) && ((100 < sum)))) {
    for(int i=0;i<NUMPIXELS;i++){
 
        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(128,255,0)); // Moderately bright green color.
        pixels.show(); // This sends the updated pixel color to the hardware.

      }
      delay(100);
  }

  if ((((sum < 300)) && ((200 < sum)))) {
    for(int i=0;i<NUMPIXELS;i++){
 
        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(255,255,0)); // Moderately bright green color.
        pixels.show(); // This sends the updated pixel color to the hardware.

      }
      delay(100);
  }

    if ((((sum < 400)) && ((300 < sum)))) {
    for(int i=0;i<NUMPIXELS;i++){
 
        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(255,128,0)); // Moderately bright green color.
        pixels.show(); // This sends the updated pixel color to the hardware.

      }
      delay(100);
  }
  
  if ((((sum < 500)) && ((400 < sum)))) {
    for(int i=0;i<NUMPIXELS;i++){
 
        // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
        pixels.setPixelColor(i, pixels.Color(255,0,0)); // Moderately bright green color.
        pixels.show(); // This sends the updated pixel color to the hardware.

      }
      delay(100);
  }
    
    Serial.println(sum);
    delay(100);
}

Credits

Sunny Zhao
1 project • 0 followers

Comments