LDR to activate arduino code in sketch

I am trying to write an arduino sketch for a robot that navigates an LED light grid, I need to know if what I am proposing is feasible?

I have built a robot with a singular chassis mounted LDR, I need to know if I can use the LDR and set a threshold that when passed will trigger an event in the code? So say for example

IF LDR threshold passes 800 THEN Turn left 90°,continue forward, turn right 90°.

I'm a complete Arduino novice so any advice would be hugely appreciated :)

Yes.

You need to wire the LDR as part of a voltage divider and use one of the analog pins to measure the voltage at the junction of the voltage divider.

This crude diagram may help - connect X to the analog pin.

Arduino 5v pin --------LDR -------x--------fixed resistor-------- Arduino GND pin

Choose a fixed resistor that is about the middle range of the LDR resistance - it's not critical.

You will ned to experiment to find the value that works best for your threshold.

...R

It depends on the brightness of the LED as to how much the LDR will change. I would expect that it could work.

The easiest way to find out is try it. Put the LDR you want to use as one side of a voltage divider connected to the analogue input and read the value (when facing down to the table you want to use). Then repeat with one of the LEDs you want to use. If there is enough difference then all is well.

Weedpharma

The grid will be in a dark room and each of the LED's on the grid is individually housed in tubing that the robot passes over on a sheet of plastic acrylic so the LDR values jump dramatically (Like switching a light on in a room).

Excuse my ignorance but when you say a voltage divider does that basically mean that I'm tapping off of the LDR to an analogue pin and then reading that pin in the arduino code? I have only just started using arduino so this is all new to me.

ensampliste: Excuse my ignorance but when you say a voltage divider does that basically mean that I'm tapping off of the LDR to an analogue pin and then reading that pin in the arduino code? I have only just started using arduino so this is all new to me.

That's why I drew my crude diagram.

...R

Voltage Divider = two resistors in series, because you can use it to divide voltage (knowing ohm's law, consider how the voltage in the middle relates to the voltage on the two ends - it becomes clear why they call it a voltage divider).

In the case of an LDR, one of those resistors is the LDR. So as the resistance of the LDR changes (due to changing light levels), it's resistance changes, so the voltage at the middle (ie, between the two resistors) changes. You may need to play around with the value for the fixed resistor to get something that will work within the range of light levels you want - you want it to be in between the resistance of the LDR in the "dark" light level, and the "light" light level, when it's over an LED), in order to maximize the change in voltage, thus making it easier to detect.

the x ges to the A1 pin.
if (analogRead(A0) > 200){goleft()}

ah that makes perfect sense, thank you everyone for your help I think I have an idea how to tackle it now!