Introduction: Arduino RGB LED & Piezo Music Sync

Have you ever wanted to get the timing of the color of an RGB LED to sync with your piezo notes? If so, this is the Instructable for you! This project was designed by Rachelle Tan and Emily Brooks as part of the Physical Computing and Fabrication course at the Digital Humanities Summer Institute 2016 at the University of Victoria. The elements included were an origami heart box that opened to reveal a big red button that when pressed started a rainbow LED display that syncs with the first stanza of "What the World Needs Now" by Hal David and Burt Bacharach. I have included our Arduino files and a diagram to help you replicate the project. I would love to see how you use and modify this tutorial!

Step 1: Parts Needed

For this project you will need:

(1) Computer/Laptop with Arduino software downloaded

(1) Arduino Uno

(1) USB cable

(1) Breadboard

(1) RGB LED

(1) Piezo

(4) Resistors

(10) Jumper cables

(1) Big Red Button (not pictured)

(2) Alligator clips (not pictured)

Step 2: Start Arduino Sketch

To start you new sketch:

  1. Open Arduino
  2. Go to File > New
  3. Go to File > Save and name your sketch folder
  4. Declare your variables as int (integers)
  5. Make arrays[] for melody, note durations, and the red, green, and blue values
  6. In void setup(), set your pinMode for the RGB pins as OUTPUT and for the button as INPUT
  7. In void loop(), use digitalRead to read the value of whether the button has been pressed or not to determine if the tone should be played

(Links are connected to Arduino Reference pages)

Step 3: Include Pitches Library

To include the pitches.h library:

  1. Write #include "pitches.h" at the top of your code
  2. Click the down arrow to the right on the IDE> click New Tab
  3. Name the new file pitches.h
  4. Copy and paste the values in pitches.h
  5. Save file

Step 4: Finish Code

In order to finish the code:

  1. Determine what colors and order you want for your array. Make arrays for R, G, and B values on scales of 0-255 (Red = 255,0,0; Orange = 255,165,0; Yellow= 255,255,0; Green= 0,255,0; Teal= 0,255,255; Blue= 0,0,255; Violet= 255,0,255)
  2. Read your sheet music and translate into usable data (C4=middle of piano/treble clef, 4=quarter note)
  3. Write a function to analogWrite values to each pin of the RGB LED

Find finished code attached to this tutorial.

Step 5: Assemble Prototype

To assemble your prototype:

  1. Orient your breadboard and Arduino next to each other
  2. Carefully plug the leads of the piezo, RGB LED, and button into the breadboard as shown in the diagram (we used alligator clips to connect the button)
  3. Plug in the resistors of the RGB LED pins
  4. Use jumper cables to connect the parts to the Arduino pins based on the pin numbers you declared in your code

Step 6: Run Code and Enjoy!

To complete the project:

  1. Connect your Arduino to your computer/laptop via USB cable
  2. Verify your code by hitting the checkmark in the top left hand corner
  3. Go to Tools > Board and select Arduino Uno
  4. Go to Tools > Serial Port and ensure that your laptop is recognizing that you have connected your Arduino
  5. Click the right arrow (Upload) and enjoy the efforts of all of your hard work!

Comments

author
scratchndent (author)2017-02-14

Arduino: 1.6.10 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/----/Downloads/RGB_Piezo/RGB_Piezo.ino:10:21: fatal error: pitches.h: No such file or directory
#include "pitches.h"
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

why am i getting this when i try to upload even though pitches.h file is there and open

author
Makeademic (author)scratchndent2017-02-14

Hi @scratchndent, it looks to me like you're opening a file from the Downloads folder and need to move it to your Arduino sketch folders. Check out this site for more info: https://programmingelectronics.com/understanding-the-arduino-sketchbook-opening-and-saving-arduino-sketches/

author
hasham99900999 (author)2016-11-09

very nice ))))))))

About This Instructable

1,611views

16favorites

License:

Bio: Scholar. Instructor. Web & Graphic Designer. Editor. Maker. Hacker. Photographer. TV Watcher. Baker. Florida Gator.
More by Makeademic:Light-Up Jack-o-Lantern CostumeArduino RGB LED & Piezo Music SyncAmbrosia Flatbread
Add instructable to: