You are absolutely right ...

Adruino UNO.
This is the sketch:
/*
Switch ON yellow LED when casting shadow over green LED
*/
int g = 9, y = 11, carica;
void setup() {
pinMode(y, OUTPUT);
Serial.begin(9600);
}
void loop() {
pinMode(g, OUTPUT);
digitalWrite(g, HIGH);
delay(50);
pinMode(g, INPUT);
carica = analogRead(A1);
Serial.println(carica);
digitalWrite(g, LOW);
delay(200);
Serial.println(analogRead(A1));
if (carica - analogRead(A1) < 180)
digitalWrite(y, HIGH);
else digitalWrite(y, LOW);
delay(30);
}
The two LEDs (green pin 9 sensor, yellow pin 11 light emitter) are driven through 220ohm resistors.
I "charge" green LED as a capacitor at the beginning of loop and read its tension through pin A1, then I read the residual tension after 200ms.
Knowing that the discharge is faster if the LED is in light condition than in shadow I decide to switch yellow LED OFF or ON (I use a threshold of 180).
Using USB power I have the expected behavior (yellow LED ON in shadow and OFF in light).
Using external power (9V) yellow LED OFF in light an slowly blinking in shadow.
Using external power (15V) yellow LED blinks slowly regardless light conditions.
I can't explain it.