10 years ago.

LDR connection!

Hello guys! I plan on connecting 2 LDRs to my mbed board (LPC1768) and based on different voltages of the LDR rotate the motor until the voltages are equal. I am having trouble with where to connect the LDR's? and how to express voltages in code! Thanks in advance!

1 Answer

10 years ago.

LDRs are variable resistors. You can use a simple voltage divider consisting of one LDR in series with a regular resistor. The common connection of LDR and resistor goes to one of the analog inputs of the LPC1768. The other end of the LDR goes to ground, the other end of the resistor goes to 3V3. You can use the AnalogIn() method to read the voltage value on the LDR/Resistor. That value will depend on the light hitting the LDR. You will have to measure the LDR resistance at the expected light input to select the best value for the series resistor. You will probably be aiming for a clear voltage swing between minimum and maximum amount of light input. Then check the AnalogIn values that you get and apply suitable thresholds. You can also go for some experimenting by using a potmeter instead of a resistor and try out which setting gives the best results.