9.1 Adding a Photoresistor
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
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
Hi Rav - MIDI values are 7-bit e.g. 0-127.
My bad :-) Thanks for the info.