# Peeling Elephant Garlic: Input CdS photoresistor_Output LED

Really beautiful, thank you so much. I will work on this description and post back!

I appreciate what you said about reading the sensors and running the multiplexors being done first.

I have not put the sensor in the garlic-bulb yet. Upon doing this I can actually see how much light makes it through the husk. Hopefully the husk will obscure the light enough, such that I can employ the anlalog voltage reading method. This entails making a voltage divider, such that the voltage will change due to the variable resistor(LDR).

I hope that the voltage divider that was advised above, and that I sketch the diagram of, will yield some analog reading.

The other facet of the Voltage divider is choosing the right value for the the pulldown resistor. this little tip is given in the adafruit tutorial:

If you're planning to have the sensor in a bright area and use a 10KΩ pulldown, it will quickly saturate. That means that it will hit the 'ceiling' of 5V and not be able to differentiate between kinda bright and really bright. In that case, you should replace the 10KΩ pulldown with a 1KΩ pulldown. In that case, it will not be able to detect dark level differences as well but it will be able to detect bright light differences better. This is a tradeoff that you will have to decide upon!

You can also use the "Axel Benz" formula by first measuring the minimum and maximum resistance value with the multimeter and then finding the resistor value with: Pull-Down-Resistor = squareroot(Rmin * Rmax), this will give you slightly better range calculations

So presuming at this point I have analog voltage reading is successful for 1 photocell. I would need to coordinate the voltage readings from a number of photocells. I think it will be about 30.

The tutorial offers this bit of code. It is for 1 photo cell not a multiplex. It also gives a reading of 5 states, (dark,dim,light,bright,verybright), where I require only 2 states reading, (peeled/unpeeled).

``````/* Photocell simple testing sketch.

Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider

void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
}

void loop(void) {

Serial.print("Analog reading = ");

// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
delay(1000);
}
``````

That would be my first query; how could one adapt the above ^ code for 30 Photocells and just 2 states, or write a new program if need be.

Secondly;

I would like to illuminate one LED per bulb peeled. It does not matter which LED goes with what.
I think this next bit of code (below) tends in that direction but is more of a continuous representation than discrete peeled/unpeeled representation.

``````/* Photocell simple testing sketch.

Connect one end of the photocell to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the sensor divider
int LEDpin = 11;          // connect Red LED to pin 11 (PWM pin)
int LEDbrightness;        //
void setup(void) {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
}

void loop(void) {

Serial.print("Analog reading = ");

// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0