Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

day/night sensor for pic input

Status
Not open for further replies.
just use a basic green led and a NPN transistor. (you could use a red/yellow led, but they are far more sensitive to light pollution)

put led in something where it won't be able to see terrestrial light; in daylight (or other strong broadband light) led will output ~1.5v into the transistor and pull a pic pin low. in darkness, the output is only a few millivolts from ambient light, not enough to cause the transistor to conduct enough current to register as a changed logic state for the pic.

good thing about green LEDs is they're not at all sensitive to the orangeish glow of light pollution. blue leds would probably work too, but they're kinda expensive to dedicate to this kind of application
 
led cathode to ground, led anode to transistor base... transistor collector to pic pin, transistor emitter to ground... either use a pic pin with an internal pull-up (like portb), or use your own weak external pull-up, connected to v+

my suggestion is just something fast, which could be scrapped together from parts laying around my work bench and provide a simple Light/Dark logic state. on the other hand, you could abandon the transistor all together, and just connect the leds' anode directly to an analog input on your PIC, the LED will output a voltage between 0 and ~1.5v in relation to the intensity of the light it is 'seeing' - you could take this data and do what you want with it, like adjusting the light/dark threshold... for example is it overcast, or did the sun really set? and conversely, was that just some passing by automobile headlights, or did the sun rise?
 
Ok I tried a few different leds & transistors with a clear IR giving the best responce.
but even it needed to much light for my app. (change state 1st. light and last light). got to thinking I had some photo transistors tried them but same thing .
right now I'm using a photoresistor, pot and transistor. and can adjust the pot to get what I need not sure how hard its going to be on the batteries.
 
...not sure how hard its going to be on the batteries.
Depends on the battery and current consumption of the circuit

Take into account your output as well as your potentiometer, and your photoresistor (LDR).

You could probably measure the resistance of the entire circuit with a ohmmeter (DMM set to the ohms function).

Once you get that, use ohms law to get the current being consumed by the circuit.

Convert your current into mA.

Divide this current by the maH stated in the battery's specifications.

your answer is the number of hours the battery is expected to last, provided that this is the first time you are using it.
 
mstechca said:
You could probably measure the resistance of the entire circuit with a ohmmeter (DMM set to the ohms function).

Once you get that, use ohms law to get the current being consumed by the circuit.

Convert your current into mA.
The puny 0.2V to 1.5V from an ohm-meter won't power an entire circuit enough to give an indication of its "resistance" nor its current draw.

Ohm's Law doesn't work with active circuits but would determine the current used by the LDR in series with a pot.
 
Are you just looking for light/dark or do you want to differentiate between day/night regardless of cloudcover or lighting? With the micro you might incorporate time and an expected gradual change in lighting that might more clearly signal the transistion from day/night or night/day. You might use time to eliminate false triggering during certain periods of time - an example might be the hours when you know it will be night regardless of clouds or other intereference. It may not need to be this hard but then maybe it's not all that simple in your case.
 
You can use an LDR (aka CdS photosensor). Ideally you want to just use a pullup resistor with it so it makes a voltage divider and use the PIC's ADC, though the impedance of the cell may be a problem. If it's too much error you can look to see if a lower value pullup resistor might help, otherwise you'd need a buffer.

To really save on power, instead of tying the pullup to +5v, tie it to a PIC output pin. Only turn it on long enough to wait for the ADC input to settle, do a conversion, and turn it off again. Very low power.
 
Ok thanks. I'm going to try the setup I got ( LDR, transistor & pot (voltage divider) and see what happen. if not that will try LDR and a comparator
as Nigel said and try to keep it Cheap&simple. :shock:
 
components:
1 LDR
1 10k Pot
1 2n2222 transistor
1 Led

replace the 1k resistor w/LDR, 1k pot w/10 k pot, transistor is 2n2222,
Vs= 5-12 V dc.

adjust the sensitivity using pot
LED lights up when its dark

my schematic is in word cz im having probs w/my os... hope this helps...
:shock:
 

Attachments

  • doc2.doc
    23.5 KB · Views: 189
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top