Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] automatic light on off using an ldr and pic

Status
Not open for further replies.

tejashs

Member level 1
Member level 1
Joined
Sep 4, 2011
Messages
38
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,513
hello guys,
i am currently experimenting with a PIC16F873A microcontroller.(this is the only microcontroller i have tried other than 8051s).
i tried doing an automatic light on off mechanism for a room using an LDR, i connected the ldr as a voltage divider with a 100k resistor and connected it to one of the ADC pins in the controller.

in the program part i measured the light intensity in the room and gave something like this

Code:
if(light_value < 400)
    light = 1;
else 
    light = 0;

but the problem is when i make the room dark to test, the light source(LED) turns on and illuminates the LDR so in the next round the LED is switched off...
its kinda blinking LED...
any hints to rectify for this????

The LDR gives 1M ohm when completely dark and i am using 7 white led's as a bulb....
i am also planning to implement pwm contol for LED after i learn that part... any tips would be helpful
 

This circuit works correctly but perhaps not as per your requirements. What are your requirements / specifications?
 

i just want the 7 LEDs to glow when the room gets dark....
but the thing is when it switches on, the ADC will measure the light due to LEDs so they are switched off... it is like a blinking LED....
i want it to glow continuously and switch off only when the room is lit by any other source than the LEDs

here is the basic diagram of what i am doing
light.png
 
Last edited:

But if the Leds glow when the room is dark the the room is not dark anymore !!; you must change your specification to for the leds must glow when it is dark outside.
 

Your problem is actually seen on commercial 'night lights'. You must shield you light sensor from your LEDs or come up with a far better algorithm for deciding when to turn the LEDs off.

Keith
 

so the only methid is to cover the ldr when LEDs are on....
are there any other kind of sensors (other than LDR) or methods to make this or is there no solution to this problem?
 

You could use time to decide when to turn them off. Put a large amount of hysteresis in the thresholds maybe.

Keith
 
I do not know your user requirements for this system but it appears that you want to maintain the lighting in a room even if the natural (sun) light from the window disappears. The challenge is to suitable sense the natural light status uniquely. The room light can be from the natural or from the LEDS and is therefore not suitable.
 
May be you can try out dong this,
1. check out what value are you getting when the led's are on from the ldr. Say it is LED_ON.
2. check out what values are you getting from the ldr in day light.
3. If the 1st value and the 2Nd values doesn't match than the solution is specify in the code that if the ldr value is equal to LED_ON then perform no operation or something like that.
 
How about trying a different colored filter in front of the ldr? Maybe red, since the LED output has very little red in it.

---------- Post added at 18:36 ---------- Previous post was at 18:31 ----------

second choice.
Turn-on level - 400 like in your program.
Turn-off level: Store what the light level was just after you turned on the LEDs (within a couple seconds). When the light level exceeds the stored level (combination of low ambient light and LEDs) then the ambient light has been restored; turn off the LEDs
 

How about trying a different colored filter in front of the ldr? Maybe red, since the LED output has very little red in it.
what is that filter.... covering the LDR a red plastic or paper ??
 

I was thinking any sort of clear colored plastics I could find. (Go to flea market and find some old kids' toys to break parts off of - like ambulances or planes or light sabres- or old ugly jeweled light that you could pull the jewels out of). I would get a wide variety and find something or even a combo that worked.
 

Can you please share the schematic of how to make the actual project?
Please I badly need it
 

Hello tejashs,
Can you describe your problem in points(What Do you want to do)?
 

i followed steveelliott's suggestion and it's working. thanks very much
I was thinking any sort of clear colored plastics I could find. (Go to flea market and find some old kids' toys to break parts off of - like ambulances or planes or light sabres- or old ugly jeweled light that you could pull the jewels out of). I would get a wide variety and find something or even a combo that worked.

also i experimented with some success using different threshold for on and off conditions also suggested by steveelliott.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top