How to Play "Crank Dat" by Soulja Boy on Arduino
by christophersfactory in Circuits > Arduino
755 Views, 0 Favorites, 0 Comments
How to Play "Crank Dat" by Soulja Boy on Arduino
"Crank Dat" by Soulja Boy is arguably the most influential song to human cultural canon in history. This guide will teach you everything you need to learn to make your Arduino play "Crank Dat" on repeat.
Supplies
Wiring
The wiring is very simple. Connect the ground to the ground of your Arduino. Connect the positive to any digital pin -- I will use pin 6.
You may need a resistor. If you're using this type, you will not need one. If you're not sure if you need a resistor or not, try attaching a 1K potentiometer with the resistance on max, then slowly turn the resistance down (and thus the volume up) until your speaker sounds like a rat and a tin can being spun together in a centrifuge.
Code
Arduino knew that its products were destined to play "Crank Dat," so they put in a built-in, super-simple dedicated function for creating tones. The function is as follows:
tone(pin, hertz);
To stop playing a tone on a pin, the function is simply:
noTone(pin);
Using the piano frequency chart, we can deduce that the holy progression of notes to be played is C, G, G#. The notes will be played quickly to mimic the steel drum of our sacred hymn. These notes in frequencies are 523, 391, and 415. "Crank Dat" is played at 140 beats per minute and in 4/4 time signature, which means that there are 140/4 = 35 measures per minute, and one measure every 60/35 = 1.71428571429 seconds. This also means that one beat happens every 1.71428571429 / 4.00 = 0.42857142857 seconds, and thus a quarter note is 1/0.42857142857 *100 = 233.333ms long. I used this to go ahead and set int tempo = 233.
Then, following the sheet music, we can make a rough digitization of the song. I will attach my code both in text here, and as a supporting file to this step.
int tempo = 233;
void setup(){
Serial.begin(9600);
pinMode(6, OUTPUT);
}
void loop(){
tone(6, 523);
delay(1*tempo);
noTone(6);
delay(2*tempo);
tone(6, 391);
delay(1*tempo);
noTone(6);
delay(2*tempo);
tone(6, 415);
delay(1*tempo);
noTone(6);
delay(3*tempo);
tone(6, 523);
delay(1*tempo);
noTone(6);
delay(2*tempo);
tone(6, 391);
delay(1*tempo);
noTone(6);
delay(2*tempo);
}
Downloads
Annoy Everyone Around You
Now that your Arduino is successfully playing "Crank Dat" by Soulja Boy on an endless loop, consider hiding your project somewhere in the dwelling where anyone that lives with you will have trouble finding it. Consider putting it above ceiling tiles, under a couch, or behind a television.
In the next project, we will discuss ways of making your portable worship hymn playing device hand-cranked, so that it can be used more often and in more locations, so stay tuned for that. Below is an example of what that will look like.