public class LDR extends AnalogInputDevice
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))
IF R1 = 10,000ohm, vRef = 5v
When dark, if rLDR == 100,000ohm
vLDR = 5 * (100,000 / (100,000 + 10,000)) = 4.54V
When light, if rLDR == 100ohm
vLDR = 5 * (100 / (100 + 10,000)) = 0.0495V
rLDR = R1 / (vRef/vLDR - 1)
IF R1 = 10,000ohm, vRef = 5v
When dark, if vLDR=4V
rLDR = 10,000 / (5 / 4 - 1) = 40,000ohm
When light, if vLDR=1V
rLDR = 10,000 / (5 / 1 - 1) = 2,500ohm
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() |
float |
getLuminosity() |
addListener, addListener, close, disableListener, enableListener, getScaledValue, getUnscaledValue, run
addListener, removeAllListeners, removeListener, valueChanged
getPinNumber
public LDR(int pinNumber, float vRef, float r1) throws RuntimeIOException
RuntimeIOException
public LDR(AnalogInputDeviceFactoryInterface deviceFactory, int pinNumber, float vRef, float r1) throws RuntimeIOException
RuntimeIOException
public float getLdrResistance() throws RuntimeIOException
RuntimeIOException
public float getLuminosity() throws RuntimeIOException
RuntimeIOException
Copyright © 2016 mattjlewis. All rights reserved.