how to make a shadow sensor

I have photosensor, and been able to breadboard and using some tutorials ,
I make the arduino light the Led when Light, but How can I make it the other way, the dimm up the Led when shadow is over the photosensor
any help is very welcome

I assume your photosensor is an LDR (Light Dependent Resistor) and that it is hooked up as a voltage divider to an anlagog input.

You read the amount of light with analogRead() which in turn returns a number in the 0 - 1023 range.

You set a threshold in that range that you decide is "shadow" and then start to make the LED shine brigther with analogWrite().

And if you then put the LED next to the light sensor you will have made a relaxation oscillator.

If you don't see the LED flash then introduce a small delay in the loop();

thank you all.
I have cadmium sulfide photoshell n LDR (Light Dependent Resistor)
the sketch for the electronics and ardruino is from Massimo Banzi,
works great, when I put my finger on the LDR the led Fades
how ever I want the other way, when shadow or light is block from LDR I want the led to go On.
my current info is like this.

tannk you in advance.

goes like this

for the LDR connection goes like this

ground---Resistor 10k--connection to pin 0 analog----LDR-- --5v

for LED goes like this

groudn---LED ----pwm 9
running this

#define LED 9;
int val = 0;
void setup () {
pinMode(LED, OUTPUT);
}
void loop () {
val = analogRead(0);
analogWrite(LED, val/4);
delay(10);
}

If the code you posted works the way you want, one simple solution would be to replace

analogWrite(LED, val/4);

with

analogWrite(LED, 255-(val/4));

val/4 will always be a value between 0-255, so doing a 255 - (val/4) will result in an "inverted" value. 0 becomes 255, 255 becomes 0, 50 becomes 205, etc.

Good luck in your Arduino endeavours! :smiley: