Arduino MusicStump: Light, Captive Touch and a Buzzer

94

2

1

Posted

Introduction: Arduino MusicStump: Light, Captive Touch and a Buzzer

An interactive tree with an LED ring at the top, a buzzer to make sound and a captive touch sensor inside that changes the color as you touch it. To make this fun little thing you'll need the following:

Electronics:
- 1x Arduino Uno

- 15x cables

- 1x soldering iron with a round tip

- 1x Adafruit 8-key captive touch (CAP1188)

- 1x Arduino power cable

- 1x 8 LED ring

- 1x Buzzer

- 1x hot glue gun

- Download the library of CAP1188 https://learn.adafruit.com/adafruit-cap1188-breako...

- Download the library of Adafruit Neopixel https://github.com/adafruit/Adafruit_NeoPixel

Extra (casing):

- 1x tree stump

- 1x stick for inside

- wooden platter to place it all on/in

- Stuffed animal stuffing for the outside

You can also use something else as outside, be creative!

Now let's begin...

Step 1: Step 1: LED Ring With Captive Touch

Now if you're lucky your LED ring already has pins attached to it. If not it is time to solder!

The things we'll be using for this project are:

- DI (Digital input, pin 6~

- 5V (for power, 5V pin)

- GND (The ground, GND pin)

That's the LED ring for now.

Now the captive touch.

Place it in a breadboard and connect everything as follows:

SDA/MISO in pin (analog in) A4
SCK in pin (analog in) A5
VIN in (power) 5V
GND in a GND pin
1x cable at C1 (on the Captive touch itself)

Now to test upload the following code to your Arduino:

// Julia Emmink
// Light and touch code for the interactive tree 19/01/2018 // Made with the use of the Adafruit Neopixel and Adafruit captive touch (CAP1188) (is to be installed) and the LED blinking with no delay

// NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include

#define PIXELSPIN 6 // Where you connected the LED Ring #define NUMPIXELS 8 //The ammount of LEDs that are on your ring #define CALIBRATIONTIME 20000

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELSPIN, NEO_GRB + NEO_KHZ800);

unsigned long pixelsInterval = 500; // the time we need to wait unsigned long colorWipePreviousMillis = 0; unsigned long theaterChasePreviousMillis = 0; unsigned long rainbowPreviousMillis = 0; unsigned long rainbowCyclesPreviousMillis = 0;

int theaterChaseQ = 0;

uint16_t currentPixel = 0;// what pixel are we operating on

// TOUCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #include #include

// Reset Pin is used for I2C or SPI #define CAP1188_RESET 9

// CS pin is used for software or hardware SPI #define CAP1188_CS 10

// These are defined for software SPI, for hardware SPI, check your // board's SPI pins in the Arduino documentation #define CAP1188_MOSI 11 #define CAP1188_MISO 12 #define CAP1188_CLK 13

// Use I2C, no reset pin! Adafruit_CAP1188 cap = Adafruit_CAP1188();

void setup() { // NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ currentPixel = 0; pixels.begin(); // This initializes the NeoPixel library. pixels.show(); // This sends the updated pixel color to the hardware.

// TOUCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Serial.begin(300); Serial.println("CAP1188 test!");

if (!cap.begin()) { Serial.println("CAP1188 not found"); while (1); } Serial.println("CAP1188 found!"); }

void loop () { // TOUCH + NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uint8_t touched = cap.touched(); if (touched == 0) { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(0, 255, 125)); } } else { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(100, 0, 150)); } }

}

void colorWipe(uint32_t c) { // NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Gets rid of the color pixels.setPixelColor(currentPixel, c); pixels.setPixelColor(currentPixel - 1, pixels.Color(0, 0, 0)); pixels.show(); currentPixel++; if (currentPixel == NUMPIXELS) { currentPixel = 0; pixels.setPixelColor(7, pixels.Color(0, 0, 0));

} }

Test it and have fun! As you see when you touch the C1 cord the color changes. (If it doesn't the first time just unplug your Arduino and plug it back into your computer.)

Step 2: Step 2: Adding Sound!

With the use of a handy tutorial I made this. The tutorial is bellow:

https://github.com/xitangg/-Pirates-of-the-Caribbe...

Time to grab your buzzer! Put the (-) of the buzzer in one of the GND pins and the (+) in pin 10~

That's about it, now time to run the code again and hear that lovely Pirates of the Caribbean tune! Now have fun testing!

// Julia Emmink
// Light, touch and music code for the interactive tree 19/01/2018
// Made with the use of the Adafruit Neopixel and Captive Touch (CAP1188) (is to be installed) and the LED blinking with no delay


// NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include

#define PIXELSPIN 6 #define NUMPIXELS 8 #define CALIBRATIONTIME 20000

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELSPIN, NEO_GRB + NEO_KHZ800);

unsigned long pixelsInterval=500; // the time we need to wait unsigned long colorWipePreviousMillis=0; unsigned long theaterChasePreviousMillis=0; unsigned long rainbowPreviousMillis=0; unsigned long rainbowCyclesPreviousMillis=0;

int theaterChaseQ = 0;

uint16_t currentPixel = 0;// what pixel are we operating on

// MUSIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const int buzzer = 10; //Define pin 10, can use other PWM pins (5,6 or 9) //Note pins 3 and 11 can't be used when using the tone function in Arduino Uno const int songspeed = 1.5; //Change to 2 for a slower version of the song, the bigger the number the slower the song //***************************************** #define NOTE_C4 262 //Defining note frequency #define NOTE_D4 294 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_G4 392 #define NOTE_A4 440 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_D5 587 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_G5 784 #define NOTE_A5 880 #define NOTE_B5 988 //***************************************** int notes[] = { //Note of the song, 0 is a rest/pulse NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0, NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0, NOTE_A4, NOTE_G4, NOTE_A4, 0 }; //***************************************** int duration[] = { //duration of each note (in ms) Quarter Note is set to 250 ms 125, 125, 250, 125, 125, 125, 125, 250, 125, 125, 125, 125, 250, 125, 125, 125, 125, 375, 125 };

// TOUCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include #include #include

// Reset Pin is used for I2C or SPI #define CAP1188_RESET 9

// CS pin is used for software or hardware SPI #define CAP1188_CS 10

// These are defined for software SPI, for hardware SPI, check your // board's SPI pins in the Arduino documentation #define CAP1188_MOSI 11 #define CAP1188_MISO 12 #define CAP1188_CLK 13

// Use I2C, no reset pin! Adafruit_CAP1188 cap = Adafruit_CAP1188();

void setup() { // MUSIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for (int i=0;i<203;i++){ //203 is the total number of music notes in the song int wait = duration[i] * songspeed; tone(buzzer,notes[i],wait); //tone(pin,frequency,duration) ;} //delay is used so it doesn't go to the next loop before tone is finished playing //You can click reset on Arduino to replay the song // NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ currentPixel = 0; pixels.begin(); // This initializes the NeoPixel library. pixels.show(); // This sends the updated pixel color to the hardware.

// TOUCH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Serial.begin(300); Serial.println("CAP1188 test!"); if (!cap.begin()) { Serial.println("CAP1188 not found"); while (1); } Serial.println("CAP1188 found!");

}

void loop () { // TOUCH + NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uint8_t touched = cap.touched(); if (touched == 0) { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(0,255,125)); } } else { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(100,0,150)); } }

for (int i=0;i<19;i++){ //203 is the total number of music notes in the song //int iSecond = duration[i] int wait = duration[i] * songspeed; tone(buzzer,notes[i],wait); if (touched == 0) { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(0,255,125)); } } else { if ((unsigned long)(millis() - colorWipePreviousMillis) >= pixelsInterval) { colorWipePreviousMillis = millis(); colorWipe(pixels.Color(100,0,150)); }}

delay(wait);

} }

void colorWipe(uint32_t c){ // NEOPIXEL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Gets rid of the color pixels.setPixelColor(currentPixel,c); pixels.setPixelColor(currentPixel-1,pixels.Color(0,0,0)); pixels.show(); currentPixel++; if(currentPixel == NUMPIXELS){ currentPixel = 0; pixels.setPixelColor(7,pixels.Color(0,0,0));

} }

Step 3: Additional Step: Making the Stump 'Arduino Ready'

If you do decide to use a tree stump you have to do the following.

  • Get a tree stump (I got one from an old Christmas tree for free)
  • Measure your Arduino and see how you want to have the wiring in the tree stump
  • Hollow out the stump (I used a drill machine from school)
  • Sand the rough edges off
  • Add fun small details

Details I added was a small logo that I made with a laser cutter. I also stacked all my electronics inside on a stick inside my tree and I added stuffed animal stuffing on the outside to let the light through and give that small extra softness.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Spotless Contest

      Spotless Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments