Introduction: Pebbles the Sleepytime Bear

Picture of Pebbles the Sleepytime Bear

Alright Welcome to the instructable of creating pebbles the sleepytime bear!
I made this project for a assignment I had for school called "HKU" which stands for "Hogeschool voor de Kunsten Utrecht" in english "Highschool of the Arts Utrecht" Which is a little bit funny since it actually is a Bachelor University with multiple Masters.

Anyway

ON TO THE STEPS!

Step 1: Checking Necessary Materials

Picture of Checking Necessary Materials

Starting with the board we will have to get all the right components

- 1x Arduino Uno
- 1x Breadboard BIG
- 1x Breadboard Extra Small
- 4x Buzzer 3-24 Volt
- 14 Koper Kabels
- 1x 100w Resistor
- 1X Push Button Set

Once we have done that its up to the next step!

Step 2: Designing the Arduino Uno Hardware

Picture of Designing the Arduino Uno Hardware

I started with hooking up the Buzzers first.
For ease and having it as 1 component I took the Tiny Breadboard (Extra Small), and put them on the breadboard. Together with the power and the port cables I connected them all in a matter, so I knew which color belonged to what Buzzer.

Next up I took the Large Breadboard (I know.. Such an overkill)
I put the button on it and started connecting the resistors(its a 100 Ohm Resistor)
And connected both port ground and power to it.

Step 3: Putting the Arduino Together

Picture of Putting the Arduino Together

I used a slightly different buzzer in the pictures but its basically the same one.
As you can see I hooked up the buzzer without a resistor since a resistor will tone down the volume by a large margin. All power cables go into the big breadboard where it gets 5v and Ground if necessary

Materials

  • Arduino Uno
  • 4x Buzzer 3-24 Volt
  • 1x Tiny Breadboard (Extra Small)
  • 8x Copper Cables

Step 4: Putting the Arduino Together P2.

Picture of Putting the Arduino Together P2.

As you can see the button on the Large Breadboard is the same as the schematic I drew out in my design.

It also goes towards the Arduino so it can be used in the future of this Instructable

For this part you will be needing:

Material

  • 1x Breadboard BIG

  • 1X Push Button

  • 1X Resistor

  • 5x Copper Cables

Step 5: Coding the Arduino

So now we are off to be coding the buzzers and the button, trying to make all 4 buzzers play when we push the button.

First thing I do is create an array with multiple usable frequencies for the notes:

int noteFreqArr[] = {<br>49.4, 52.3, 55.4, 58.7, 62.2, 65.1, 69.9, 73.42, 78.4, 82.41,
88, 93.2,98.8, 105, 110, 117, 124, 132, 140, 148,
157, 166, 176, 186,198, 209, 222, 235, 249, 264,
279, 296, 314, 332, 349.23, 373,395, 419, 440.00, 470,
498, 527, 523.25, 587.33, 627, 659.25, 698.46, 746,784, 837,
887, 940, 996, 1050, 1110, 1180, 1250, 1320, 1400, 1490,
1580, 1670, 1770, 1870, 1990, 2100<br>};

Next up, I will be creating the Setup() function.
With this, I will be checking which port is what component.
If it's an output or input.

void setup() {
    pinMode(4, OUTPUT); // set a pin for buzzer output
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, INPUT);
}

In the next part, I will be creating a playNote function that will withhold the Note, Length of the note and the breath it can take.
Breath = A pause between notes (Taking a breath) we will use this so we don't have to use a delay between our playNote function.

void playNote(int noteInt, long length, long breath = 0) {<br>    length = length - breath;
    buzz( 4, 5, 6, 7, noteFreqArr[noteInt], length);
    if(breath > 0) { //take a short pause or 'breath' if specified
        delay(breath);
    }
}

Next we will creating the buzz() function which will hold the inputs and outputs.
The delay timer towards seconds and the length of the frequencies.

void buzz(int targetPin, int targetPin1, int targetPin2, int targetPin3, long frequency, long length) {<br>    long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
    //// 1 second's worth of microseconds, divided by the frequency, then split in half since
    //// there are two phases to each cycle
    long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
    //// multiply frequency, which is really cycles per second, by the number of seconds to
    //// get the total number of cycles to produce
    for (long i=0; i < numCycles; i++){ // for the calculated length of time...
        digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
        digitalWrite(targetPin1,HIGH); // write the buzzer pin high to push out the diaphram
        digitalWrite(targetPin2,HIGH); // write the buzzer pin high to push out the diaphram
        digitalWrite(targetPin3,HIGH); // write the buzzer pin high to push out the diaphram
        delayMicroseconds(delayValue); // wait for the calculated delay value
        digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
        digitalWrite(targetPin1,LOW);
        digitalWrite(targetPin2,LOW);
        digitalWrite(targetPin3,LOW);
        delayMicroseconds(delayValue); // wait againf or the calculated delay value
    }
}

And last but not least, setting up the notes I want to work with.
Looking back at the array we made, its much easier to set different frequencies. Since I stored those, I can put an "int" in the function and it will actually go towards the array and play that note.

void loop() {
 if(digitalRead(8) == HIGH ){
    playNote(47, 500, 100);
    playNote(48, 1000, 25);
    playNote(47, 1000, 25);
    playNote(46, 500, 100);
    playNote(43, 1000, 25);
    playNote(44, 1000, 25);
    playNote(47, 1000, 25);
    playNote(48, 1000, 25);
    playNote(47, 1000, 25);
    playNote(43, 1000, 25);
    playNote(44, 500, 100);
    playNote(38, 500, 100);
    playNote(47, 500, 100);
    playNote(48, 1000, 25);
    playNote(47, 1000, 25);
    playNote(46, 500, 100);
    playNote(43, 1000, 25);
    playNote(44, 1000, 25);
    playNote(47, 1000, 25);
    playNote(48, 1000, 25);
    playNote(47, 1000, 25);
    playNote(43, 1000, 25);
    playNote(44, 500, 100);
    playNote(35, 2000, 200);
    playNote(27, 500, 100);
    playNote(22, 500, 100);
    playNote(25, 500, 100);
    playNote(24, 500, 100);
    delay(1000); // wait a bit between buzzes
    }
}

Parts of this code comes from Rob Faludi on faludi.com it has helped me a great deal, My own code had some errors with the frequencies and this one helped me a lot figuring out how to make it work.

Step 6: IT WORKS!

Picture of IT WORKS!

Now lets put this Arduino into the bear and it ready to be used.

Now you can easily put your children to sleep! Just make your kid hug it and it will play the tune you want
I chose a song from the Dutch Amusement Park attraction called "Vila Volta", well I tried at least haha.

Hope you enjoyed this Instructable and see you next time :D

Step 7: Video!

Comments

mrsmerwin (author)2017-08-14

How do you get it into the bear in such a way that hugging will hit the stitch?

About This Instructable

133views

1favorite

License:

More by FeliciaN6:Pebbles the Sleepytime BearArduino Uno: Pebbles the Screaming Bear.
Add instructable to: