Components:
- 7 LDRs
- 7 x 10KΩ resists
- Jumper wires
- USB cable
- Computer
- Arduino Uno
- Breadboard
Description
For a while now I have been wanting to combine sounds and colors, so this assignment was the perfect opportunity to do so. I created this object that reproduces specific sounds depending on the color that has been selected. To choose a color one has to touch the center of the corresponding flower (see picture). Each flower has an LDR, therefore each time the user approaches his/her finger to the flower the arduino detects the drastic change on the value of the sensor, and triggers the playback of a specific sound.
Code
int rojo = A0; // select the input pin for the LDR
int naranja = A1; // select the input pin for the FSR
int amarillo = A2; // select the input pin for the FSR
int verde = A3; // select the input pin for the FSR
int azul = A4; // select the input pin for the FSR
int morado = A5; // select the input pin for the FSR
int led = 13; // select the input pin for the FSR
int rojoV0 = 0;
int naranjaV0 = 0;
int amarilloV0 = 0;
int verdeV0 = 0;
int azulV0 = 0;
int moradoV0 = 0;
int rojoV1 = 0;
int naranjaV1 = 0;
int amarilloV1 = 0;
int verdeV1 = 0;
int azulV1 = 0;
int moradoV1 = 0;
int count = 10;
int speakerPin = 7;
unsigned int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
void setup() {
pinMode(led, OUTPUT);
pinMode(speakerPin, OUTPUT);
digitalWrite(led, HIGH);
digitalWrite(speakerPin, LOW);
Serial.begin(9600); // Sets the data rate in bits per second (baud) for serial data transmission.
Serial.println(“WELCOME to the colorful sounds lab!”);
Serial.print(‘\n’);
}
void loop() {
// read the values from the sensors:
rojoV1 = analogRead(rojo);
naranjaV1 = analogRead(naranja);
amarilloV1 = analogRead(amarillo);
verdeV1 = analogRead(verde);
azulV1 = analogRead(azul);
moradoV1 = analogRead(morado);
if (rojoV1 – rojoV0 > 50)
{
/*Serial.print(“Rojo0: “);
Serial.print(rojoV0);
Serial.print(” Rojo1: “);
Serial.println(rojoV1);
Serial.print(‘\n’);*/
count = 0;
}
else if (naranjaV1 – naranjaV0 > 50)
{
/*Serial.print(“Naranja0: “);
Serial.print(naranjaV0);
Serial.print(” naranja1: “);
Serial.println(naranjaV1);
Serial.print(‘\n’);*/
count = 1;
}
else if (amarilloV1 – amarilloV0 > 50)
{
/*Serial.print(“amarillo0: “);
Serial.print(amarilloV0);
Serial.print(” amarillo1: “);
Serial.println(amarilloV1);
Serial.print(‘\n’);*/
count = 3;
}
else if (verdeV1 – verdeV0 > 50)
{
/*Serial.print(“verde0: “);
Serial.print(verdeV0);
Serial.print(” verde1: “);
Serial.println(verdeV1);
Serial.print(‘\n’);*/
count = 4;
}
else if (azulV1 – azulV0 > 50)
{
/*Serial.print(“azul0: “);
Serial.print(azulV0);
Serial.print(” azul1: “);
Serial.println(azulV1);
Serial.print(‘\n’);*/
count = 5;
}
else if (moradoV1 – moradoV0 > 50)
{
/* Serial.print(“morado0: “);
Serial.print(moradoV0);
Serial.print(” morado: “);
Serial.println(moradoV1);
Serial.print(‘\n’);*/
count = 6;
}
rojoV0 = rojoV1;
naranjaV0 = naranjaV1;
amarilloV0 = amarilloV1;
verdeV0 = verdeV1;
azulV0 = azulV1;
moradoV0 = moradoV1;
if (count < 7)
{
for( int i=0; i<50; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count]);
}
count = 10;
}
delay(200);
}