User Guide
www.kitronik.co.uk
Ambient Light Breakout
Ambient Light Sensor Breakout -
5105
Circuit Overview
This circuit uses the SFH 320-3/4-Z phototransistor and provides an analogue signal which gives a
representation of the levels of light that are falling on the phototransistor on the board. This is
achieved by creating a potential divider using a 2.2M resistor and the phototransistor. As the light
level increases, the resistance of the phototransistor decreases, which increases the voltage at the
SIG pin. So by reading the voltage at the SIG pin you can determine how much light the
phototransistor is being exposed to.
(Measurements in mm)
Electrical Characteristics
Supply Voltage
SIG output
Current Consumption
Spectral Range of
Sensitivity
Min
0.6V
0.3V @Vcc = 5V
450nm
Typical
3-5V
<10mA
1150nm
Max
6V
4.9V@Vcc = 5V
Pinout
Vcc
SIG
GND
Supply Voltage
Analogue Out
Ground
Page 1 of 3
User Guide
www.kitronik.co.uk
Ambient Light Breakout
Arduino Schematic
This board is very simple to connect to the Arduino. Simply connect the SIG pin to an analogue input
(yellow wire),
the GND pin to the power ground on your Arduino
(black wire)
and the Vcc pin to
either 5V or 3V3 depending on the operating voltage of your microprocessor
(red wire).
If you are
unsure what this is you can check by using a multi-meter to measure the voltage across AREF and
GND on your Arduino.
The code on the next page can be used in conjunction with the circuit on the previous page to test
the breakout board. Upon uploading the code the red LED should blink twice then turn on for 5
seconds. During this time the light sensor is being calibrated to the light levels in the room so make
sure not to cover it. When the sensor has been calibrated the green LED will turn on. If you reduce
the level of light falling on the phototransistor (for example by covering it with your hand) the green
LED should fade. If you completely cover the light sensor with your hand the LED should turn off, and
when you remove your hand the LED should turn back on.
Arduino Connections
Light Sensor Board
SIG
Vcc
GND
Arduino
A0
5V or 3V depending on your AREF
(see previous page for details)
Ground
Page 2 of 3
User Guide
www.kitronik.co.uk
Ambient Light Breakout
Arduino Sketch
This sketch is available as a download from the website.
// constants:
const
int
sensorPin = A0;
const
int
ledPin = 6;
const
int
calibPin = 13;
const
int
calibTime = 5000;
calibrate(ms)
// variables:
int
sensorValue = 0;
int
sensorMin = 1023;
int
sensorMax = 0;
//
//
//
//
pin that the sensor is attached to
pin that the LED is attached to
pin that the calibration LED is attached to
time to measure light levels and
// the sensor value
// minimum sensor value
// maximum sensor value
void
setup()
{
// turn on LED to signal the start of the calibration period:
pinMode(calibPin,
OUTPUT);
digitalWrite(calibPin,
HIGH);
// calibrate during the first five seconds
while
(millis() < calibTime) {
sensorValue =
analogRead(sensorPin);
// record the maximum sensor value
if
(sensorValue > sensorMax) {
sensorMax = sensorValue;
}
// record the minimum sensor value
if
(sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
// signal the end of the calibration period
digitalWrite(calibPin,
LOW);
}
void
loop()
{
// read the sensor:
sensorValue =
analogRead(sensorPin);
// map the sensor value to a value between 0 and 255 (acceptable values
for PWM output
sensorValue =
map(sensorValue,
sensorMin, sensorMax, 0, 255);
// fade the LED using the calibrated value:
analogWrite(ledPin,
sensorValue);
}
Use this sketch in conjunction with the Arduino hook-up guide on the previous page.
Page 3 of 3