@scrollock: There must be more about this "project" than you have revealed so far if the title of your thread,
"LDR based relay switching with the help of Very Low Cost, Low Power Microcontroller" is any indication of what you are trying to accomplish with a PIC.
I suspect that you want to put the PIC to "sleep" to conserve power until the LDR output is greater than or less than 4.52 volts. After the LDR voltage crosses this "trigger" level, the PIC will "wake up" and change the state of a relay, controlling who knows what and for what purpose. The PIC can then go back to sleep until another change in the comparator state occurs.
This "sleep, awaken and do something, go back to sleep" algorithm is a powerful way to minimize power consumed by the PIC, especially if the program execution task while the PIC is awake is short and simple.
One problem I see you might have is reducing the power drawn to energize the LDR, and the power drawn by a possible voltage divider that establishes the 4.52 volt reference threshold for a change in comparator state. The maximum impedance of a voltage source connected to the comparator input pins (there are two) is 10,000 ohms. This voltage divider will have a strong influence on the total current requirements, assuming the LDR is excited from a 5 VDC supply and the PIC is also operated from the same supply. Of course, since you are driving the coil of a electro-mechanical relay, its current requirements when energized are probably orders of magnitude greater than the PIC, the LDR, and whatever voltage divider you use to establish the 4.52 volt reference level for the comparator. This may not be a problem if the relay coil is energized from its own separate power supply, and you are not interested in a truly low-power implementation.
I must agree with Bluejets on this, vis a vis experience, but the PIC 10F206 is a good PIC to learn with if you equip yourself with the right parts.. Be sure you get the 8-pin PDIP package so you can breadboard your LDR circuit with the PIC. You will also need a PICKit3 or PICKit4 programming pod. Purchase one of these directly from Microchip.com or reputable electronics distributor such as DigiKey. Do not purchase a cheap Asian knock-off product.
A small solder-less breadboard is essential, along with insulated, tinned, 22 AWG solid "hook up" wire. Don't try to use larger diameter wire by forcing it into the holes on the breadboard because you will ruin those holes for later use. Limit resistor sizes to 1/4-watt or less for the same reason. If you need to insert components with leads larger than 22 AWG, solder solid "hook up" wire to their leads.
LDRs are high-impedance, highly non-linear, low-light sensitive, resistive devices made with cadmium sulfide. Their "dark resistance" can be ten megohms or more, quickly dropping to a few tens of ohms upon exposure to normal daylight conditions. In other words a six order of magnitude change in resistance is to be expected for LDRs. This can make the LDR problematical if a specific light intensity is required for triggering the relay. Even if you get the attenuation ratio correct, the resulting impedance may be too great to properly operate the comparator in the PIC 10F260. That's where the bread-board comes in handy for trying different LDR input circuits, as well as voltage divider circuits for the 4.52 volt reference applied to the other comparator input.
BTW, WTF did you come up with the need for a 4.52 volt comparator switching threshold? And are you aware that practical circuits, i.e., circuits that actually work, require hysteresis in the comparator? This is normally accomplished using positive feedback to the non-inverting comparator input from the positive-going output when the comparator changes state.
My final advice for the moment is for you to actually print out a hard copy of the PIC datasheet. Sit down somewhere that you won't be disturbed and carefully read it. Make notes in the margins. Use a high-light pen if you spot something you think is important or that you don't understand. You must fully understand the PIC registers: the function of each bit and how it is set or cleared. Microchip is famous for cramming ten pounds of electronics into a one pound integrated circuit, using I./O bits and status bits for multiple purposes. Only by fully understanding the datasheet will you be able to produce even a simple program.
Putting the PIC to sleep is easy. Waking it up and knowing why it was awakened is another matter entirely. Your program must ignore wake-up events that did not originate from a change of state of the comparator, do whatever "housekeeping" tasks are required, and then immediately put the PIC back into sleep mode..
Please define what you mean by "accurate results."
I really appreciate u for replying on my thread, Hereby I will be informing you about what exactly I want to accomplish. I guess you have understood only half of the mentioned thread.
Specifically there is nothing to do with 4.52V value which is concerning everybody. Its just the value I preferred to trigger the relay according to the voltage across LDR vs light intensity relation, I derived . Obviously changing the value the of resistor in voltage divider circuit will change that value. I used that value just for reference to bring more clarity on my concept or idea of implementation.
BTW, WTF did you come up with the need for a 4.52 volt comparator switching threshold? And are you aware that practical circuits, i.e., circuits that actually work, require hysteresis in the comparator? This is normally accomplished using positive feedback to the non-inverting comparator input from the positive-going output when the comparator changes state.
I have already implemented such LDR based lighting switch with help of specific
comparator IC but not with comaprator embedded in microcontroller. While comparator IC implementation, I have also implemented Schmitt Trigger to avoid false triggering due to hysteresis.
My main query is that if I use
PIC10F206 which does not contains ADC Peripheral, instead it contains comparator, correct me if I'm wrong but as per my understanding implementing voltage divider across this comparator will be acting as just another normal Voltage comparator ic.
Instead is it better to use a microntroller with ADC peripheral which will take voltage across LDR as an input and convert it to appropriate value and based on such value I will code to trigger relay.
In terms of
accuracy which will be better ADC or embedded comparator in microcontroller?
Please define what you mean by "accurate results."
With respect to
ADC referring to term
accuracy I mean that, if due to change in light intensity, the voltage across LDR is changing from 3.12 to 3.25 (
values mentioned are hypothetical just used for giving example for better understanding) then how much change in value of ADC will be observed? That is for value of 3.12 across LDR, ADC was converting it in to 300 (
yet another hypothetical value) then for 3.25 how much change in the ADC will be observed? Will it be still giving 300 or supportive change in ADC value like 317 or 320 (
yet another hypothetical value) will be observed.
If not exact but certain linear change in ADC values with respect to voltage values across LDR is obtained then it will be good accurate system.
In short, if graph for
voltage across LDR vs light intensity and
ADC values vs light intensity is plotted then
slope of both the graph should be
certainly equal.
Even I have referred different techniques of ADC such as SAR, Delta- Sigma, Dual Slope(Integrating ADC) etc.. . But as per my understanding for this LDR specific above quoted application ,
(correct me if I'm wrong) Dual Slope(Integrating ADC) will be most suitable. But I am unable to find a microcontroller with such ADC technique implementation.
With respect to microcontroller embedded comparator, referring to term
accuracy I mean, there should be minimum effect of hysteresis on comparator ouput.
Obviously I will be offering delay to avoid any unwanted triggering, but that is secondary sort of thing.
"I suspect that you want to put the PIC to "sleep" to conserve power until the LDR output is greater than or less than 4.52 volts. After the LDR voltage crosses this "trigger" level, the PIC will "wake up" and change the state of a relay,"
Yes you suspected it correctly. I wanna do that too. But that is secondary implementation or another stage of application you can say...
Looking forward for ur valuable feedback on this ..................
@hevans1944 and
@Bluejets as well as other forum members
Thank You