Arduino and Processing, LDR

This is an updated version of the LDR post from here.

To build the electronic circuit you need the following parts:

  • a LDR light sensor,
  • a 1kΩ resistor,
  • and a couple of wires.

A LDR light sensor is a variable resistor. Notice, that in this case we use a pull-up resistor (which means that it is located before the sensor). Still, we measure the voltage ‘between’ this resistor and the light sensor. The circuit on your breadboard should look something like this:

Working circuit on breadboard

If everything is set up right, you can connect the board to USB port of your computer. The power LED should light up the next step is to export the program, which reads the state of the switch to the board. Open the ap_ReadAnalog.pde file in Arduino set the right serial port (from the menu Tools->Serial Port) and baudrate (in the code), compile the program, and then click on the Upload icon () to send the program to the board.To check if everything works fine so far, see if the control LED goes off when you cover the sensor with you hand. If it’s turned off you might have to expose it to more light to pass the threshold value and cause the LED to light up. Now, you can download and unzip and open the file pa_LDR.pde in Processing.Then you will have to set the right serial port as described before.

Run your Processing program. A new window will open and you should see something like this:

Program Output

The maximum size of the pulsating circle depends from the quantity of light that hits the sensor. More light will increase the size of the circle, less light will make it smaller.


Comments are closed.