Go Down

Topic: Project 6 extended to multiple photoresistors (Read 1 time) previous topic - next topic

MatLoz

When we looked into project 6, we thought it would be fun to add more photoresistors, so we made a few changes to the project to be able to control 4 photoresistors which allow a wider range of possibilities. We also added 4 leds to show which photoresistor is used to play the sound.
We made a short video to show how it work.

http://www.youtube.com/watch?v=nHSMjO48JM4

We found this tool : circuits.io on the web to generate the schema but were unable to use the exact same design as our board (piezo component has been replaced by a capacitor). So we're unsure of the accuracy of the design, but you might find this tool useful.
We added a photo of the board and the generated schema as attachments in this post.

Here are the changes we made to the code :

First we declared our constants and arrays of values. To get notes frequencies, we used this website : http://www.phys.unsw.edu.au/jw/notes.html

Code: [Select]
const int SENSORS_COUNT = 4;
const int soundLedPins[SENSORS_COUNT] = {4, 5, 6, 7};
const int lowSensorValues[SENSORS_COUNT] = {262, 349, 466, 622};
const int hiSensorValues[SENSORS_COUNT] = {330, 440, 587, 784};


Then in the setup() function we added the following loop, which allow us to output to the leds:

Code: [Select]
for (int i = 0; i < SENSORS_COUNT; i++)
{
  pinMode(soundLedPins[i], OUTPUT);
}


We changed the loop function that way :

Code: [Select]
void loop()
{
  int values[SENSORS_COUNT];
  values[0] = analogRead(A0);
  values[1] = analogRead(A1);
  values[2] = analogRead(A2);
  values[3] = analogRead(A3);
 
  int sensorValue = 1023;
  int sensorIndex = -1;
  for (int i = 0; i < SENSORS_COUNT; i++)
  {
    if (values[i] < sensorValue)
    {
      sensorValue = values[i];
      sensorIndex = i;
    }
  }
 
  if (sensorIndex >= 0)
    playSound(sensorValue, sensorIndex);
}


and created a function to play sound based on sensor value and index :

Code: [Select]
void playSound(int value, int sensorIndex)
{
  // define pitch based on sensor value and calibration values
  int pitch = map(value, sensorLow, sensorHigh, lowSensorValues[sensorIndex], hiSensorValues[sensorIndex]);

  // play the tone for 20 ms on pin 8
  tone(8, pitch, 20);
 
  // leds
  int pinIndex = SENSORS_COUNT - sensorIndex - 1;
  digitalWrite(soundLedPins[pinIndex], HIGH);
  delay(10);
  digitalWrite(soundLedPins[pinIndex], LOW);
}


We hope you will like it, if you have any question don't hesitate to reply to this post !

jn-wp

funny start in the video!
leds blinking in the dark and stop playing if light hits them! haha! :D

CSGuy

I saw that on a space ship once. They were using it to probe my mind.

Ytirakok

Hi! It's really cool extension. Exactly what I'm working on right now. But I can't fiqure out what is Project 6 to modify it.  May be you still have the full project. I'm trying to connect several photoresistors for each LED but the code doesn't work. Seems like everything is fine with the circuit, but code, I'm not very good in that.

I would be super thankful if you could share the full code. Thanks!!!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy