9.1 Adding a Photoresistor

Uncategorized — roguescience @ 5:14 pm

A photoresistor is a kind of variable resistor that DECREASES its resistance as the amount of light it receives INCREASES.

Use the following circuit diagram and photograph to add a photoresistor to your controller. Remember you will need to connect it to its own analog input.

Use serial communication, mapping and thresholding techniques so that the photoresistor outputs a range of 0-127 only when its value changes.

To test your photoresistor - cut and paste the following code:

/*
 * 7.1 Test photoresis
 * roguescience.org
 *
 *
 * analog pin 1 <-- photoresistor
 */

int photoPin = 1;
int photoVal = 0;

void setup() {
  Serial.begin(9600);            //start communicating at 9600 baud
}

void loop(){
    photoVal = analogRead(photoPin);
    Serial.println(photoVal);
}

Next map the data between 0-127. Use thresholding to try to have it only send data when it changes. Once you are happy with the data incorporate the photoresistor into your main MIDI controller code - use the potentiometer as a guide. Remember to declare all of the photoresistors variables at the top of the code. Remember that the lighting conditions will affect how this sensor behaves so try to test it in A146 if you can - I will install the Arduino software on the G5.

coming soon - auto-calibrating light sensors

3 Comments »

  1. Hi,
    I think, but I’m new at this, that there is a bug when you write “Next map the data between 0-127″ Shouldn’t there be 0 - 255???

    Best regards

    Comment by RaV — May 12, 2010 @ 1:26 am
  2. Hi Rav - MIDI values are 7-bit e.g. 0-127.

    Comment by roguescience — May 12, 2010 @ 9:40 am
  3. My bad :-) Thanks for the info.

    Comment by RaV — May 12, 2010 @ 9:45 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2010 Roguescience Arduino Tutorials | powered by WordPress with Barecity