Sound Reactive Oneshot Clover

by absolpurple in Circuits > Arduino

130 Views, 0 Favorites, 0 Comments

Sound Reactive Oneshot Clover

IMG_C76EF7942D10-1.jpeg
IMG_8797.JPG
Oneshot Clover - Arduino Project

Hi to whoever found this project!

This Arduino project for school is basically a giant game reference to a small indie title called Oneshot, to sort of celebrate that it got a switch port recently. In this game’s story the three colored clover is a major symbol and I decided to put my own spin on it with a clover made out of a LED strip that reacts to sound, with the color palettes referencing the four areas in the game (as well as a spoiler related palette for those who played the solstice route :).

It’s not a particularly difficult project, and there’s quite a bit of flexibility with the LED colors, so have fun making your own version!

Supplies

What you’ll need

For the basic setup you’ll need the following things:

  • Arduino UNO
  • Breadboard
  • LED Strip (I used the WS2813)
  • Sparkfun Sound sensor (with headers in my case)
  • 4 Jumper cables female-male
  • 8 Jumper cables male-male
  • A resistor (technically optional, I’m using it for safety)


And for the housing of this project you’ll need these:

  • Bell jar
  • Circular box with a lid (should be around the same diameter as the bell jar’s base)
  • Iron wire (should be strong enough to hold up the LED strip without losing its shape)
  • Some glue, tape and double sided tape
  • A drill or something else to make holes in wood
  • Paint (optional)


There are also two websites you can use

The Wiring

Arduino_Wiring.jpg

The wiring for this project is rather straightforward

Connect the 5V Pin on the Arduino to the + row of the breadboard and the GND Pin to the - row.

Attach the 4 female-male jumper cables to the end of the LED strip.

Connect the 5V cable of the LED strip to the + row and the GND cable to the - row.

The WS2813 LED Strip has two cables to control the lights: a main cable and a backup cable. 

Connect them to the beadboard at the same height as the LED Strip’s 5V cable, place a resistor next to them and a cable leading to the 10 Pin on the Arduino.

Finally for the sound detector, VCC goes to the + row, and GND to the - row.

I’m using the ENVELOPE signal of the detector, so connect that to the A0 pin on the Arduino.


The Housing

IMG_8769.JPG
IMG_8770.JPG
IMG_8777.JPG
IMG_8778.JPG
IMG_8779.JPG
IMG_8792.JPG
IMG_8793.jpg
IMG_8795.jpg
IMG_8794.JPG
IMG_8797.JPG

The clover 

Draw your clover shape on a piece of paper, make sure that it stays within the measurements of the bell jar.

Then take a piece of iron wire and twist it to match the shape on the paper.


The base

Draw dots at where the iron wire reaches the base, and then a larger circle around both, big enough for the LED wires to fit through. Then drill them out so you have two holes relatively close together.

Also make a hole in the side of the box, this is where your arduino usb cable can fit through.

Optionally you can paint the base and box, I painted them black using acrylic paint.


Combining the base and clover

Now it’s time to combine everything! Place the arduino and breadboard in the box, with the usb entrance of the arduino facing the hole.

Attach the metal clover to the base using some double sided tape, seal it with some regular tape so nothing else will stick to it. Then attach the base to the lid of the box so the holes overlap.

Peel part of the backing off of the adhesive side of your ledstrip, then pull it through one hole. Start attaching it to the iron wire. 

Peel off more backing as you go. Sometimes you might need to fold the ledstrip a bit to stick to curves. 

If you’re near the end of the iron wire and still have a lot of ledstrip left, cut it at the designated line (be careful to make a clean cut) and then tidy it away. Make sure to count how many leds you have left after cutting!

From here you can place the jar over the clover. That takes care of the housing!

Color Palettes

Color Picker.png
Clover.png
Barrens.png
Glen.png
Refuge.png
Tower.png
Journal.png

Rather than having the Ledstrip just show one plain color, I decided to make color gradients with three colors. I used a color picker to create a baseline for myself and CSS Gradient to make the gradients.


Translating the Palettes into Code

One thing to note is that CSS Gradient works with color positions from 0 to 100, but arduino uses 0 to 255. You can work around this by multiplying the color positions by 2.55.

Coding

Finally it's coding time!

Here is the code I wrote (with a lot of help as I'm really not that great at coding):

//First all the Ledstrip stuff
#include <FastLED.h>
#define NUM_LEDS 34 //After cutting my strip this was the amount of leds
#define LED_PIN 10
#define LEDTYPE WS2813 //Or whichever Ledstrip you're using
#define COLOR_ORDER GRB //Depends on which Ledstrip you're using
#define BRIGHTNESS 40 //60 is a good starting point, but feel free to change it
#define VOLTS 5 //Voltage of your Ledstrip
#define MAX_AMPS 500 //Limit the current to prevent problems


//Then all the Sound Sensor stuff
#define MIC_PIN A0


//Color Palettes
DEFINE_GRADIENT_PALETTE (clover){
0, 135, 6, 6,
64, 226, 40, 5,
120, 12, 218, 20,
185, 28, 82, 147,
255, 3, 10, 55
};


DEFINE_GRADIENT_PALETTE (barrens){
0, 0, 4, 103,
77, 53, 0, 241,
120, 147, 0, 255,
164, 53, 0, 241,
255, 0, 4, 103
};


DEFINE_GRADIENT_PALETTE (glen){
0, 0, 56, 11,
77, 0, 207, 77,
120, 0, 111, 230,
164, 0, 207, 77,
255, 0, 56, 11
};


DEFINE_GRADIENT_PALETTE (refuge){
0, 88, 0, 16,
77, 156, 0, 205,
120, 222, 0, 119,
164, 156, 0, 205,
255, 88, 0, 16
};


DEFINE_GRADIENT_PALETTE (tower){
0, 26, 0, 66,
77, 144, 0, 190,
120, 130, 0, 255,
164, 144, 0, 190,
255, 26, 0, 66
};


DEFINE_GRADIENT_PALETTE (journal){
0, 29, 5, 91,
98, 182, 41, 68,
118, 255, 233, 0,
153, 182, 41, 68,
255, 29, 5, 91
};


//And some setup for the Palettes
CRGBPalette16 currentPalette = glen;
CRGB leds[NUM_LEDS];
uint8_t paletteIndex = 0;
int paletteCounter = 0;

void setup() {
//Pinmodes
pinMode(MIC_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);


// Ledstrip setup
FastLED.addLeds<LEDTYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();


// Mic setup
Serial.begin(9600);


// Which Palette should be shown first
changePalette(0);
}

void loop() {
// put your main code here, to run repeatedly:
fill_palette(leds, NUM_LEDS, paletteIndex, 255 / NUM_LEDS, currentPalette, 255, LINEARBLEND);
FastLED.show();


int sensorData = analogRead(MIC_PIN);
delay (300);
Serial.println(sensorData);

// How much should the mic pick up to change color
if(sensorData > 110){
soundInput();
}
}


void soundInput(){
changePalette(paletteCounter);
paletteCounter++;


if (paletteCounter > 5){
paletteCounter = 0;
}
}


void changePalette(int newMicInput) {
switch(newMicInput){
case 0:
currentPalette = clover;
break;


case 1:
currentPalette = barrens;
break;


case 2:
currentPalette = glen;
break;


case 3:
currentPalette = refuge;
break;


case 4:
currentPalette = tower;
break;


case 5:
currentPalette = journal;
break;


default:
Serial.println("No matching case!"); //This one is for when something goes wrong
break;
}
}


Down below is also the Arduino Sketch I made for this project.

Finished!

IMG_C76EF7942D10-1.jpeg

And that's it! Hope you liked it and/or made your own version, please let me know if you do.