public class LDR extends AnalogInputDevice
Generic Photoresistor / Light-Dependent-Resistor (LDR).
Wiring:
vRef vLDR GND | | | +---R1---+---LDR---+
When there is a lot of light the LDR has low resistance (vLdr ~ 0V). When it is dark the resistance increases (vRef ~ vRef).
vLDR = vRef * (rLDR / (rLDR + R1))
Given R1 = 10,000ohm and vRef = 5v:
When dark, if rLDR == 100,000ohm: vLDR = 5 * (100,000 / (100,000 + 10,000)) = 4.54V
When light, if rLDR == 100ohm: {code vLDR = 5 * (100 / (100 + 10,000)) = 0.0495V}
rLDR = R1 / (vRef / vLDR - 1)
Given R1 = 10,000ohm and vRef = 5v:
When dark, if vLDR=4V: rLDR = 10,000 / (5 / 4 - 1) = 40,000 Ohm
When light, if vLDR=1V: rLDR = 10,000 / (5 / 1 - 1) = 2,500 Ohm
listeners
pinNumber
Constructor and Description |
---|
LDR(AnalogInputDeviceFactoryInterface deviceFactory,
int pinNumber,
float vRef,
float r1) |
LDR(int pinNumber,
float vRef,
float r1) |
Modifier and Type | Method and Description |
---|---|
float |
getLdrResistance()
Read the resistance across the LDR.
|
addListener, addListener, close, disableListener, enableListener, getScaledValue, getUnscaledValue, run
addListener, removeAllListeners, removeListener, valueChanged
getPinNumber
public LDR(int pinNumber, float vRef, float r1) throws RuntimeIOException
pinNumber
- Pin to which the LDR is connected.vRef
- Reference voltage.r1
- Resistor between the LDR and ground.RuntimeIOException
- If an I/O error occurred.public LDR(AnalogInputDeviceFactoryInterface deviceFactory, int pinNumber, float vRef, float r1) throws RuntimeIOException
deviceFactory
- Device factory to use to construct the device.pinNumber
- Pin to which the LDR is connected.vRef
- Reference voltage.r1
- Resistor between the LDR and ground.RuntimeIOException
- If an I/O error occurred.public float getLdrResistance() throws RuntimeIOException
RuntimeIOException
- If an I/O error occurred.Copyright © 2016 mattjlewis. All rights reserved.