Hit'n'Blink

Hit'n'Blink © GPL3+

LED patterns triggered by beats (physical force, NOT sound)

  • 499 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

About this project

What is it about ?

In case a mechanical force (e.g., a "beat") hits a simple piezo sensor, an LED color pattern is lit. Brightness depends on how hard the beat hits the piezo sensor. LED color pattern can be selected by turning a potentiometer.

What made me to do this ?

As so often, there's not only a single cause...

Curiosity: Can I successfully implement the component I bought into an Arduino project ?

Family business: Can I support my little son's desire to "help" me in an Arduino project ?

Challenge: Can I make up a project that supports my son's above mentioned whish AND convinces him (once more), that playing around with Arduino is fun ?

Education: Last but not least I hoped to stimulate my son's practicing simple drum patterns for music school.

How did I do it ?

Mechanics

First a word on the "housing". My son decided to get rid of his bug eye viewer ("Becherlupe"). That seemed to just perfect to me, cause in my experience manufacturing of a nice containment is one of the most challenging parts in Arduino projects.

Hardware

A piezo sensor (output voltage changes depending on applied mechanical force) is connected to an analog input of an Arduino Nano. In case the signal from that piezo sensor increases above a defineable threshhold

  • its strength is determined and used to set the brightness of the connected LEDs (LED ring at bottom of bug eye viewer and LED strip along outer circumference).
  • a counter is increased and depending on that counter a red, yellow or green LED (connected to 3 digital outputs of the Arduino Nano) is lit for a short time.

The color pattern of those LEDs is determined depending on the resistance across a potentiometer (connected to another analog input of the Arduino Nano).

The three single LEDs are lit depending on the number of counts, i.e., how often the piezo sensor threshhold was surpassed. This could serve as a indication how intense someone practiced his drum patternsby simply counting beats ;-). Up to now my experience w/ this tells me not to underestimate the impression red, yellow or even green lights have on children ;-).

Since this thingy should be mobile and safe I decided to use simple AA batteries as power source. Goal is to make sure to be able to supply a stable voltage of >5V to ensure reliable operation of the Arduino Nano. This could be easily achieved, e.g., by using a 9V block battery. However, the WS2812B LEDs on the LED ring and strip used are (as far as I understand information I found in the www) prone to destruction in case the supplied voltage is significantly higher than 5V.

Using 3 x NON-rechargeable AA batteries might be an option, but the nominal max. voltage of 4.5 V might drop during operation leading to unstable operation of the Arduino Nano. 4 x NON rechargeable AA batteries will (at least initially) provide ~6 V, leading to destruction of some of the LEDs.

3 x rechargeable AA batteries will provide a too low voltage (~3, 75 - 3.9 V) for reliable operation of the Arduino Nano. So my final choice were 4 x rechargeable (NiMH) batteries, providing 5 - 5.3 V.

Initially I made the mistake to connect the supplied power to VIn pin of the Arduino Nano. Due to the voltage drop across Arduino's internal voltage regulator the remaining voltage dropped below the limit neede for stable operation of the Arduino Nano.

Finally a few pictures...

Daytime...

...and nighttime...

Code

HitArduino
/*
 * Visualization of drum sticks hitting drum pad
 * LED ring and/or stripe (selectable by external switch, see schematics) w/ selectable
 *  - color pattern (based on input from potentiometer)
 *  - brighntess depends on how hard the drum stick hits the drum pad
 *  Drum stick hitting drum pad is detected by a simple piezo sensor placed underneath the drum pad
 * 
 * Written by T. Geppert, April 2020
 */

/*
 * Constants and alike
 */
// LED stuff =============================================================================
// LED Ring / Stripe ---------------------------------------------------------------------
#include <FastLED.h>
#define NUM_LEDS 24                       // Number of LEDs in ring
#define LED_DATA_PIN 9                   // Data Pin for control of LEDs in strip 1

CRGB leds[NUM_LEDS];                    // create array for LED ring

#define LED_HUE_STD 13                       // STandarD HUE = "color" of LED; 0~red, 32~orange, 64~yellow
#define LED_SAT_STD 255                     // STandarD SATuration = saturation of color of LED; 0~neutral grey, 255~pure color
#define LED_VAL_STD 100 

int LED_HUE = LED_HUE_STD;                  // HUE used for FastLED depending on input conditions
int LED_SAT = LED_SAT_STD;                  // SAT used for FastLED depending on input conditions
int LED_VAL = LED_VAL_STD;                  // VAL used for FastLED depending on input conditions

// LED red/yellow/green ----------------------------------------------------------------------
#define LED_RED_PIN 3
#define LED_YELLOW_PIN 4
#define LED_GREEN_PIN 5

// Vibration sensor =============================================================================
#define VIB_SENS_PIN_1 A1                   // Input from vibration sensor 1
int VibRead_1;

// Other stuff =============================================================================
#define LEDMode_PIN A3
int trigLim = 100;                        // trigger limit for vibration sensor
int beatsCount = 0;                         // counts number of beats (limits for red, yellow, green can be set below)

int beatsRedLim = 192;
int beatsYellowLim = 384;
int beatsGreenLim = 1536;

int switchOnDelay = 2;                   // time  (ms) between switchin on subsequent LEDs

/*
 * Setup ===================================================================================
 */
void setup() {
  Serial.begin(9600);
  FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, NUM_LEDS);    // setup LED ring

  pinMode(LED_DATA_PIN, OUTPUT);
  pinMode(LEDMode_PIN, INPUT);

  pinMode(LED_RED_PIN, OUTPUT);
  pinMode(LED_YELLOW_PIN, OUTPUT);
  pinMode(LED_GREEN_PIN, OUTPUT);

  pinMode(VIB_SENS_PIN_1, INPUT);

}
/*
 * End of Setup ===================================================================================
 */

/*
 * Main Loop ===================================================================================
 */
 
void loop() {
  LED_HUE = LED_HUE_STD;                  // HUE used for FastLED depending on input conditions
  LED_SAT = LED_SAT_STD;                  // SAT used for FastLED depending on input conditions
  LED_VAL = LED_VAL_STD;                  // VAL used for FastLED depending on input conditions

  // Wait until vibration sensor detects something
  VibRead_1 = 0;
  while( VibRead_1 < trigLim ) {
    VibRead_1 = analogRead(VIB_SENS_PIN_1);       // VibRead_1 used as trigger as well as determining brightness of LEDs
//Serial.println("Waiting for input from vibration sensor");
  }

  beatsCount = beatsCount + 1;                    // increase number of beats
  // turn on red, yellow or green LED, depending on number of total beats
  if (beatsCount <= beatsYellowLim) {
    digitalWrite(LED_RED_PIN, HIGH);
  }
  if (beatsCount > beatsYellowLim && beatsCount < beatsGreenLim) {
    digitalWrite(LED_YELLOW_PIN, HIGH);
  }
  if (beatsCount > beatsGreenLim) {
    digitalWrite(LED_GREEN_PIN, HIGH);
  }
  
  LED_VAL = map(VibRead_1, 0, 1023, 0, 255);      // derive brightness values for LEDs from magnitude of vibration
/*Serial.println();
Serial.println(VibRead_1);
Serial.println(LED_VAL);
*/  
/*Serial.print("Vib Sens 1: ");
Serial.print(VibSens_1);
Serial.print(" Vib Read 1: ");
Serial.println(VibRead_1);
*/
  
  int LEDMode = analogRead(LEDMode_PIN);  // value used for selection of color pattern
  
/*Serial.print("LEDMode: ");
Serial.println(LEDMode);
*/

  // set LED HUE etc. depending on input
  if (0 < LEDMode && LEDMode < 250) {
    LED_HUE = 2;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (250 < LEDMode && LEDMode < 500) {
    LED_HUE = 80;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (500 < LEDMode && LEDMode < 700) {
    LED_HUE = 150;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (700 < LEDMode && LEDMode < 1023) {
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(int(192/NUM_LEDS*i), LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }

  //Turn all LEDs OFF
  digitalWrite(LED_RED_PIN, LOW);
  digitalWrite(LED_YELLOW_PIN, LOW);
  digitalWrite(LED_GREEN_PIN, LOW);
  for (int i=0; i<NUM_LEDS; i++) {
    LED_HUE = 0;
    LED_SAT = 0;
    LED_VAL = 0;
    leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
    FastLED.show();
    delay(switchOnDelay);
  }

}
/*
 * End of Main Loop  ===================================================================================
 */

Schematics

Schematics for Hit'n'Blink.

Comments

Similar projects you might like

Arduino Controlled Traffic Lights for Kids Without Delay()

Project showcase by stemmayhem

  • 9,131 views
  • 9 comments
  • 48 respects

Buzz Wire with Score Counter

Project tutorial by behrooz66

  • 12,466 views
  • 27 comments
  • 49 respects

Sezme: A Memory Game for the Arduino

by mariogianota

  • 2,196 views
  • 1 comment
  • 10 respects

Bluetooth Mobile Remote Lamp with Weather Station

Project tutorial by Kutluhan Aktar

  • 2,187 views
  • 1 comment
  • 3 respects

Sound Sensor Activated LEDs with LCD for Sound Level Data!

Project tutorial by HeathenHacks

  • 8,906 views
  • 8 comments
  • 24 respects

Renewing the Nikko Turbo 2 RC Car

Project tutorial by MarcoGPS

  • 4,025 views
  • 2 comments
  • 10 respects
Add projectSign up / Login