Servo triggered by photoresistor - help needed!

Hi!

Im making a track for marbles as a school assignment. I got some experience with arduinos but not photo resistor so i dont know how to implement it in the code.

I want the photo resistor to act as a switch so when it dosent receive any light(blocked by a marble), the servo will be triggered.

[u]So this is what i want the code to do:[/u]

*See if the photo resistor is "triggered"

*Have a variable delay that runs in the loop (when the ldr is triggered)

  • Move the servo 180 degrees after the delay

*delay after the 180 movement

*Move the servo back to its original position (0 degress) after the delay.

I would also like to have a led that show when the photoresistor is triggered!

[u]Here is the parts:[/u]

*Arduino uno

*turnigy 9g servo (180degress of motion

*Photoresistor 2-20 kohm (got it set up like this right now http://www.arduino.cc/en/uploads/Tutorial/switchCase_bb.png)

[u]I got access to these parts:[/u]

*Leds

*Alot of diffrent values of resistor and potentiometers

*An arduino mega 2560

  • small capacitors with diffrent values

  • transistors

Im looking for help with the code, Preferably the hole code for it because of the lack of time. I know thats alot to ask for but i really need help with this! Im getting better at programing the arduino, but im not on this level :D

Thanks alot!

I personally would use a photo transistor. Attach the circuit to a digital input. You would then treat it like a switch.

You might use the photo resistor in a voltage divider connected to an analog input to detect or measure light/dark conditions. based on this you might be able to have the servo do things.