# LDR, photodiode or?

#### MrDEB

##### Well-Known Member
working on Christmas 2020 project and trying to decide what to use for detecting "dark'"
project entails a Christmas star that is placed on top of Christmas tree, powered by coin cell battery or 5v USB walwart.
leaning towards the wall-wart idea so battery would no need to be replaced.
project utilizes an 18f43k22 to control the 35 LEDs.
the light sensor will turn on the LEDs when it gets dark and runs for predetermined amount of time ( thinking 6 hours) thus a long delay is programmed in the pic.
the light sensing circuitry to be connect to an ADC port.
looking at different light sensor ideas using photo diode, photo transistor or even an LDR. All basically the same but trying to utilize the KISS method.
any ideas on which sensor type to utilize?

#### alec_t

##### Well-Known Member
An ADC typically requires a source impedance <10k, which makes interfacing to an LDR easiest and least interference-prone, in my opinion.

##### Member
I agree with alec_t

LDR and suitable resistor is the simplest option and the easiest to understand.

#### Nigel Goodwin

##### Super Moderator
Likewise, it's crazy to consider anything else. You don't even need to use an analogue input, you can use a simple capacitor charging technique on any normal I/O pin, as in my joystick tutorial - and easily achieve more than 8 bit resolution.

##### Member
I think Mr Deb should use PIC analogue input (or possibly comparator) for measuring LDR/resistor potential divider voltage.

Not nearly as clever as capacitor charge timing, but simpler to understand for a beginner.

#### Visitor

##### Active Member
^^^ Especially since the chip he's using has plenty of ADC inputs.

#### Visitor

##### Active Member
You might consider something like the Everlight ALS-PDIC243-3B (datasheet). It will have more uniform and predictable results than random photocell, and its response to tailored to match the human eye – IR is filtered out.

At LCSC, the qty 10 price is 20 cents each, or 42 cents each at Mouser.

The circuit is pretty simple.

Last edited:

#### MrDEB

##### Well-Known Member
I clicked on the data sheet that Jon posted but it is a relay, not a LDR
it happens

#### Visitor

##### Active Member
Sorry. Link fixed. But to be fair, the part number was there – you could have found it with the tiniest bit of effort.

#### gophert

##### Well-Known Member
Sorry. Link fixed. But to be fair, the part number was there – you could have found it with the tiniest bit of effort.

View attachment 126227
But he knew you couldn't resist fixing it.

#### Visitor

##### Active Member
I do know how to edit a post – it seems like a hardly-known skill here.

#### MrDEB

##### Well-Known Member
I was wrong in thinking you posted the correct link.
been searching for inexpensive wall warts but everything is $6+ These Christmas stars are Christmas presents for friends and family so cost is a big issue. Need to$hip these stars to Florida and California so my cost has exploded not to mention if going with a wal wart then a voltage regulator will be needed so cost = ++
Going with battery power only with LDR
need to research PWM further.
onward with design

#### Pommie

##### Well-Known Member
Any USB wall wart will power a USB Arduino which will easily make your project possible.

Mike.

#### Visitor

##### Active Member
You're right. Usually, I buy better power supplies. For about the same price.

At thrift stores and PC recyclers, one of the greatest values are power supplies from cell phone and computer manufactures and other "wall warts" that came with consumer electronics. These power supplies were engineered for a long service life, follow good design practices and have all the ratings. For a buck or two. Some are a little more, like the mammoth X-Box power supplies, which provide 12 volts at up to 16 amps depending on the version.

While I can't state with utter confidence as some do here, the switching power supplies I have tested have a strong self-preservation instinct. As current draw approaches the and exceeds the maximum rated current draw, the output voltage rapidly falls to zero.

A very safe way to have an illuminated ornament would be to use a USB power bank. Recharge it periodically and it will work great.

#### throbscottle

##### Well-Known Member
Why not fit it with a small rechargeable battery? Solder tagged NiMh battery will trickle charge with no special circuitry. Give it a USB socket and they can charge it using their phone charger before they stick it on the tree. Battery voltage hits the PIC's supply voltage range with no regulator. Don't know how long it would light your LED's for though. You using super-low current ones?

#### MrDEB

##### Well-Known Member
I looked at flea bay and saw the ones Jon posted and yes I want them with cords plus not worry about a fire.
still contemplating what direction.
As for LEDs, using standard white and blue. only one resistor for the blue (multiplexing each LED so only one rsistor works (did similar last year and the LEDs twinkle. The white LEDs this year will be clustered in groups of 3 or 4. These will twinkle with a longer off time. Contemplating using PWM but need to breadboard and experiment with PWM.
issue with throbscottles suggestion is USB wal-wart issue plus I still need to add a voltage reg which will increase the cost slightly.
And yes I viewed and printed out the data sheet for the ALS-PDIC 243-3B AND THE PT42-21C/TR8

#### throbscottle

##### Well-Known Member
Am I right in thinking you are making these as Christmas gifts?

My point was, nearly everyone has more USB phone chargers than they know what to do with. Settle on this standard and you don't need to supply one. Phone manufacturers already make them an optional add-on.

As to voltage regulation, that PIC will run on 5.5v down to 2.3v. Unless you meant the version with an L in the name. So it would not be needed.

I think you are right to not trust off-brand chargers. But there are also reputable manufacturers cheaper than the big-name brands.

#### MrDEB

##### Well-Known Member
My present schematic has both a usb input port and a coin cell battery at present. IF I have both then maybe keep both but?
If one puts it on the top of the tree then adds the usb cord sounds good BUT if only the battery and battery goes dead then what!!
Will have a LDR so battery life should last longer plus I am planning on 500-1K resistors so drain should be pretty low..
I have some friends in town that I gave one to two years ago with a wall-wart and they put it in their kitchen as a night light so it really has some brightness to it using 250-500 ohm resistors.
LOTS to consider.