# LED staying on very dimly

I have a setup where I connect two seperate instances of an LED and a photoresistor. Shine on photoresistor 1 for ~3 sec, LED 1 goes out. Shine on photoresistor 2 for ~3 sec, LED 2 goes out as well.

You can only put out LED 2 if you have first put out LED 1.

Only problem I"m having, after writing LOW to led 1, there is some residual voltage keeping it on. If I shine the laser on photoresistor 2 the LED dims more, but not fully. Only when both LEDs are written low do they fully dim.

I've measured it through with a multimeter. When LED1 = LOW, it receives 0,27V When LED1 = LOW and shine laser on photoresistor it receives -0,03V When LED1 = LOW & LED2 = LOW it receives 0,00V

What the heck

/*  Blind the cyclops!
Het doel van dit spel is om de photoresistor te raken met de laserstraal en zo de cycloop te verblinden. Als de taak geslaagd is dooft de LED boven het hoofd van de cycloop.
Als het oog van de ene cycloop verblind is kan er nog een tweede oog aan toegevoegd worden om de puzzel te vermoeilijken. Daarbij kan bijvoorbeeld een specifieke tijd ingesteld
worden waarbinnen de twee triggers af moeten gaan. De ogen van de cyclopen kunnen namelijk herstellen!
*/

//The laser
const int laserPin = 12;     // define laser pin

//The first eye
const int ledPin1 = 4;      // define left LED pin
const int photoPin1 = A0;    // define left analog photoresistor pin
int photoValue1 = 0;         // initialize photoresistor
int val1 = 0;
int blinded1 = 0;

//The second eye
const int ledPin2 = 10;      // define left LED pin
const int photoPin2 = A1;    // define left analog photoresistor pin
int photoValue2 = 0;
int val2 = 0;
int blinded2 = 0;

void setup() {
pinMode(laserPin, OUTPUT);    // define laser pin as output
pinMode(ledPin1, OUTPUT);      // define led pin as output
pinMode(ledPin2, OUTPUT);      // define led pin as output
Serial.begin(9600);           // start communication with serial monitor
}

void loop() {

//  Serial.println(photoValue);           // comment this for calibration purposes

digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(laserPin, HIGH);       // initialize the laser beam

if (blinded1 != true && blinded2 != true){

if (photoValue1 > 992 ) {             // check whether the laser beam is triggering the photoresistor. Adapt equation to calibration value.
val1++;                            // if it is, start incrementing val by 1
Serial.print("Val1 count is");
Serial.println(val1);
if (val1 == 100){                   // when val reaches 3000, kill the cyclops
blinded1 = true;
digitalWrite(ledPin1,LOW);
Serial.print("You have blinded the first cyclops");
}
}
else {                                // if the laser beam stops triggering the photoresistor before val reaches 50, reset val
val1 = 0;
}
}
if (blinded2 != true && blinded1 == true){

digitalWrite(ledPin1,LOW);

if (photoValue2 > 992) {             // check whether the laser beam is triggering the photoresistor. Adapt equation to calibration value.
val2++;                            // if it is, start incrementing val by 1
Serial.print("Val2 count is");
Serial.println(val2);
if (val2 == 100){                   // when val reaches 3000, kill the cyclops
blinded2 = true;
digitalWrite(ledPin2,LOW);
digitalWrite(laserPin, LOW);    // kill the laser for safety purposes
}
}
else {                              // if the laser beam stops triggering the photoresistor before val reaches 50, reset val
val2 = 0;
}
}
if (blinded2 == true && blinded1 == true){
Serial.write("You have blinded both cyclopses, succes!!");
delay(10000);
blinded1 = false;
blinded2 = false;
val1 == 0;
val2 == 0;
}
}

I suspect your loop is running faster than you imagine. Both LEDs are getting a HIGH at the beginning of every time it loops. The dimness looks steady to you but it is merely alternating rapidly. Dims further when more happens with the second stuff because it ever so slightly prolongs LOW before the HIGH at the top of loop.

INTP: I suspect your loop is running faster than you imagine. Both LEDs are getting a HIGH at the beginning of every time it loops. The dimness looks steady to you but it is merely alternating rapidly. Dims further when more happens with the second stuff because it ever so slightly prolongs LOW before the HIGH at the top of loop.

That was indeed the problem. Thanks a bunch!