Introduction: Rapunzel's Magic Brush

This is a hair brush that lights up and plays music when its owner or its owner's friends get close to it or shake it. It also senses light, and turns on a red indicator when it's dark outside. This magical hair brush will never get lost!


Step 1: Summary

There are three major parts to creating a wonderful Tangled-themed brush. The main components are a LilyPad Arduino circuit, LED photoresistor circuit, and the brush itself. You may follow these instructions in the order they are presented. 

Step 2: Arduino Circuit

Materials

• 1 speaker or 1 piezo
• 1 LilyPad Arduino w/ ATmega 328 with the right cables to connect to the computer
• 2” of female headers
• 10 LEDs
• 1 ft of wire
• Solder

Procedure

Step 1:
Download and install the Arduino software.  Open Arduino and use the http://www.sparkfun.com/tutorial/AIK/ARDX-EG-SPAR-WEB.pdf to practice creating CIRC-06 “Piezo elements.”

Step 2:
Open Arduino and go to file>examples>digital>button. Set up the Arduino, the LED, and the button as is instructed in the comments. Try to compile your code, connect your arduino to the computer, and upload the code to your Arduino board using ctrl U. Tip: Go to tools>board and tools>serial port to make sure the right options have been selected. In this case you be using the LilyPad Arduino w/ ATmega 328 and the COM for whichever port you have plugged your Arduino to.

Step 3:
Now you are prepared to create your own circuit. We are going to make a combination of both examples into a cooler one. The point is to make all the LEDs light up when the Arduino is playing music, and to make it play music only when triggered to do so. Here for pin 2, instead of using a button, we will only us a wire that will work as an antenna, sensing either human capacitance or motion. For pins 3-8 and 10-13 we will connect LEDs that will be connected to ground. The speaker will maintain its connection from pin 9 to ground. Finally, power (the 3V battery) should be plugged in from + to -. Tip: in order to make all the connections robust it is effective to use a female header that has been soldered in the bottom (to connect all of its pins). If you connect this header to ground, and then plug in the ground for each LED, the speaker, and power to it, debugging will be a much easier task.

Step 4:
Copy paste this code to Arduino, compile it, and upload it to your board.
/* Melody
* (cleft) 2005 D. Cuartielles for K3
*
* This example uses a piezo speaker to play melodies.  It sends
* a square wave of the appropriate frequency to the piezo, generating
* the corresponding tone.
*
* The calculation of the tones is made following the mathematical
* operation:
*
*       timeHigh = period / 2 = 1 / (2 * toneFrequency)
*
* where the different tones are described as in the table:
*
* note  frequency  period  timeHigh
* c          261 Hz          3830  1915 
* d          294 Hz          3400  1700 
* e          329 Hz          3038  1519 
* f          349 Hz          2864  1432 
* g          392 Hz          2550  1275 
* a          440 Hz          2272  1136 
* b          493 Hz          2028 1014
* C         523 Hz         1912  956
*
* http://www.arduino.cc/en/Tutorial/Melody
*/

int speakerPin = 9;
int ledPin1= 3;
int ledPin2= 4;
int ledPin3= 5;
int ledPin4= 6;
int ledPin5= 7;
int ledPin6= 8;
int ledPin7= 10;
int ledPin8= 11;
int ledPin9= 12;
int ledPin0= 13;
const int buttonPin = 2;
int buttonState = 0; //must declare variables

int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, HIGH);
      digitalWrite(ledPin5, HIGH);
      digitalWrite(ledPin6, HIGH);
      digitalWrite(ledPin7, HIGH);
      digitalWrite(ledPin8, HIGH);
      digitalWrite(ledPin9, HIGH);
      digitalWrite(ledPin0, HIGH);   
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);
      digitalWrite(ledPin9, LOW);
      digitalWrite(ledPin0, LOW); 
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin0, OUTPUT);
}

void loop() {
  buttonState= digitalRead(buttonPin);
  while(buttonState==HIGH){
    for (int i = 0; i < length; i++) {
      if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
       buttonState= digitalRead(buttonPin);
    }
      else {
      playNote(notes[i], beats[i] * tempo);
       buttonState= digitalRead(buttonPin);
    }}
      digitalWrite(speakerPin, HIGH);
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, HIGH);
      digitalWrite(ledPin5, HIGH);
      digitalWrite(ledPin6, HIGH);
      digitalWrite(ledPin7, HIGH);
      digitalWrite(ledPin8, HIGH);
      digitalWrite(ledPin9, HIGH);
      digitalWrite(ledPin0, HIGH);     
  }
  while(buttonState==LOW) {
    digitalWrite(speakerPin, LOW);
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      digitalWrite(ledPin6, LOW);
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, LOW);
      digitalWrite(ledPin9, LOW);
      digitalWrite(ledPin0, LOW);   
     buttonState= digitalRead(buttonPin);
  }
}

Step 5:
Test your circuit! Try touching the antenna and see if it lights up and starts playing Twinkle Twinkle Little Star.


Step 3: Photoresitor Circuit

Materials
• 1 photoresistor
• 1 LED
• 1 470 ohm resistor
• 1 100k ohm resistor
• 1 2N3904 MOSFET
• 1 3V watch battery
• 3” of female headers
• 2 drops of hot glue
• solder
• 2 2” pieces of wire
• Electric tape

Procedure

Step 1:
Access this website and try make the circuit they have work. You do not need 12V, because 3V will work just fine. http://www.alpharubicon.com/elect/autoled2many.htm. Debugging tip: If the LED is not turning on when it’s dark, try changing power with ground; don’t forget to change the direction of the LED as well!

Step 2:
Make a miniature breadboard using female headers. You should have at least 3 3-pin sets and 2 2-pin set. By pin set, I mean pins that are soldered together. Once you have those, use hot glue to attach them. Then, you should be able to connect accordingly. Transfer from your breadboard to the mini breadboard.

Step 3:
Cover the battery and the bottom parts of the circuit with electric tape. Because we are going to put this circuit next to the LilyPad circuit later on, it should be well-insulated. Test your circuit by covering the photoresistor and seeing if the LED turns on!





Step 4: Brush

Materials
• Ouchless Paddle Brush
• 5 little Sugru bags
• Acrylic Paint
• Paint brushes
• Knife or whichever tool you can use to deconstruct the brush
• Hot glue
• String
• Beads

Procedure

Step 1:
Buy an ouchless brush like the one shown in this website: http://www.goody.com/#/grid/ouchless/products/ouchless_paddle_brush.
Step 2:
Use a knife to remove the top of the brush. Here you can see the top that was recently removed next to the brush.

Step 3:
Find something from the Disney movie Tangled that you would like to paint on the brush. Use the paint and paint brushes to do so and let it dry.

Step 4:
Place both circuits inside the brush, and make sure the work. Using only two drops of hot glue, attach the top back on. You should have a fully functional brush by now!

Step 5:
Drill a hole on the bottom of the handle and decorate it with string and beads. Use sugru to add a more comfortable handle!






Step 5: You Are Done!

Test your brush! It senses distance and movement!

 http://www.youtube.com/watch?v=YQUZQhxwrso&feature=colike

Arduino Challenge

Participated in the
Arduino Challenge

Make It Real Challenge

Participated in the
Make It Real Challenge