What is on the board · 02 of 10

Not an LDR

The clear part is a NEWOPTO XYC-PT21C-L1, an NPN phototransistor: light lets a current through it, and that current is the reading. The old page called it an LDR, and three of its claims followed from that: its speed, the colour it sees best, and what VCC does. All three were wrong for this board.

A transistor that light turns on

An ordinary NPN transistor has three legs. A small current into the base lets a larger current flow from collector to emitter. A phototransistor leaves the base out, or rather, lets light do its job: light falling on the silicon makes the small current, and the transistor passes a larger one in proportion. More light, more current. Dark, almost none.

Not an LDR
Show
Part
XYC-PT21C-L1
Sees best
850 nm
Switches in
15 µs
The part is 3.2 × 1.5 mm and 1.1 mm tall, a clear lens over a silicon chip. The board prints C beside its left pad and E beside its right. C is the collector, the datasheet's pin 2, and it goes to VCC. E is the emitter, pin 1, and it is SIGNAL.

The part on this board is a NEWOPTO XYC-PT21C-L1. It is 3.2 by 1.5 mm and 1.1 mm tall, and its lens is clear, which is why it looks white in the pictures. It has two legs. The board prints C beside the collector and E beside the emitter, and the net list wires the collector to VCC and the emitter to SIGNAL, with the 4.7 kΩ resistor from SIGNAL to ground.

What it replaced

Its datasheet says it can replace the older kind of light sensor, a resistor whose value changes with light. That is what the page before this book described, and it is where the confusion came from. The two look nothing alike on a board and behave differently in three ways that matter.

Speed. This part switches in about 15 µs. The old page said the sensor took a long time to settle and could not see flicker. This one is fast enough to follow the ripple of many mains lamps, which the flicker under room lights deals with.

Colour. This part is most sensitive at 850 nm, in the near infrared just past what you can see, and responds from 400 to 1100 nm. The old page put its best response in the middle of the visible range. It sees infrared is about what that does to a reading.

VCC. In a divider, the reading is a fraction of VCC, so a different VCC moves every reading. Here the light sets a current and the resistor turns it into a voltage, and VCC only sets how high that voltage can go. VCC sets the ceiling works it through.

One thing it got right

A brighter light gives a higher voltage on SIGNAL, and the number is not a unit. Two blocks under the same lamp can read differently, because the datasheet lets any one sensor be 30 % more or less sensitive than typical. So the old page's advice stands: read the two conditions you care about and put the threshold between them. A night light does exactly that.

When it does not work

My old sketch and notes treat it as a resistor. Is my board different?

No. Every TK20 carries the same phototransistor; the old page described a different kind of sensor. Sketches that simply read the analog pin still work, and a brighter light still gives a higher number. What changes is the explanation, and the three things that follow from it: speed, colour and VCC.

Can I measure its resistance with a multimeter?

Not usefully. A transistor is not a resistor, and a meter on its ohms range pushes its own small current the wrong way through it or not at all. To see it respond, power the block and measure the voltage between SIGNAL and GND while you cover and uncover it.

Why does the sensor look white in the pictures?

Its package is clear: a clear lens over the silicon, so light reaches the chip from above. Against the black board it shows as a small pale rectangle. Keep it clean. A fingerprint, a label or a blob of glue over it cuts the light it gets, and every reading with it.

Does it measure lux?

Not directly. It gives a current roughly in proportion to light, and its datasheet quotes that current at 10, 30 and 100 lux under its own test lamp. Under a different light, the same lux gives a different reading. Treat the number as brighter or darker, and calibrate for anything more.

Where this goes next

How the current through the phototransistor becomes the voltage on SIGNAL, and where the arithmetic stops.

Light becomes volts

Edit this page — content/books/ambient-light-sensor/not-an-ldr.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Ambient Light Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum