ARDUINO meets PROCESSING

LDR light sensor


navigation

To build the electronic circuit you need the following parts:

The schematic for the circuit looks like this:

scheme for LDR

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:

picture of light sensor circuit

If everything is set up right, you can connect the board to the serial (or USB) port of your computer and, if necessary, to the power supply. The power LED should light up and 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 and baudrate, compile the program, and then press the reset button on your board and click on the export 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 pa_LDR.zip and open the file pa_LDR.pde in Processing. You will have to set the right serial port, which you do by editing the variable portname. Eventually you will also have set the correct baudrate by editing its variable (baudrate).

Now, you can run your Processing program. A new window will open and you should see something like this:

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.