Introduction: Arduino Play (micro)music Without Shield

Picture of Arduino Play (micro)music Without Shield

micromusic, 8 bit music, arduino music!

Step 1: About

Picture of About

For a project of an art collective, I made a music-playing with Arduino. Music begins with ultrasonic sensor.

Step 2: Code

The code for the music you write by hand, play by ear!

My code is a little part from the Carmen of Bizet

//Antonio Mainenti http://soundobject.eu/ Credit: Melo

#define trigPin 7 // pin trig #define echoPin 6 //pin echo #define buzzer 9 // buzzer or output int variabile; //repeats 4 times the first part int freq = 294; //D int freq2 = 440; //A int freq3 = 698; //F int freq4 = 440; //A int freq5 = 294; //D int freq6 = 587; //D int freq7 = 554; //C# int freq8= 523; //C int freq9= 494; //B int freq10= 466; //A# int durata = 7000; //duration of notes int durata2 = 500; int durata3 = 70; int durata4 = 3000; int durata5 = 1000; int durata6 = 100; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(buzzer, OUTPUT); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; for(variabile=0; variabile<4; variabile++) // repetition { if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq, durata); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq2, durata2); //tone(pin, frequency, duration) } delay(200); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq3, durata3); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq4, durata4); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq5, durata5); //tone(pin, frequency, duration) } delay(500); } //second part if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq6, durata5); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq7, durata5); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq8, durata6); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq8, durata6); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq8, durata2); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq9, durata5); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq10, durata); //tone(pin, frequency, duration) } delay(500); if (distance > 100 || distance <= 0){ Serial.println("Out of range"); noTone(buzzer); } else { Serial.print(distance); Serial.println(" cm"); tone (buzzer, freq2, durata); //tone(pin, frequency, duration) } delay(1000); }

Step 3: Pin, Arduino and Sensor

Picture of Pin, Arduino and Sensor

ultrasonic sensor:

VCC----- 5V

TRIG-----pin7

ECHO-----pin6

OUT

GND----gnd

audio out:

arduino pin9----10k resistor-----out

gnd----4,7k resistor----out

Step 4: Frequencies

Picture of Frequencies

one note, one frequency.

for example:

A4= 440

one note, one duration

Step 5: Finally

Comments

About This Instructable

2,671views

19favorites

License:

Bio: is a singer, musician, composer and instrument builder. His first sound experiences, when he’s five years old, are made with a red and black ... More »
More by ninuxi:Arduino play (micro)music without shieldSolar theremin with Arduino
Add instructable to: