Adjusting Light Sensor Sensitivity for Microcontroller Input

In summary, you may want to consider using a schmitt trigger to reduce the sensitivity of your light sensor to allow it to only actuate when there is a voltage of at least 2.5VDC or higher.
  • #1
azra
8
0
Hi,

I am using a light sensor connected to an analog input of a microcontroller. My circuit turns an output high when there is a voltage of 2.5V or higher at the analog input i.e when there is a light shining on the sensor. But sometimes my output goes high even though I have no light shining on the sensor.
I would like the the sensor to be less sensitive so that it operates only when it senses a voltage of at least 2.5V or higher. How can I go about achieving this result? Would using a schmitt trigger be a good idea?I'd appreciate your advice!

Thanks in advance,
azra
 
Engineering news on Phys.org
  • #2
You didn't say what the sensor is or what the interface
circuit is betweel the microcontroller and sensor.

You also are unclear about the whole 2.5 volt thing:

"My circuit turns an output high when there is a voltage of 2.5V or higher at the analog input i.e when there is a light shining on the sensor."
vs.
"I would like the the sensor to be less sensitive so that it operates only when it senses a voltage of at least 2.5V or higher. "

...which makes it sound like there's already a threshold
level of 2.5V to actuate the response to the sensor.

If it's truly an "analog input" on the microcontroller,
then it may be going into an analog to digital converter,
and you should be able to change (within limits) the
sensitivity of the microcontroller to the input by just
reprogramming a different threshold value of ADC counts
for actuation.

If it's a digital input to the microcontroller that's tied to
an analog signal source, yes, by all means, you should
already be using something like a schmitt trigger between
the amplified / conditioned analog sensor signal and a
digital input bit.

I don't know what the analog sensor signal output
circuitry looks like, or whether it's easy to add circuitry to
your board; you mention adding a schmitt trigger, so I
guess you can add entirely new ICs without difficulty.

Without changing the existing analog output of the
sensor circuit you could add an operational amplifier
configured for non-inverting signal gains of x2, then
take the output of the op-amp and use a two-resistor
voltage divider of e.g.
10kohms series + 10kohms pot wiper to ground to
create an adjustable electrical voltage divider so that
your x2 buffered/amplified sensor input signal is divided
by at least x2 up to xInfinity.

Then you'd take that signal from the junction of
the two-resistor voltage divider, feed it into a
schmitt trigger, and the output of the schmitt trigger into
your microcontroller.

Another probably more desirable (from the sound of your
circuit) option would be to implement an
analog comparator circuit with hysteresis,
logic level compatible output, and
use a comparator IC with a built in voltage reference
(unless you have a handy one in your microcontroller
board) so that the sensor signal level that triggers the
microcontroller input bit is adjustable via the comparator
reference level. You'd use a
fixed resistor and potentiometer to set the reference value
at the other input of the comparator anywhere from
+2.5Vdc or higher/lower if such adjustment benefits
you.,

Here's an article showing comparator designs with
hysteresis added:
http://www.maxim-ic.com/appnotes.cfm/an_pk/3616

The resistor divider between the output and the input
pin and ground gives the hysteresis which has an
effect similar to a schmitt trigger.

Vref would he your 2.5V or other desired reference level
which you could generate from another resistor divider
from a +3.3 or +5 or whatever voltage reference you
have handy and which would be compatible with your
parts voltage levels; again, there are comparators with
built in voltage references if that helps.

Use a comparator with a specified power supply voltage
capability the same as your microcontroller, and power
them from the same power supply feed.

Use a comparator with a relatively fast output rise-time
of under 1 microsecond, and which has its output high
and output low logic levels compatible with your
microcontroller.

Of course if your sensor signal already is a voltage
mode signal which can drive a relatively low output
impedance, you could probably directly use a
two-resistor or resistor<--->pot<---->ground
voltage divider directly on the sensor output signal
you now have, e.g. series resistor of 47kohms, pot of
470kohms to ground, and then you'll have from
0.9x to 0.0x of the present input voltage available on
the pot wiper. Then you'd feed THAT voltage into
a schmitt trigger and that into your uC.

Of course you'd need the
adjusted signal level to be able to exceed the schmitt
trigger's VIH (minimum voltage input high) level,
or the sensor could never trigger the schmitt trigger.
Evidentally it's already over 2.5VDC in magnitude, but
I have no idea what your circuit's logic levels are or
by how much your sensor signal can exceed 2.5V, or
what the sensor signal output impedance is etc...
so it's hard to say what's best.
 
  • #3
"You didn't say what the sensor is or what the interface
circuit is betweel the microcontroller and sensor."

The microcontroller I'm using is a PIC16f877A.The light sensors in my circuit are solar cells (Part#CPC1822).I have connected 4 solar cells to four analog inputs (PortA pin 0,1,5,6) of my PIC.The code in my PIC reads the voltage from the solar cells and does an A/D conversion and then if the voltage is approximately greater than 2.5V then turns certain output bits of the PIC high.The voltage is 2.5V-5V iwhen I shine a light on the solar cell.This voltage is converted from A-to-D by the code in the PIC and I have certain LEDs flashing as a result.

"You also are unclear about the whole 2.5 volt thing:"

I've actually done the analog-to-digital conversion theoretically and taken readings so that I know what to expect. For example if I input a voltage of 2.215V at one of the analog inputs of the PIC and convert it I get the binary value of '0111'.My code works fine and works perfectly when I have four 5K pots connected to the four analog input pins of the PIC. I get the desired output bits to flash.But when I connect up the solar cell (I have 0.1uF capacitors in series with each cell to filter out the high-frequency noise) to the PIC analog inputs I get the same results.But the only problem from what I gathered is that the solar cells are quite sensitive and sometimes my output bits which are only suppose to flash in presence of a light start flashing without the light source.I would like to eliminate that problem so that the solar cells only respond when it senses a voltage of 2.5 V or higher

So I would like to figure out how to have a circuit between the PIC and the solar cells(one that is easy to implement as I have four solar cells) that looks at just one threshold trigger voltage of 2.5V and ignores voltages below it.The Schmitt trigger ,from what I understand , would need an inverter if I were to add it to my circuit and it deals with two threshold voltages.

Thanks a bunch for your detailed reply!Sorry for not clarifying things in my previous post! What would be the best way to get around this problem according to you?

I appreciate your help!


azra
 
  • #4
"(I have 0.1uF capacitors in series with each cell to filter out the high-frequency noise)"

You mean the capacitors have one end grounded and the
other end tied to the solar cell output?
That'd be more of a case of the capacitor being in
parallel with the solar cell, which would probably be what
you want for such filtration.

What's the power supply voltage of the PIC?
What's the specified input voltage range of the PIC ADC
based on your power supply and reference voltage
selection?

Since you said the lighted voltage of the solar cells
is 2.5-5V, I assume that means that the PIC analog
input can handle such voltages.

Anyway since you apparently have no other active
circuitry between the solar cells and the sensor outputs,
and the solar cells can handle low impedance loads,
you could just use two-resistor a resistive voltage divider
to attenuate the input voltages by some multiplier e.g
0.5x or 0.7x or whatever. Connect a 4.7k resistor to
the solar cell, and a 22k pot to ground, and feed the
wiper of the pot out to the ADC inputs of the PIC, and
you'll have an attenuated version of the solar cell voltages
going to your ADC inputs. Whatever the PIC ADC values
are now, they'd become some fraction of those values
after attenuation. You'd still have to choose some ADC
threshold value as being the level at which you decide
that the solar cell is illuminated enough to take action,
but, as you wished, that'd happen at a higher illuminance
level than it presently does after the signal is attenuated.

Since you are feeding analog voltages into an
analog input of the PIC for ADC conversion, you do NOT
need a schmitt trigger or comparator on the analog signal
inputs. Schmitt triggers or logic-output comparators are
for taking analog or slowly-rising (compared to a fast
digital logic circuit) input signal and generating a sharp
and jitter-free digital output bit from those analog signals
such that the digital output from the trigger/comparator
would be compatible to use in general digital logic circuitry.

However as long as the PIC ports are programmed to be
analog inputs of the ADC, it's permissible to feed any
DC or slowly varying AC signal within the ADC input
voltage range to those pins without schmitt triggering
or comparator use.

Now if you wanted to configure the PIC input pins
as logic input bits, THEN you'd benefit from
a schmitt trigger or logic compatible comparator before
the location of the PIC digital input bits.

You asked for a circuit to selectively send a logic
signal to the PIC if the analog input exceeded 2.5VDC,
which would be the logic compatible comparator with
~500mV of hysteresis that I mentioned before. However
since you're feeding the signals to ADC analog inputs, it'd
be rather incompatible with the idea of using analog
inputs to the PIC to convert the analog signals to
digital bits outside of the PIC. If you really want the
PIC to have digital input bits coming from a threshold
detector comparator with hysteresis, you might as well
configure the PIC inputs as digital input bits or
digital input interrupt bits or something like that.

The comparator circuit isn't especially complex, you
could buy a comparator that runs on either +5V or
+3.3V or +2.5V or whatever matched your PIC
power supply and logic levels, and you could get the
comparators 4 comparators per DIP package of
14 or 16 pins. You'd need two resistors for hysteresis
on each comparator, and the quad-comparator IC
would have enough comparators for one for each of your
four solar cell inputs. It would be about as simple
and low cost as you are going to get for a solution
to a threshold detection comparator problem.

However, again, that doesn't seem to be necessary
if you intend to use the PIC inputs as ADC inputs and just
select some digitized signal level X as your decision
threshold in software.

To prevent ESD or over-voltages from the cell inputs
from damaging the PIC, you could put these diodes
on each sensor input:
1) diode cathode to solar cell; diode anode to ground
2) diode anode to solar cell; diode cathode to +Pwr supply

1n914 diodes or any small signal switching diode
or general purpose small signal schottky diode would be
fine.

Double check what you have your feference voltage
for ADC conversion set to be, and the PIC power supply
voltage ; you could get erroneous operations if your
signal voltage (e.g. +2.5 to +5Vdc) range appearing
at the PIC exceeded either the PIC's power supply
voltage, or if it exceeded the maximum postiive input
voltage that the ADC can accept to give positive
full scale readings given the selected modes/reference.

I assume the negative end of the solar cells is grounded
to the PIC's analog & digital ground, and that the
solar cell polarities are hooked up to give only
positive voltages to the PIC inputs, so you shouldn't
have signal excursions more negative than the PIC
power supply unless the PIC was powered down
(which the diodes I mentioned would help solve),
though you could still exceed the most negative
ADC input common mode input voltage that corresponds
to a digitized 000 if that happens at a voltage much
above 0V in the PIC's ADC/reference range.
 
  • #5
Re: quad comparators:
http://www.national.com/mpf/LM/LM339.html [Broken]

The National (or equivalent) LM139/LM239/LM339
is a quad comparator that can be powered
anywhere from +2 to +36Vdc, and is available in
a 14 pin DIP package.

You would use a pull-up resistor on its output going to
your system's positive logic supply voltage, since the
comparator happens to be an open-drain part.

Three additional resistors would yield a hysteresis
function that would allow a cleaner jitter-free
digital output from an analog input that is
potentially fluctuating near the comparator threshold.

A simple two-resistor voltage divider
between (analog positive power supply) and
(analog ground) would yield a mid-point reference
voltage that could be fed to all of the 4 comparators'
reference inputs to determine your comparator switching
point thresholds. If you had an output (e.g. 2.5V)
Vref from the PIC or elsewhere, of course you could use
that as +Vref for each of the comparators instead.

For hysteresis

resistor-A would go from the solar cell
output to the (+) comparator input.

resistor-B would go from the comparator output to
the (+) comparator input.

resistor-C would go from the
(+) comparator input to analog ground

q.v.
http://www.maxim-ic.com/appnotes.cfm/an_pk/3616

The comparator output transitions aren't as fast
as some other digital logic, but they're probably
acceptably fast for PIC digital inputs; check the
datasheet parameters for max. input rise/fall time for
the PIC vs. the comparator output rise/fall time given
a certain pull-up resistor on the open drain output.
 
Last edited by a moderator:
  • #6
"You mean the capacitors have one end grounded and the
other end tied to the solar cell output?"

Yes, you're right. I meant to say that the capacitors were in parallel with one end connected to the solar cell and the other end grounded.


"What's the power supply voltage of the PIC?"
What's the specified input voltage range of the PIC ADC
based on your power supply and reference voltage
selection?"

The power supply voltage for the PIC is 5V.The ADC has a Vref+ which is connected to the same 5V as the PIC and a Vref- which is connected to ground (the same as that of the PIC)


"Since you said the lighted voltage of the solar cells
is 2.5-5V, I assume that means that the PIC analog
input can handle such voltages."

Yes.


"you could just use two-resistor a resistive voltage divider
to attenuate the input voltages by some multiplier e.g
0.5x or 0.7x or whatever. Connect a 4.7k resistor to
the solar cell, and a 22k pot to ground"

So the solar cell's positive input connects to the 47k resistor which connects to the 22k pot which in turn goes to ground.The pot's wiper then goes to the PIC analog input.Did I understand correctly?

I'm not sure I understand how to attenuate the input voltage by a multiplier as you mentioned (0.5x or 0.7x).Is that by the voltage divider rule? And what does the 'x' in the 0.5x stand for?
How can I find out exactly by what fraction I attenuated the signal?

"I assume the negative end of the solar cells is grounded
to the PIC's analog & digital ground, and that the
solar cell polarities are hooked up to give only
positive voltages to the PIC inputs"

Yes, the negative end of the solar cell is grounded (it's the same ground as the PIC's).The positive end of the solar cell is connected to the PIC analog input.No, I did not get a negative voltage at the solar cell's postive input when I connected a multimeter across it.

I think I'll opt for the 47k resistor and 22k pot voltage divider circuit since the Schmitt trigger and comparator circuits deal with digital outputs and I have my PIC inputs configured as analog ones.

So the voltage at the 22k pot's wiper would be about 2.1V (going into the PIC analog input) if the voltage at the solar cell is 2.5V (according to the voltage divider rule).I think that works! If I need to trigger the solar cells at a voltage higher than 2.5V I could use a bigger resistance in place of the 4.7k fixed resistor.

Thanks!
azra
 
  • #7
I've done something like this before. Implement hysteresis with your uC!
 
  • #8
If you have a network as follows:
<S>---<R1>---<O>---<R2>---<GROUND>

Where:
S = signal voltage, i.e. connected to the positive output
of your solar cell.

O = Attenuated output voltage going to your PIC ADC

GROUND = Where the PIC power supply, -Vref,
and Solar cell negative side are grounded to.

R1 = Resistor
R2 = Resistor

You have:

I = current through the resistors = S/(R1+R2)
O = voltage at PIC ADC in = (I * R2)
so combining:
O = (S * R2 / (R1+R2))

So R2/(R1+R2) is a multiplicative attenuating factor
that divides the input voltage, or, rather, multiplies it
by that fractional value that is less than or equal to 1.

So if
R2=100k
R1=000k Factor = (100k)/(100k+000k)=1.0
R1=001k Factor = (100k)/(100k+001k)=0.99
R1=010k Factor = (100k)/(100k+010k)=0.90
R1=030k Factor = (100k)/(100k+030k)=0.769
R1=100k Factor = (100k)/(100k+100k)=0.500
R1=200k Factor = (100k)/(100k+200k)=0.333
R1=470k Factor = (100k)/(100k+470k)=0.175

So you could make either R1 or R2 a pot hooked up as a variable
resistor and get an easily variable range of attenuations within
the limits that you'd calculate by the above voltage divider equation
and the limits of your pot (0k to whatever).

If you wanted you could *just* use a single pot since
then you'd have a three terminal device:
S--R1---O--R2---GROUND
where R1 and R2 were actually the same resistor and 'O' being
connected to the 'wiper' terminal of the pot would move anywhere
along the resistance spread of the pot thus creating
two resistors one being from the wiper to one end of the pot,
the other being from the wiper to the other end of the pot.
In this case you'd have the (O) signal taken from the wiper
being anywhere from 100% of the input signal to 0% of the input
signal.

Your PIC chip's ADC input pin probably has some "built in"
resistance (ADC input resistance or input impedance on the data sheet))
to ground, though, so it'll act as if there's a smaller value of R2
than you really have in the circuit because of that.

Similarly the solar cells have some output impedance that
depends on the light level and the solar cell etc. that looks
like a 'R1' resistor of some value built into the solar cell,
so because of that the circuit will perform as if R1 is bigger
than it really is.

To deal with those effects you want to use some compromise
value of R1 and R2 so that you're not presenting too low of
a total resistance on the solar cell while yet not presenting
too high of a total resistance to the PIC ADC input.

Thus you'd probably use some limit like
(R1+R2) = somewhere in the range of 10k to 47k combined and
then your divider operation should be fairly predictably correct
despite the actual internal resistances in the solar cell and PIC chip
because of the kinds of values experience teaches me that they're likely
to be. It's a relevant concern if you need to know to high accuracy
precisely *what* the attenuating factor is, but if you just need
a relative "ballpark estimate" of an attenuation factor X then
just hook it up with convenient values and it'll work fairly close
to the predicted values.
 
  • #9
"Your PIC chip's ADC input pin probably has some "built in"
resistance (ADC input resistance or input impedance on the data sheet)"

Yes the maximum input impedance is 2.5k

Thanks for your reply!

I think I'll use the first two resistor voltage divider configuration you suggested.

<S>---<R1>---<O>---<R2>---<GROUND>

I had a 0.1uF capacitor in parallel with the solar cell, should I leave it connected between signal<O> going into the PIC or no?
I also had another idea that I'd like to ask you about.I'm not sure if it'll work or not but here goes..

<S>--<Scmitt trigger IC>---<R1>---<base of NPN transistor>
<emitter of NPN>--ground
<S>--<R2>--<collector of NPN>--<PIC analog input>

I'm not sure what value to pick for R2 but R1 could be=(Vcc-Vbe)/Ibase; Vbe~0.7V, Ibase-->from the spec sheet of 2n3904(those are the ones I have handy).
The schmitt trigger IC would be powered by Vcc as V+ and ground as V-.
The <S> would be the signal from the solar cell or Vref and that same signal goes
into the collector of the NPN transistor through a high resistance R2.

The way I understand it,when Vref would be greater than 2.5V there would be a low signal at the output of the schmitt trigger which would cause the NPN transistor to stay off and so the Vref going into the PIC would be high.If Vref is less than 2.5V there would be a high signal at the output of schmitt trigger IC which would turn the NPN transistor on and cause a drain at the collector so the PIC would receive a low voltage.

Do you think this arrangement might work?If it does I might try it this way as well.Could you please recommend
a Schmitt trigger IC I could use for this application.

Thanks for your suggestions!

-azra
 
  • #10
You could also simply purchase an ambient light sensor with an integrated digital serial interface, like the ISL29001 from Intersil. It would probably be a snap to implement.

- Warren
 
  • #11
Thanks Warren!
 
  • #12
Hi,

I tried to use the voltage divider approach with a 5K pot. But at the output of the voltage divider ( analog input to the PIC) the voltage is very low like about 5mV. This is the way I connected it-->

<positive end of Solar Cell>--><one end of 5K pot>
<other end of pot>--><Gnd><--<negative end of Solar Cell>
<wiper of pot>--> <PIC analog input>

I'm not sure why this is happening.I'd appreciate any suggestions or advice.

Thanks in advance,
azra
 
  • #13
I just looked at the "www.clare.com/home/pdfs.nsf/www/CPC1822.pdf/$file/CPC1822.pdf"[/URL] The short circuit current under direct sunlight (6000lux) is only 50 uA. Try a higher resistance pot.
 
Last edited by a moderator:
  • #14
Thanks dlgoff!

I used a 20k pot in series with a 8.2k resistor. I get the desired result (without using the solar cell) when I use Vcc (5V)to one end of the 8.2k resistor .But when I connect the solar cell and shine a light on it ( the voltage which should increase to about 3V-4V) changes very little above 0V.I tried to measure the current through the circuit .I get a reading of 0.12A and then it decreases to less than 50uA (the short circuit current of the solar cell).I'm not sure why this happens when I use the solar cell.

How can I go about solving this problem?

Thanks,
azra
 
  • #15
"I had a 0.1uF capacitor in parallel with the solar cell, should I leave it connected between signal<O> going into the PIC or no?"

Leave it connected across the solar cell terminals
themselves and it'll be fine. If you really end up with
a serious problem of the analog signal changing too
rapidly or getting high frequency noise coupled into your
circuit then you could look at more intensive
capacitive+resistive filtering connections.
But for the moment that doesn't seem to be a problem and
leaving it across the solar cell terminals is just fine for
just a little bit of filtration.

I also had another idea that I'd like to ask you about.I'm not sure if it'll work or not but here goes..

<S>--<Scmitt trigger IC>---<R1>---<base of NPN transistor>
<emitter of NPN>--ground
<S>--<R2>--<collector of NPN>--<PIC analog input>

I'm not sure what value to pick for R2 but R1 could be=(Vcc-Vbe)/Ibase; Vbe~0.7V, Ibase-->from the spec sheet of 2n3904(those are the ones I have handy).
The schmitt trigger IC would be powered by Vcc as V+ and ground as V-.
The <S> would be the signal from the solar cell or Vref and that same signal goes
into the collector of the NPN transistor through a high resistance R2.

The way I understand it,when Vref would be greater than 2.5V there would be a low signal at the output of the schmitt trigger which would cause the NPN transistor to stay off and so the Vref going into the PIC would be high.If Vref is less than 2.5V there would be a high signal at the output of schmitt trigger IC which would turn the NPN transistor on and cause a drain at the collector so the PIC would receive a low voltage.

Do you think this arrangement might work?If it does I might try it this way as well.Could you please recommend
a Schmitt trigger IC I could use for this application.

A good schmitt trigger for use between +5V
power supply and 0V ground logic would be the
74HC14, I'd guess that you could get them cheaply
in quantity one from DigiKey, Mouser, Newark, et. al.,
and that the datasheets would be available from
www.ti.com[/url], [url]www.fairchild.com[/URL], etc.
They are INVERTING S.T. gates, though, FYI, so use
two in series or just realize/accept the signal inversion.
[url]http://www.fairchildsemi.com/pf/MM/MM74HC14.html[/url]
[URL]http://www.onsemi.com/PowerSolutions/product.do?id=74HC14DR2G[/URL]

R1 being between a CMOS +5V logic schmitt trigger
output and the base of an NPN transistor whose emitter
is grounded would be having about +5V across it when
the S.T. output is HIGH.
The S.T. can drive 10 TTL load equivalents, and is
specified with the absolute maximum current output per
pin of 25mA. So choosing 3mA of base current to the
transistor should be a reasonable compromise. As you
said, V_BE is around 0.7V for a typical single small
signal NPN, so 5-0.7 = 4.3V, and so about 1.5k R1 would
give you about 3mA of base current when the S.T. is high.

As for the rest:
<S>--<R2>--<collector of NPN>--<PIC analog input>
<+VREF>--<R2>--<collector of NPN>--<PIC analog input>
<+5V>--<R2>--<collector of NPN>--<PIC analog input>

Well I don't see too much point in any of the options there
but your logic with the transistor operation is mostly
correct.

If the S.T. output is low, the transistor will have
I_BASE = 0, the NPN will be OFF / non-conducting, and
there will be basically a high resistance between
emitter and collector. Since the collector goes to the
PIC input, the PIC will effectively see a signal input
equal to whatever is connected to the PIC input
ignoring the transistor which acts like an open circuit
between its C and E when it's OFF. If you had
<S>--<R2>---<PIC INPUT> where <S> is the
solar cell, it'd be the same as having the solar cell go
to the PIC IN through R2 when the transistor is OFF.

If you have <+5V>---<R2>---<PIC INPUT> then
when the transistor is OFF the PIC would see
+5V through R2 resistance on its input.
The similar would be true if the source was <VREF>
assuming <VREF> is some fixed positive voltage
between +2.5 and +5VDC.

When the S.T. output is HIGH, transistor base gets 3mA
current, the collector emitter path goes to some fairly
low resistance, and assuming R2 is more than a few
hundred ohms, the collector voltage would be getting
down into the range of less than +0.5VDC so the PIC
would see a low voltage signal.

However if what you want is a LOGIC level
at the PIC input, why not just reconfigure the PIC
input as a LOGIC input and not an ADC analog input.

Then you could just do:
<+SOLAR CELL>---<ST IN>
<ST OUT>---<PIC DIGITAL IN>

and you have a logic input to the PIC that is
0 if the solar cell terminal goes from dark low voltage
to illuminated higher voltage and transitions to
output somwhere between +2.3 and +3.1VDC.

1 when the solar cell was illuminated but goes dark
and transitions from a high positive voltage output
lessening to somewhere between +2.0 and +0.9VDC.

If you want that inverted logically you could just connect
another ST gate in series with the first
and then have the opposite
<1> <0> sense of those logic levels appearing at the PIC.

If you really wanted the solar cell analog voltage to appear
at the PIC ADC analog input, I don't see too much point
in adding the S.T. and NPN...

Now if you wanted you could tie the solar cell analog
to the PIC ADC, AND tie the solar cell analog to some
S.T. type of circuit whose logic output goes to some
DIFFERENT PIC logic interrupt input pin configured to
give you an software interrupt when there is a logic level
change based on the solar cell voltage so your
software could go out and measure the actual voltage
of the ADC at that moment or something.

But if you want to work with analog signals and you
had something like an 8 bit ADC with
+VREF = +VIN_MAX = +5V, then
ADC 255 = +5.00VDC in
ADC 127 = +2.50VDC in
ADC 063 = +1.25VDC in
etc. so you can just choose some number of ADC
reading as a threshold for saying "light" or "dark"
and then it is a small matter of choosing whatever
ADC number best suits the light level you're trying to
detect. It shouldn't be very necessary to use
external comparators, schmitt triggers, attenuators,
amplifiers, etc. to make the level of the signal that
corresponds to 'light' and 'dark' some particular value
since the ADC in the PIC can already (with some
limited resolution) tell you the value anywhere between
+VREF and 0V.
 
Last edited by a moderator:
  • #16
My guess is that maybe you've mixed up the
wiper of the POT and the fixed end-terminals of
the POT. There is no fixed mode of construction to
tell which terminal is which, so unless you have the
data sheet or a diagram/label on the pot itself, or have
measured it with a ohm meter to distinguish the
terminals, room for confusion exists.

I am surprised the PIC has such low input impedance,
usually ADCs are more than ~ 2.5k to ~ 6k ohms
input resistance or input impedance for general purpose
usages at low frequencies. Anyway since you use a 5K
pot there will be an action as if the lower resistor in
the pot was lower than it is e.g. the parallel combination
of the lower resistor with the PIC ADC input resistance
to ground.

But that would not be such a severe effect as to make
the PIC measure only 5mV of signal even when the
solar cell puts out a signal that would be read as more
than +2.5V if you had not used the POT as a
voltage divider.

Consequently there may be a defect in wiring or
misidentification of the POT terminals etc.

You could use a lower impedance POT of 2K or 1K if
you wanted more accuracy of voltage division compared
to the low input impedance of the PIC ADC, but even
a 5K pot should give you very suitably adjustable
voltage inputs to the PIC, so there must be an error
in wiring or in the programming of the PIC.

Use a DMM. Adjust the pot wiper in the middle of
the range of motion. Measure between
<A> to <B> and <A> to <C> and <B> to <C>.

Whichever one of those measurements yields close to
5K ohms for a 5K pot and such that the measurement
does NOT change when you change the position of the
pot wiper, those are your pot's fixed terminals.
The other pin is the wiper.

Set the DMM on DC voltage measurement mode
with the probes set to measure in the range of
0V to +20V or so. Or +12V or +10V range, whatever.
If you connect +5VDC to one pot end terminal and GND
to the other pot end terminal you should be
able to measure anywhere from +5VDC down to 0Vdc
voltage on the wiper pin relative to GND pin depending on
your adjustment of the wiper from one extreme to
the other. It should not matter much if the PIC
ADC input is also connected to the wiper or not when
you perform such measurement.

Make sure the PIC has power applied, though, and
consider using proper techniques to prevent
electrostatic discharge and handling related
voltage and current / mechanical disruptions to the PIC
as you work on the circuitry while the PIC is connected.

Also consider adding the diodes I mentioned
between PIC ADC IN and GND and +PIC POWER SUPPLY
to protect the PIC from voltages/currents that can appear
on its ADC input. It's conceivable that the PIC's
ADC input could get "locked up" temporarily
into some strange mode where it has low resistance to
ground, even much more so than normal, if it has had
a voltage at its input that isn't proper for it.


Hi,

I tried to use the voltage divider approach with a 5K pot. But at the output of the voltage divider ( analog input to the PIC) the voltage is very low like about 5mV. This is the way I connected it-->

<positive end of Solar Cell>--><one end of 5K pot>
<other end of pot>--><Gnd><--<negative end of Solar Cell>
<wiper of pot>--> <PIC analog input>

I'm not sure why this is happening.I'd appreciate any suggestions or advice.

Thanks in advance,
azra
 
  • #17
I just looked at the CPC1822 specs. The short circuit current under direct sunlight (6000lux) is only 50 uA. Try a higher resistance pot.

Oops! Being a "solar cell" I assumed it had a typically
LOW output impedance that'd be useful if it was to
be providing power to other electronics.

50uA in the bright light indicates a very high
output impedance solar cell that is really more of a
"light sensor" than a "photovoltaic power cell".

You have a bit of a problem here because the PIC has
a LOW ADC input resistance of ~ 6 kOhms.
And the best suited output impedance to drive the PIC
ADC input is between 0 and 5kOhms, the less the better.

The solar cell, on the other hand seems to be a high
impedance sensor with a few kilo ohms of internal
impedance.

Choosing a pot that's high impedance to act as a precise
voltage divider that doesn't load the solar cell too much
would indicate pot resistances in the 10's of kilo-ohms.
But that'd be unsuitable since the PIC's
low input impedance would drastically load the
voltage divider.

What you might consider doing is using a 10k variable
resistor (pot wiper to one pot end terminal, leave the other
pot terminal disconnected) between the PIC & S.C.
<SOLAR CELL+OUT>---<R1>---<PIC ADC IN>

Then there will be some voltage dropped by the input
current of the PIC and you'll see a bit of attenuation,
though it might depend on how often you read the ADC.

I guess there's no harm in trying a higher 20K or so
R1,R2 divider... maybe you have.. Let's see...
 
  • #18
I am confused. It sounded like the problem at first
was that the solar cells were *too* sensitive and
output *too much* voltage for you. Now they seem as if
they're a bit feeble in their output.

You could connect a parallel resistance with the solar
cell to give it a resistive load even less than the PIC's
ADC impedance, that'd attenuate the signal read
by the PIC because part of the voltage would drop across
the internal series output impedance of the solar cell.

<PIC ADC IN>----<+SC>----<R1>---<GND>

R1 could be the wiper and one end terminal of a 50k pot
hooked up as a variable resistor.

I am pretty sure you'd end up with some satisfactory
load resistance setting that would yield an
sufficiently attenuated but sufficiently strong signal
going into the PIC.

I am still confused that your PIC ADC just hooked to the
naked <+SOLAR CELL> output doesn't just give you a
digital reading of 0...N corresponding to 0...+5V and
among those values, one of them would be a suitable
threshold for your light / dark decision point.

Thanks dlgoff!

I used a 20k pot in series with a 8.2k resistor. I get the desired result (without using the solar cell) when I use Vcc (5V)to one end of the 8.2k resistor .But when I connect the solar cell and shine a light on it ( the voltage which should increase to about 3V-4V) changes very little above 0V.I tried to measure the current through the circuit .I get a reading of 0.12A and then it decreases to less than 50uA (the short circuit current of the solar cell).I'm not sure why this happens when I use the solar cell.

How can I go about solving this problem?

Thanks,
azra
 
  • #19
"I'm not sure why this happens when I use the solar cell."

What type of light source are you using? Have you tried it in sun light?
 
  • #20
I tried to measure the current through the circuit .I get a reading of 0.12A and then it decreases to less than 50uA (the short circuit current of the solar cell).I'm not sure why this happens when I use the solar cell.

That's likely because
a) there's a capacitor in parallel with the solar cell,
so the capacitor charges slowly from the solar cell, but
when discharged the capacitor can provide a high burst
of current that gradually tapers down until at a long time
short circuit you just get the continuous stream of
current at the rate the solar cell can supply into a short.

and

b) because voltmeters / ammeters often have some
time of instability / fluctuating readings as they
begin to track a new signal, the signal changes, etc. and
eventually the readings settle down. Sometimes it's due
to genuine changes in the signal being measured (e.g.
the charge or dischargs of a capacitor), other times it's
just the way the meter does its ranging and estimation,
often times being confused by waveforms that may not
be sine-waves in the case of AC circuits.
 
  • #21
"That's likely because there's a capacitor in parallel with the solar cell,so the capacitor charges slowly from the solar cell, but when discharged the capacitor can provide a high burst of current that gradually tapers down until at a long time short circuit you just get the continuous stream of
current at the rate the solar cell can supply into a short"

I tested the voltage divider circuit without connecting it up to the PIC.So at first I had the 20k pot, a 4.7K resistor in series with the pot.The setup was as follows:

5V-->4.7K<--20K pot-->Gnd
|
multimeter

I measured the voltage between one end of the pot and the Gnd with the multimeter and I got the voltage reading that I had calculated.
Then I introduced one solar cell instead of the Vcc(5V) in the same setup.I still hadn't connected it up
to the PIC at this point and I did not use a capacitor either.

"What type of light source are you using? Have you tried it in sun light?"

I'm using a laser light and I was using a red filter to cover the solar cell.I haven't tried it in direct sunlight,no but I'm using the red filter to filter out ambient light.
More often then not the recurring problem of the solar cell sensing a voltage of 2.5V (which triggers off my output) doesn't happen when I cover the solar cell.I only intended for the the solar cellsnot to register a voltage of 2.5V or higher unless I shined the light on it.
My ADC works fine because I've tested the setup with 5k pots in place of solar cells and I get very satisfactory results.So I figured the problem lay with the solar cells which seem to set off my outuputs on powering up

So that's why I was thinking of a way to block out the voltage of 2.5V or lower so the cells wouldn't register it and therefore would remain unresponsive at that voltage unless a higher one was around (which would happen in presence of an artificial light)
The voltage divider was an excellent idea but the in previous voltage divider setup I used the solar cells didn't have enough current to drive the pots.

"I am confused. It sounded like the problem at first
was that the solar cells were *too* sensitive and
output *too much* voltage for you. Now they seem as if
they're a bit feeble in their output."

The solar cells are still quite sensitive. If I connect a voltmeter across just the two terminals of the cell I get a voltage reading of about 1V.But if I shine a laser on it
jumps up to about 4V.I have the solar cells connected to a low-pass RC circuit going into the PIC analog input.
The outputs were not 'too much voltage' for me, I merely tried to stop the solar cells from functioning till I shined a light on them.Since it starts to show a change between the range of 2.5V-4V when a light shines on them , I figured if I could force the solar cells not to respond till it read a voltage of at least 2.5V I'd be able to eliminate the
stray voltage(noise?) it seems to be picking up on powering up.Keeping the solar cells covered doesn't seem
to be a practical solution so I was looking for other alternatives.


"I am still confused that your PIC ADC just hooked to the
naked <+SOLAR CELL> output doesn't just give you a
digital reading of 0...N corresponding to 0...+5V and
among those values, one of them would be a suitable
threshold for your light / dark decision point."

Sorry,I think I sounded ambiguous in my earlier posts.I get a fine ADC reading with just the solar cells
connected to my PIC analog inputs.It's just that,as I mentioned earlier,I would like a certain degree of control over this circuit so I do not want the solar cells to trigger
off my outputs unless I shine a light whichis tantamount to the cells registering a voltage of 2.5V or higher.And I've already established the light/dark threshold decision point.

"My guess is that maybe you've mixed up the
wiper of the POT and the fixed end-terminals of
the POT. There is no fixed mode of construction to
tell which terminal is which, so unless you have the
data sheet or a diagram/label on the pot itself, or have
measured it with a ohm meter to distinguish the
terminals, room for confusion exists."

I've connected up the pot and measured the maximum resistance it can reach.As far as I know the
second pin of the pots are wipers ,possibly a coincidence because that was the case with both the 5k and the 20k pots I used.
So it would be quite fair to say that there is little room for confusion in this regard.

"You could use a lower impedance POT of 2K or 1K if
you wanted more accuracy of voltage division compared
to the low input impedance of the PIC ADC, but even
a 5K pot should give you very suitably adjustable
voltage inputs to the PIC, so there must be an error
in wiring or in the programming of the PIC."

Yes Idid consider that option.But what I'm confused about is if there was indeed a problem with the wiring or say may bewith the programming for instance,would it have given me the same results when I had the5k pots connected to my PIC's analog inputs instead of the solar cells.
I changed the pot's resistances and therefore voltages going into the PIC input and I got the right results.

"However if what you want is a LOGIC level
at the PIC input, why not just reconfigure the PIC
input as a LOGIC input and not an ADC analog input"

I would have done just that but there is all this ADC coding I've written for the PIC which I would rather not do away with. And it would also make the use of the PIC rather redundant especially at this point. And as you pointed out earlier that the use of schmitt triggers or comparators would not help since I am using an analog input.
That's why I thought the voltage divider idea sounded like the best solution.

Thanks for replying to my earlier posts!much appreciated!


azra
 
  • #22
azra said:
Yes the maximum input impedance is 2.5k

I looked up the data sheet for the PIC.
That 2.5k is the maximum source impedance.
With a short circuit current of 50ua your solar cell is a much higher source impedance than that.

You probably need an op-amp to fix up the impedance requirements.

A couple things you could try.
Use the maximum PIC acquisition time.
Take several samples and see if all the samples satisfy your 2.5v requirement before turning on the coresponding output pin.

If you can not get a good string of say 10 samples for the illumination condition then cheating won't work and you need the preamp.
 

1. How do I adjust the light sensor sensitivity for my microcontroller?

To adjust the light sensor sensitivity for your microcontroller, you will need to modify the code in your microcontroller's programming. This can be done by changing the value of the sensitivity variable or by using a calibration function to adjust the sensitivity based on the current lighting conditions.

2. What is the purpose of adjusting the light sensor sensitivity?

Adjusting the light sensor sensitivity allows for more accurate readings from the sensor. This is especially important in environments with varying light levels, as it ensures that the sensor is able to detect even small changes in light and provide reliable data.

3. How can I determine the optimal sensitivity level for my microcontroller's light sensor?

The optimal sensitivity level for your microcontroller's light sensor will depend on the specific project or application you are working on. It is recommended to experiment with different sensitivity levels and test the sensor in different lighting conditions to find the most accurate and reliable setting.

4. Can I use a light sensor with automatic sensitivity adjustment?

Yes, there are light sensors available that have automatic sensitivity adjustment capabilities. These sensors use algorithms to continuously adjust the sensitivity based on the current lighting conditions, ensuring accurate readings without the need for manual adjustments.

5. What are some common troubleshooting steps for adjusting light sensor sensitivity?

If you are having trouble adjusting the light sensor sensitivity, some common troubleshooting steps include checking the wiring and connections, making sure the sensor is properly calibrated, and checking for any interference from other electronic devices. It may also be helpful to consult the datasheet or documentation for your specific light sensor to ensure proper usage and calibration.

Similar threads

  • Electrical Engineering
Replies
11
Views
984
  • Electrical Engineering
Replies
5
Views
1K
  • Electrical Engineering
Replies
1
Views
719
Replies
2
Views
307
  • Electrical Engineering
Replies
7
Views
2K
  • Electrical Engineering
Replies
20
Views
1K
  • Electrical Engineering
Replies
7
Views
952
  • Electrical Engineering
Replies
5
Views
1K
  • Electrical Engineering
Replies
7
Views
6K
  • Electrical Engineering
Replies
1
Views
834
Back
Top