Photoswitch

Hello everyone, New to the forms.. I actually bought this arduino duemilanove to just act as a ligh or photoswitch. I also bought a mini photocell. I really just need help writting the program. Can anyone help me?

Needs: when light is present no output when it is dark full output. needs to be checking at least once every minute.

This is what I got so far.

const int SensorPin=0; // input for photocell const int LedPin=13; ///pin for led const int Threshold=1022; //value of sensor const int stop=0; //make it never ending

void setup() { //delcare the ledpin as output //initialize serial communication pinMode(LedPin, OUTPUT); Serial.begin(9600); }

//void Why(){ //while(stop==0){loop();} //}

void loop() {

int SensorValue = analogRead(SensorPin);

if (SensorValue>Threshold){analogWrite(LedPin , SensorValue);}

else { analogWrite(LedPin,0); } // print the analog value: // Serial.println(SensorValue, DEC); }

const int Threshold=1022

Out of a maximum value of 1023, that's a pretty narrow range.

What is your "photocell", and how is it wired?

Also, writing this value to an "analogWrite" with a maximum range of 0..255 will work, but it's best to get it right. Try looking at "map".

here is my photcell

http://www.sparkfun.com/commerce/product_info.php?products_id=9088

I have it wired so that it takes v5 ref on one leg and then one leg in analog input .

output is digital pin 13.

You need to wire it as a voltage divider: http://en.wikipedia.org/wiki/Voltage_divider

I am slightly confused do i just slect an arbitrary resistor. Also I am not an electronics expert by no means as a note. Also shouldn't the arduino act as a voltage divider. Cant the analog in switch just tell if there is zero volatge or +5 voltage. I just need a little more elaboration please, Thanks in advance for your help by the way.

Set your threshold lower, and have a look at p26 on oomlout.co.uk’s beginners guide for wiring help: http://ardx.org/src//guide/2/ARDX-EG-OOML-WEB.pdf